Answer the question
In order to leave comments, you need to log in
About logback.xml - is it possible to specify in which package which appender to use?
Hello,
In terms of logging, my application is cut into 2 planes:
1 - local application logs
2 - logs of changes that this application makes to the database
So. According to clause 2, logs should be written to the database, respectively, they have a different logic, their own appender with a cache to write in batches, etc.
Well, the question arises, is it possible to somehow specify in the config file - here, in this class or package - I want to use this appender for the database, and in these packages - another appender?
If possible, for example the config:
<configuration>
<appender name="DB_APPENDER" class="com.test.logging.LogCachedAppender">
</appender>
<root level="debug">
<appender-ref ref="DB_APPENDER" />
</root>
</configuration>
Answer the question
In order to leave comments, you need to log in
I do like this:
<configuration debug="false">
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%-50class{50} [%-5level]: %msg%n</Pattern>
</layout>
</appender>
<appender name="gui" class="logback.appender.JavaFXAppender">
<layoutPattern>[%-5level]: %msg%n</layoutPattern>
</appender>
<!-- в коде я запрашиваю это логгер по имени, у него добавлен свой аппендер, все что передается в этот логгер - добавляется в добавленные аппендеры.
если удалить этот логгер, то все, что было адресовано ему - пойдет в root
-->
<logger name="cardservices" level="debug" additivity="false">
<appender-ref ref="gui" />
</logger>
<root>
<appender-ref ref="console" />
</root>
</configuration>
private static Logger logger = LoggerFactory.getLogger("cardservices");
...
//сообщение пойдет в логгер с именем "cardservices" и, соответственно в его аппендеры (для данного примера аппендер "gui".
logger.info("rere");
<configuration>
<appender name="DB_APPENDER" class="com.test.logging.LogCachedAppender">
</appender>
<logger name="DB_LOGGER" level="debug" additivity="false">
<appender-ref ref="DB_APPENDER" />
</logger>
<root level="debug">
<appender-ref ref="OTHER_APPERNDER" />
</root>
</configuration>
private static Logger logger = LoggerFactory.getLogger("DB_LOGGER");
Well, or in general, any way I can tie a specific logger only to my DB_APPENDER
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question