Caprica Software

vlcj 3.x Tutorial

Logging

Recent versions of vlcj use the SLF4J API for logging.

As is the intent of SLF4J, vlcj does not depend on any particular logging implementation (e.g. Logback, Log4J or whatever). You are free to choose the most appropriate logging framework for your own application.

There is plenty of information available in SLF4J documentation that describes how to choose a logging implementation and how to configure loggers. We will present here one example configuration using Logback with XML configuration.


Add the Logback Dependency

The simplest way is to add Logback as a dependency to your application's maven pom.xml file.

pom.xml
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logbackVersion}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${logbackVersion}</version>
</dependency>
</dependencies>

If you don't use maven, you have to add the dependency jar files manually to your project in whatever way you usually do it. Note that logback-classic itself depends on slf4j-api so you need to add that SL4FJ jar file to your project too.


Configure Logging

By default, Logback looks for a configuration file named logback.xml in the class-path of your application.

If you are using a maven project structure, you can create this file in the src/main/resources directory.

If you are not using maven, then you can create this file in root directory of your source path, and make sure it is copied to the same place as your compiled classes go.

Here's an example logback.xml file:

logback.xml
<configuration>
<timestamp key="TIMESTAMP" datePattern="HHmmss"></timestamp>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>\${user.home}/vlcj-\${TIMESTAMP}.log</file>
<append>false</append>
<encoder>
<pattern>%-36(%d{HH:mm:ss.SSS} [%thread]) %-5level %72logger{72} - %msg%n</pattern>
</encoder>
</appender>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%-36(%d{HH:mm:ss.SSS} [%thread]) %-5level %72logger{72} - %msg%n</pattern>
</encoder>
</appender>
<logger name="ch" level="ERROR"/>
<logger name="org" level="ERROR"/>
<logger name="com" level="ERROR"/>
<logger name="uk.co.caprica.vlcj" level="DEBUG"/>
<root level="debug">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
</root>
</configuration>

This configuration will get you started, it creates FILE and CONSOLE appenders with a reasonably tidy formatting pattern.

The configuration is yours, you can configure it however you want.

Please refer to the relevant logging library documentation for more information.