Question

I want to enable logging for my unmanaged extensions, which works also fine so far (at least in my unit tests). So I wrote a logback.xml and included it into my package. When I run a unit test (functional test) with a db that will be created on the fly everything works fine, i.e., my logging definitions got recognized and the logging works as expected. Here is an excerpt of the logs where you can see that the different will be registered:

12:07:56,597 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/home/me/git/myproject/target/classes/logback.xml]
12:07:56,598 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback.xml] occurs multiple times on the classpath.
12:07:56,598 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource  [logback.xml] occurs at [file:/home/me/git/myproject/target/classes/logback.xml]
12:07:56,598 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback.xml] occurs at [jar:file:/home/me/.m2/repository/org/neo4j/app/neo4j-server/2.0.1/neo4j-server-2.0.1.jar!/logback.xml]
12:07:56,699 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
12:07:56,700 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.FileAppender]
12:07:56,706 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [FAT]
12:07:56,728 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
12:07:56,757 |-INFO in ch.qos.logback.core.FileAppender[FAT] - File property is set to [logs/myproject/trace/messages.log]
12:07:56,757 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.FileAppender]
12:07:56,757 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [FAD]
12:07:56,758 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
12:07:56,759 |-INFO in ch.qos.logback.core.FileAppender[FAD] - File property is set to [logs/myproject/debug/messages.log]
12:07:56,759 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.FileAppender]
12:07:56,759 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [FAI]
12:07:56,759 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
12:07:56,760 |-INFO in ch.qos.logback.core.FileAppender[FAI] - File property is set to [logs/myproject/info/messages.log]
12:07:56,760 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.FileAppender]
12:07:56,760 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [FAW]
12:07:56,761 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
12:07:56,761 |-INFO in ch.qos.logback.core.FileAppender[FAW] - File property is set to [logs/myproject/warn/messages.log]
12:07:56,761 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.FileAppender]
12:07:56,761 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [FAE]
12:07:56,762 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
12:07:56,762 |-INFO in ch.qos.logback.core.FileAppender[FAE] - File property is set to [logs/myproject/error/messages.log]
12:07:56,762 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.FileAppender]
12:07:56,763 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [FAF]
12:07:56,763 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
12:07:56,764 |-INFO in ch.qos.logback.core.FileAppender[FAF] - File property is set to [logs/myproject/fatal/messages.log]
12:07:56,764 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.FileAppender]
12:07:56,764 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [DEFAULT]
12:07:56,765 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
12:07:56,765 |-INFO in ch.qos.logback.core.FileAppender[DEFAULT] - File property is set to [logs/default/info/messages.log]
12:07:56,766 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [FAT] to Logger[my.package]
12:07:56,766 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [FAD] to Logger[my.package]
12:07:56,766 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [FAI] to Logger[my.package]
12:07:56,766 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [FAW] to Logger[my.package]
12:07:56,766 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [FAE] to Logger[my.package]
12:07:56,766 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [FAF] to Logger[my.package]
12:07:56,766 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to DEBUG
12:07:56,766 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [DEFAULT] to Logger[ROOT]
12:07:56,766 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.

However, when I deploy the extension to my stand-alone server I'm getting the following log entries in console.log:

12:05:59,695 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [jar:file:/usr/share/neo4j/system/lib/neo4j-server-2.0.1.jar!/logback.xml]
12:05:59,696 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback.xml] occurs multiple times on the classpath.
12:05:59,696 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback.xml] occurs at [jar:file:/usr/share/neo4j/system/lib/neo4j-server-2.0.1.jar!/logback.xml]
12:05:59,696 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback.xml] occurs at [jar:file:/usr/share/neo4j/plugins/myproject.jar!/logback.xml]
12:05:59,710 |-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList@542ebbbd - URL [jar:file:/usr/share/neo4j/system/lib/neo4j-server-2.0.1.jar!/logback.xml] is not of type file
12:05:59,803 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
12:05:59,806 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
12:05:59,810 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
12:05:59,825 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
12:05:59,861 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to INFO
12:05:59,861 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]
12:05:59,861 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
12:05:59,862 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@4827a078 - Registering current configuration as safe fallback point

=> so I think that neither the settings from the logback config from neo4j nor the settings from the logback config from myproject will be registered and the fallback config (conf/logging.properties (?)) will be utilised.

Now my question is: is it possible to integrate an own logback config via an unmanaged extension or do I need to tweak the default logging.properties?

Was it helpful?

Solution

Have you tried to configure your logging in conf/custom-logback.xml? Neo4j bundles a logback.xml that includes this one.

OTHER TIPS

Here's the way how I got it working:

  1. remove logback.xml from your neo4j-server jar of your neo4j stand-alone installation (it's located, e.g., at /usr/share/neo4j/system/lib/)
  2. place your logback.xml at $NEO4J_HOME/conf/
  3. ensure that you've deployed only one logback.xml over the whole classpath of your neo4j stand-alone installation -> you can check this via reviewing the log file at $NEO4J_HOME/data/log/console.log)
  4. you may include the logback config from the logback.xml in the neo4j-server package into your logback.xml at $NEO4J_HOME/conf/)

point 3. and 4. are optional

Another aproach could be to rename your logback.xml.

This is the initialization steps that logback follows to try to configure itself:

  1. Logback tries to find a file called logback.groovy in the classpath.
  2. If no such file is found, logback tries to find a file called logback-test.xml in the classpath.
  3. If no such file is found, it checks for the file logback.xml in the classpath.
  4. If neither file is found, logback configures itself automatically using the BasicConfigurator which will cause logging output to be directed to the console.

If you rename your file to logback-test.xml, it would be preferred against the included logback.xml. This is how you use these settings files for tests as well.

The only negative point about this is, you can no longer use a different logback-test.xml for your tests.

As a last option, you can use the classpath parameter mentioned in the documentation, if you get it attached: -Dlogback.configurationFile=/path/to/config.xml

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top