I have the following file:
Logback.xml
<configuration>
<insertFromJNDI scope="context" env-entry-name="java:jboss/properties/mypropertyfile" as="propertyfile" />
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
${mypattern1} %d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n
</Pattern>
</layout>
</appender>
<logger name="com.mkyong" level="debug" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
<root level="error">
<appender-ref ref="CONSOLE"/>
</root>
</configuration>
I want to reference variables in "mypropertyfile.properties" which is referenced via the insertFromJNDI tag.
Inside mypropertyfile.properties are some values:
mypropertyfile.properties
mypattern1=AAA
mypattern2=BBB
mypattern3=CCC
However it cannot find ${mypattern1} (or any) and it says it's undefined.
From the debug logs, I can see it is printing:
Setting variable [propertyfile] to [{mypattern1=AAA, mypattern2=BBB, mypattern3=CCC}]
and so I know it is reading the file.
But how can I use the variables within this file? If I were to use ${propertyfile} it would print the whole contents of the file.
Related
In my application I use Java, Hibernate.
Logging : I use logback.xml
Can anyone suggest if there is a way to disable the logs from the below specific class from Hibernate jar.
LOGGER to be removed from the specific class : ERROR o.h.e.jdbc.spi.SqlExceptionHelper
logback.xml:
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
</Pattern>
</layout>
</appender>
<logger name="org.springframework" level="error"
additivity="false">
<appender-ref ref="STDOUT" />
</logger>
<root level="error">
<appender-ref ref="STDOUT" />
</root>
</configuration>
Add the following to your logback.xml configuration file:
<logger name="org.hibernate.engine.jdbc.spi.SqlExceptionHelper" level="OFF"/>
The instruction: level="OFF" tells Logback to disable all log output for a given logger.
In your logback.xml configuration adding the following element should work
<logger name="org.hibernate.engine.jdbc.spi.SqlExceptionHelper" level="OFF"/>
I have specified in logback.xml the dependency on the Spring logger:
logging.file.path=logs
logging.file.name=${logging.file.path}/app.log
And now, when writing logs, a logs folder is created in the root folder of the project and for some reason the logging.path_IS_UNDEFINED folder is created too.
I have two questions:
How to make logs written not inside the project folder , but on the same level with it, while writing not an absolute path, but a relative one? That is, if the project is in D:\Projects\MyProject, then the logs should be in D:\Projects\logs
And why are the logs duplicated in logging.path_IS_UNDEFINED?
Here is my logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<Pattern>%d{HH:mm:ss.SSS} [%thread] %highlight(%-5level) %logger{36} - %msg%n</Pattern>
</encoder>
</appender>
<appender name="RollingFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${logging.path}/${logging.file}.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern>
</encoder>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>2MB</maxFileSize>
</triggeringPolicy>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${logging.path}/${logging.file}-%d{yyyy-MM-dd}-%i.log</fileNamePattern>
<maxFileSize>2MB</maxFileSize>
<maxHistory>30</maxHistory>
<totalSizeCap>10MB</totalSizeCap>
</rollingPolicy>
</appender>
<root level="INFO">
<appender-ref ref="Console"/>
</root>
<root level="DEBUG">
<appender-ref ref="RollingFile"/>
</root>
<logger name="com.my.project" level="TRACE" additivity="false">
<appender-ref ref="Console"/>
</logger>
<logger name="com.my.project" level="ERROR" additivity="false">
<appender-ref ref="RollingFile"/>
</logger>
<logger name="com.my.project" level="WARN" additivity="false">
<appender-ref ref="RollingFile"/>
</logger>
</configuration>
In my application I use Java, Hibernate.
Logging : I use logback.xml
Can anyone suggest if there is a way to disable the logs from the below specific class from Hibernate jar.
LOGGER to be removed from the specific class : ERROR o.h.e.jdbc.spi.SqlExceptionHelper
logback.xml:
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
</Pattern>
</layout>
</appender>
<logger name="org.springframework" level="error"
additivity="false">
<appender-ref ref="STDOUT" />
</logger>
<root level="error">
<appender-ref ref="STDOUT" />
</root>
</configuration>
Add the following to your logback.xml configuration file:
<logger name="org.hibernate.engine.jdbc.spi.SqlExceptionHelper" level="OFF"/>
The instruction: level="OFF" tells Logback to disable all log output for a given logger.
In your logback.xml configuration adding the following element should work
<logger name="org.hibernate.engine.jdbc.spi.SqlExceptionHelper" level="OFF"/>
How to disable logger (print output) of a java library (jar) used in a java program ?
For example i use the jar joda-time-2.8.2.jar
What should I put in my logback.xml file to disable the console output of the jar
logback.xml:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<Target>System.out</Target>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n</pattern>
</encoder>
</appender>
<logger name="com.paper.white" additivity="false" level="TRACE">
<appender-ref ref="stdout" />
</logger>
<root level="WARN">
<appender-ref ref="stdout" />
</root>
</configuration>
Just create a logger for org.joda.time and set the level to OFF.
<logger name="org.joda.time" level="OFF" >
<appender-ref ref="stdout"/>
</logger>
here is my java logback configuration:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<encoder charset="UTF-8">
<pattern>%d{yyyy-MM-dd HH:mm:ss} %-5level %msg%n></pattern>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder charset="UTF-8">
<pattern>%d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender>
<logger name="org.apache.zookeeper" additivity="false">
<appender-ref ref="stdout"/>
</logger>
<logger name="com.hazelcast" additivity="false">
<appender-ref ref="stdout"/>
</logger>
<root level="INFO">
<appender-ref ref="FILE" />
</root>
what i want to do here is:
I have two log appenders: one for console,and another for log file; But for the same java package(for example:org.apache.zookeeper) I want use two different log level,INFO for file appender and ERROR for condole;
But my log configuration upside doesn't work right.
Can anyone figure out my errors or some solutions?
Since the log level per Java package can only be defined globally, you may use a ThresholdFilter to filter all levels below ERROR in your console appender.
you can just block them:
<filter class="ch.qos.logback.core.filter.EvaluatorFilter">
<evaluator>
<expression>logger.contains("zookeeper") || logger.contains("hazelcast") </expression>
</evaluator>
<OnMismatch>ACCEPT</OnMismatch>
<OnMatch>DENY</OnMatch>
</filter>