В вашей настройке могут потребоваться 2 исправления, удалите теги immediateFlush
хотя бы для тестирования и добавьте JAMES-APPENDER
в root
регистратор.immediateFlush=false
должно быть установлено, когда ожидается интенсивное ведение журнала, для целей тестирования установите его на true
.
<root level="DEBUG">
<appender-ref ref="CONSOLE" />
<appender-ref ref="JAMES" />
<appender-ref ref="JAMES-SERVER" />
</root>
Настройка обратного входа может быть удобно протестирована с использованием пакета logback-examples следующим образом:
export LOGBACK_CP="/home/luis.munoz/.m2/repository/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1.jar:/home/luis.munoz/.m2/repository/ch/qos/logback/logback-core/1.1.3/logback-core-1.1.3.jar:logback-examples-1.1.3.jar:/home/luis.munoz/.m2/repository/ch/qos/logback/logback-classic/1.1.3/logback-classic-1.1.3.jar"
java -cp "$LOGBACK_CP" chapters.appenders.ConfigurationTester ~/tmp/logback.xml
Следующие сообщения будут записаны в консоль и любые настроенные файлы
12:37:45.336 [DEBUG] main c.a.ConfigurationTester:50 - **Hello test 123
12:37:45.338 [DEBUG] main c.a.ConfigurationTester:54 - logging statement 0
12:37:45.439 [DEBUG] main c.a.ConfigurationTester:54 - logging statement 1
12:37:45.540 [DEBUG] main c.a.ConfigurationTester:54 - logging statement 2
12:37:45.640 [DEBUG] main c.a.ConfigurationTester:54 - logging statement 3
12:37:45.742 [DEBUG] main c.a.ConfigurationTester:54 - logging statement 4
12:37:45.843 [DEBUG] main c.a.ConfigurationTester:54 - logging statement 5
12:37:45.943 [DEBUG] main c.a.ConfigurationTester:54 - logging statement 6
12:37:46.044 [DEBUG] main c.a.ConfigurationTester:54 - logging statement 7
12:37:46.145 [DEBUG] main c.a.ConfigurationTester:54 - logging statement 8
12:37:46.246 [DEBUG] main c.a.ConfigurationTester:54 - logging statement 9
12:37:46.355 [ERROR] main c.a.s.s.Bar:32 - error-level request
java.lang.Exception: test exception
at chapters.appenders.sub.sample.Bar.subMethodToCreateRequest(Bar.java:32) [logback-examples-1.1.3.jar:na]
at chapters.appenders.sub.sample.Bar.createLoggingRequest(Bar.java:27) [logback-examples-1.1.3.jar:na]
at chapters.appenders.ConfigurationTester.main(ConfigurationTester.java:58) [logback-examples-1.1.3.jar:na]
В консоли записано несколько записей журнала, полезных для отладки конфигурации
...
12:37:45,333 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [CONSOLE] to Logger[ROOT]
12:37:45,333 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [JAMES] to Logger[ROOT]
12:37:45,333 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [JAMES-SERVER] to Logger[ROOT]
...
Также этот пример пакета позволяет «поиграть» с конфигурацией и проверить результат.Например:
<logger name="chapters.appenders.ConfigurationTester" level="DEBUG" additivity="false">
<appender-ref ref="JAMES" />
</logger>
<logger name="chapters.appenders.sub.sample" level="DEBUG" additivity="false">
<appender-ref ref="JAMES-SERVER" />
</logger>
<root level="DEBUG">
<appender-ref ref="CONSOLE" />
</root>
Записывает это в james.log
16:04:44.487 [DEBUG] main c.a.ConfigurationTester:50 - **Hello test 123
16:04:44.490 [DEBUG] main c.a.ConfigurationTester:54 - logging statement 0
16:04:44.590 [DEBUG] main c.a.ConfigurationTester:54 - logging statement 1
16:04:44.691 [DEBUG] main c.a.ConfigurationTester:54 - logging statement 2
16:04:44.792 [DEBUG] main c.a.ConfigurationTester:54 - logging statement 3
16:04:44.892 [DEBUG] main c.a.ConfigurationTester:54 - logging statement 4
16:04:44.993 [DEBUG] main c.a.ConfigurationTester:54 - logging statement 5
16:04:45.093 [DEBUG] main c.a.ConfigurationTester:54 - logging statement 6
16:04:45.194 [DEBUG] main c.a.ConfigurationTester:54 - logging statement 7
16:04:45.295 [DEBUG] main c.a.ConfigurationTester:54 - logging statement 8
16:04:45.395 [DEBUG] main c.a.ConfigurationTester:54 - logging statement 9
И это в james-server.log
16:04:45.502 [ERROR] main c.a.s.s.Bar:32 - error-level request
java.lang.Exception: test exception
at chapters.appenders.sub.sample.Bar.subMethodToCreateRequest(Bar.java:32) [logback-examples-1.1.3.jar:na]
at chapters.appenders.sub.sample.Bar.createLoggingRequest(Bar.java:27) [logback-examples-1.1.3.jar:na]
at chapters.appenders.ConfigurationTester.main(ConfigurationTester.java:58) [logback-examples-1.1.3.jar:na]