We followed all the posts and documentation out there but can't get any DEBUG statements generated by Hazelcast.
Hazelcast v.3.4.1 Tomcat 7 application server. Slf4j v.1.7.5
Hazelcast config:
<properties>
<property name="hazelcast.logging.type">slf4j</property>
</properties>
Logback.xml
EDIT: Here is a full logback.xml
<configuration scan="true">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} %-5level %logger{0} - [%X{sessionID}] - [%X{loginID}] - %msg%n</pattern>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${catalina.base}/logs/app.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${catalina.base}/logs/app.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>2</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger - [%X{sessionID}] - [%X{loginID}] - %msg%n</pattern>
</encoder>
</appender>
<logger name="org.mybatis" level="debug" additivity="false">
<appender-ref ref="FILE" />
</logger>
<logger name="com.hazelcast" level="debug" additivity="false">
<appender-ref ref="FILE" />
</logger>
<root level="warn">
<appender-ref ref="FILE" />
</root>
Seems like something else is needed. No hazelcast logging is visible.
I would appreciate some help.
Do you see somethng like this in the logging?
INFO: [192.168.122.1]:5701 [dev] [3.5.1]
Members [1] {
Member [192.168.122.1]:5701 this
}
Because this is a clear indication that the Hazelcast logging is working correctly. If you don't see this, then there really is a logging problem, otherwise there probably is some kind of log level problem.
Related
I have a spring boot microservice application. logback.xml is configured to write the logs to a location on the server. In addition to this, I want to write logs from a particular java class to Syslog. I do not want logs from all other classes to be written to syslog but to a rolling file appender. Is there a way to configure this using logback.
below is my logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="DEV_HOME" value="logs"></property>
<appender name="Console"
class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1.}): %msg%n%throwable
</Pattern>
</layout>
</appender>
<appender name="RollingFile"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/data/storage/log/cms.log</file>
<encoder
class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
</encoder>
<rollingPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- roll over daily and when the file reaches 10 MB, max of 7 days or 3GB threshold -->
<fileNamePattern>/data/storage/log/cms.%d{yyyy-MM-dd}.%i.Logs.gz
</fileNamePattern>
<maxFileSize>100MB</maxFileSize>
<maxHistory>7</maxHistory>
<totalSizeCap>3GB</totalSizeCap>
</rollingPolicy>
</appender>
<appender name="SPECIFIC_CLASS" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${DEV_HOME}/sizeTimeOutputlogFile.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>[%d{yyyy-MM-dd HH:mm:ss}] %p %c{1.} [%t]- %m%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${DEV_HOME}/archived/sizeTimeOutputlogFile.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!--Max Size of file to start Archive -->
<maxFileSize>10KB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!-- Days till log history to keep -->
<maxHistory>3</maxHistory>
</rollingPolicy>
</appender>
<!--syslog appender-->
<appender name="SYSLOG" class="ch.qos.logback.classic.net.SyslogAppender">
<syslogHost>localhost</syslogHost>
<facility>LOCAL0</facility>
<port>514</port>
<throwableExcluded>true</throwableExcluded>
<suffixPattern>%thread: %-5level %logger{36} - %msg%n</suffixPattern>
</appender>
<!-- LOG everything at ERROR level -->
<root level="ERROR">
<appender-ref ref="RollingFile"/>
<appender-ref ref="Console"/>
</root>
<!-- LOG "com.myproject*" at ERROR level -->
<logger name="com.myproject" level="ERROR" additivity="false">
<appender-ref ref="RollingFile"/>
<appender-ref ref="Console"/>
</logger>
<logger name="com.myproject.ActivityLogAspect" level="DEBUG" additivity="false">
<appender-ref ref="SYSLOG"/>
<appender-ref ref="SPECIFIC_CLASS"/>
</logger>
</configuration>
From the above XML, SYSLOG and SPECIFIC_CLASS appenders are used to write logs from ActivityLogAspect class. When I run my application I see that only SPECIFIC_CLASS is working. I don't see any logs written to /var/log/messages. But if I add the SYSLOG appender along with the console appender, I see the messages written to /var/log/messages.
I do not want logs from all classes written to syslog but only from one particular class.
Please advise.
I am trying to log the spring boot applications logs to a separate directory(apps-archive ie ${catalina.base}/logs/apps-archive/log.log) in the external tomcat. After I start the server the log file is empty, and there are some logs in catalina.2021-04-04.log file about application is deployed and so...
In my spring boot application I have logback-spring.xml in src/main/resources as
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>
%d [%thread] %-5level %-50logger{40} : %msg%n
</pattern>
</encoder>
</appender>
<property name="LOG_PATH" value="${catalina.base}/logs/apps-archive"/>
<appender name="SAVE-TO-FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_PATH}/log.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>
%d [%thread] %-5level %-50logger{40} : %msg%n
</Pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>
${LOG_PATH}/log_%d{dd-MM-yyyy}_%i.log
</fileNamePattern>
<maxFileSize>20MB</maxFileSize>
<maxHistory>10</maxHistory>
<totalSizeCap>400MB</totalSizeCap>
</rollingPolicy>
</appender>
<springProfile name="dev">
<root level="info">
<appender-ref ref="STDOUT"/>
<appender-ref ref="SAVE-TO-FILE"/>
</root>
<!-- Hibernate loggers -->
<logger level="DEBUG" name="org.hibernate"/>
<logger level="INFO" name="com.commerzbank.eudsgvo"/>
<logger level="DEBUG" name="org.hibernate.type.descriptor.sql"/>
<logger level="DEBUG" name="org.springframework"/>
</springProfile>
</configuration>
I have no configuration for logging in application.properties file. Can anyone please suggest me why logs file is empty in apps-archive directory on server.
The default profile spring boot apps run with is default.
Can you please change
<springProfile name="dev">
to
<springProfile name="default">
Regarding the issues with the RollingPolicy I don't have any ideas at the moment.
I use logback to print log in my SpringBoot application. When I check out the log file, I found that, all log message print twice! It is so strange .
Yeah, I have found some answer similar to my issue. But maybe they are not what I want.
here is my logback.xml:
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false">
<property name="LOG_HOME" value="${user.home}/app/logs"/>
<appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS}-[%thread]-%-5level-%logger{50}: %msg%n</pattern>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- rollover daily -->
<fileNamePattern>${LOG_HOME}/cloud-sync-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<!-- each file should be at most 10MB, keep 3 days worth of history, but at most 1GB -->
<maxFileSize>10MB</maxFileSize>
<maxHistory>3</maxHistory>
<totalSizeCap>1GB</totalSizeCap>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
</encoder>
</appender>
<appender name ="ASYNC" class= "ch.qos.logback.classic.AsyncAppender">
<discardingThreshold >0</discardingThreshold>
<queueSize>256</queueSize>
<includeCallerData>true</includeCallerData>
<appender-ref ref ="FILE"/>
</appender>
<root level="INFO">
<appender-ref ref="Console"/>
<appender-ref ref="FILE"/>
<appender-ref ref="ASYNC"/>
</root>
</configuration>
How can I make sure log messages appear only once. Thank you.
It is because you have added ASYNC and FILE for INFO.
Please remove one of them based on your requirement.
Any help or hint would be greatly appreciated!!
My SpringBoot application is logging only 1 day. I want it to log more than 30 days.
logback-spring.xml
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<charset>UTF-8</charset>
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder>
<charset>UTF-8</charset>
<pattern>${FILE_LOG_PATTERN}</pattern>
</encoder>
<file>${LOG_FILE}</file>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>${LOG_FILE}.%i</fileNamePattern>
<minIndex>1</minIndex>
<maxIndex>10</maxIndex>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<MaxFileSize>10MB</MaxFileSize>
</triggeringPolicy>
</appender>
<logger name="ca.test.hub" level="INFO" additivity="false">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
</logger>
<logger name="org.apache.cxf" level="INFO" additivity="false">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
</logger>
<logger name="org.hibernate" level="DEBUG" additivity="false">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
</logger>
<logger name="org.springframework" level="INFO" additivity="false">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
</logger>
application.yml:
logging:
file: logs/test.log
pattern:
console: "%d{dd-MM-yyyy HH:mm:ss.SSS} [%thread] %-5level %logger{36}.%M - %msg%n"
file: "%d{dd-MM-yyyy HH:mm:ss.SSS} [%thread] %-5level %logger{36}.%M - %msg%n"
level:
root: INFO
If you want to keep log files for more than 30 days your best bet is not to use FixedWindowRollingPolicy (documentation), which is used if you only want to limit the amount of log files that are kept on the file system.
A better appender suited for your requirements would be SizeAndTimeBasedRollingPolicy which, as stated in the documentation,
archive[s] files essentially by date but at the same time limit the size
of each log file
My suggested edit to your current FILE appender would be something like this
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder>
<charset>UTF-8</charset>
<pattern>${FILE_LOG_PATTERN}</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOG_FILE}-%d{yyyy-MM-dd}.%i</fileNamePattern>
<maxFileSize>10MB</maxFileSize>
<maxHistory>30</maxHistory>
</rollingPolicy>
</appender>
This SizeAndTimeBasedRollingPolicy stores files with the fileNamePattern LOG_FILE-2019-05-02.0 (LOG_FILE would of course be the value for the ${LOG_FILE} variable). This file will roll over every time it reaches a size larger that 10MB - and then a new file, LOG_FILE-2019-05-02.1, will be created and written to.
First log to be written after midnight would then create a new file, LOG_FILE-2019-05-03.0, and write to it. Log files older than 30 days will be deleted. Adjust the configuration to best suit your needs.
I'd recommend you read the documentation for this appender to get a bit more details.
Is it anyway to send startup logs to file, right now all logs up to the statement "Started Application in...." goes to stdout, I want all logging to file.
My logback config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<property name="LOG_FILE" value="logs/app${PID}.log"/>
<appender name="AI-APPENDER"
class="com.microsoft.applicationinsights.logback.ApplicationInsightsAppender">
</appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<encoder>
<pattern>${FILE_LOG_PATTERN}</pattern>
</encoder>
<file>${LOG_FILE}</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOG_FILE}.%d{yyyy-MM-dd}.%i.gz</fileNamePattern>
<maxFileSize>${LOG_FILE_MAX_SIZE:-10MB}</maxFileSize>
<maxHistory>30</maxHistory>
</rollingPolicy>
</appender>
<root level="INFO">
<appender-ref ref="FILE"/>
<appender-ref ref="AI-APPENDER"/>
</root>
</configuration>
You need to configure your logging framework. Assuming you're just using the default from spring-boot then that's LogBack. So have a look at their docs or have a search, there are many useful resources (like this one)
If you add a logback.xml file with the following content to your resources folder you should get logging to both console and file (called application.log) in the same format as you now see for just console.
<configuration>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>application.log</file>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="info">
<appender-ref ref="FILE" />
<appender-ref ref="STDOUT" />
</root>
</configuration>
You probably want to use a RollingFileAppender as this will allow you to create new files when the log file gets big.