Classpath Setup
In order to run the examples provided in the documentation, you need to add the following jars to your class path:
For logback 1.5.x targeting Jakarta EE (jakarta.* namespace)
- logback-core-1.5.20.jar
- logback-classic-1.5.20.jar
- logback-examples-1.5.20.jar
- slf4j-api-2.0.17.jar
For logback 1.3 targeting Java EE (javax.* namespace)
- logback-core-1.3.16.jar
- logback-classic-1.3.16.jar
- logback-examples-1.3.16.jar
- slf4j-api-2.0.17.jar
The logback-*.jar files can be downloaded from Maven central under the ch.qos.logback groupId whereas slf4j-api-2.0.17.jar can be downloaded from the org.slf4j groupId.
Running from the command line
You can launch the first sample application, chapters.introduction.HelloWord1 with the following command. This assumes that your current directory is $LOGBACK_HOME/logback-examples, where $LOGBACK_HOME stands for the directory where you installed logback:
java -cp lib/slf4j-api-2.0.17.jar;../logback-core-1.5.20.jar;\ ../logback-classic-1.5.20.jar;logback-examples-1.5.20.jar\ chapters.introduction.HelloWorld1
It is more convenient to set the CLASSPATH environment variable once and for all before running the examples.
The setClasspath.cmd script located in the $LOGBACK_HOME/logback-examples folder will configure the class path for the MS Windows platform. For Unix, you can use setClasspath.sh.
Please edit the script in order to adapt the LB_HOME variable to match your local environment.
Please be aware that many examples will launch Java classes along with configuration files. To access these files by using the same commands as written in the documentation, you will need to issue the commands from within the $LOGBACK_HOME/logback-examples directory.
Maven dependency declaration
To use logback-classic in your Maven project, declare the following dependency in your project's pom file.
<dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.5.20</version> </dependency>
TRANSITIVITY Note that in addition to logback-classic.jar, the above declaration will automatically pull-in slf4j-api.jar and logback-core.jar into your project by virtue of Maven's transitivity rules.
For the logback-access project, see the instructions on its dedicated page.
Optional dependencies
SMTPAppender requires
Jakarta-Mail
SMTPAppender related examples require the Jakarta-Mail
API version 2.0 or later.
Here is the corresponding Maven dependency declaration.
<!-- The jakarta.activation:activation dependency will be --> <!-- automatically pulled in by Maven's transitivity rules --> <dependency> <groupId>jakarta.mail</groupId> <artifactId>jakarta.mail-api</artifactId> <version>2.1.0</version> </dependency>
Building Logback
As of version 1.5.x, logback requires Java 21 to build but targets Java 11 or later at runtime.
If you wish to contribute to the project or just hack for fun, you will probably want to import logback as a project into your favorite IDE. Logback uses Maven as its build tool. The only mandatory logback dependency at runtime is the JRE, Also note that building from the command line is fairly trivial, the command 'mvn install' given from $LOGBACK_HOME folder should suffice.
ask for help Notwithstanding the instructions below, if you have trouble building logback from the sources, just ask for help on the logback-dev mailing list.