I have mule 3.8.1. I can see logs for each app I have in %MULE_BASE%/logs/%MULE_APP%.log just like defined in wrapper.conf file. Example log files I have are:
mule-app-APP1.log.2020-04-07
mule-app-APP1.log
mule-app-APP2.log.2020-04-07
mule-app-APP2.log
I understand that by default logs are created in the format %MULE_APP%.log where MULE_APP is mule-app-<app_name>.
My question is about "rolling" files. I mean, creating a new log file each day. There is log4j2.xml in the project but there is only AsyncRoot appender pointing out to Console appender. My question: is the "rolling" log files behavior default in mule ? or there must be a configuration set in the project by someone else, that I'm missing ?
This is not Mule behaviour. This is log4j2 behaviour which is defined in the log4j2.xml file. If you have definition like this
<RollingFile name="file" fileName="${sys:mule.home}${sys:file.separator}logs${sys:file.separator}myApp.log"
filePattern="${sys:mule.home}${sys:file.separator}logs${sys:file.separator}myApp-%i.log">
<PatternLayout pattern="%-5p %d [%t] [event: %X{correlationId}] %c: %m%n" />
<SizeBasedTriggeringPolicy size="10 MB" />
<DefaultRolloverStrategy max="10"/>
</RollingFile>
which is generate automatically when you create myApp mule Application then you will alwyas have only 10 latest rolling logs.
If you elimate fileName like this
<RollingFile name="file"
filePattern="${sys:mule.home}${sys:file.separator}logs${sys:file.separator}myApp-%i.log">
<PatternLayout pattern="%-5p %d [%t] [event: %X{correlationId}] %c: %m%n" />
<SizeBasedTriggeringPolicy size="10 MB" />
<DefaultRolloverStrategy max="10"/>
</RollingFile>
then you will have behaviour like you described with infinite rolling logs.
See more about this here https://simpleflatservice.com/mule4/RollingLogFiles.html
Related
We have an issue where whenever our Gatling performance tests are run the .log file that should generate at the root of the folder is not there.
This is my whole logback file if anyone able to help please.
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
<resetJUL>true</resetJUL>
</contextListener>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<!-- <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level>
</filter> -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%-5level] %logger{15} - %msg%n%rEx</pattern>
<immediateFlush>true</immediateFlush>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>testFile.log</file>
<append>false</append>
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%-5level] %logger{15} - %msg%n%rEx</pattern>
</encoder>
</appender>
<!-- uncomment and set to DEBUG to log all failing HTTP requests -->
<!-- uncomment and set to TRACE to log all HTTP requests -->
<logger name="io.gatling.http.engine.response" level="TRACE" />
<root level="WARN">
<appender-ref ref="CONSOLE" />
<appender-ref ref="FILE" />
</root>
Thank you very much.
Update
It seems the issue may be with IntelliJ itself as noticed we can see the file when going directly to the finder.
Disabling custom plugins should help. Seems one of configuration was corrupted.
There's a good chance the file is simply not generated where you expect it. Try setting an absolute path instead to verify.
I have a web service (Jenkins) that handles user requests, and I want to be able to dynamically append the request session id to each log line without having to actually add that variable to each and every log action.
I'm using log4j2 with slf4j implementation, I initialize the logger using an external configuration file with org.apache.logging.log4j.core.config.Configurator, I create an instance of the logger per every session using
final Logger logger = LoggerFactory.getLogger(MyClass.class);
I have for example:
logger.debug("received new request");
...
logger.debug("added something");
And I want the user session id to be added to each line without having to add it myself like:
logger.debug("{} received new request",session.getId());
...
logger.debug("{} added something",session.getId());
My log4j2.xml file is:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<Configuration status="INFO">
<Properties>
<Property name="logPath">...</Property>
<Property name="rollingFileName">...</Property>
</Properties>
<Appenders>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout pattern="[%highlight{%-5level}] %d{DEFAULT} %c{1}.%M() - %msg%n%throwable{short.lineNumber}" />
</Console>
<RollingFile name="rollingFile" fileName="${logPath}/${rollingFileName}.log" filePattern="${logPath}/${rollingFileName}_%d{yyyy-MM-dd}.log">
<PatternLayout pattern="[%highlight{%-5level}] %d{DEFAULT} %c{1}.%M() - %msg%n%throwable{short.lineNumber}" />
<Policies>
<!-- Causes a rollover if the log file is older than the current JVM's start time -->
<OnStartupTriggeringPolicy />
<!-- Causes a rollover once the date/time pattern no longer applies to the active file -->
<TimeBasedTriggeringPolicy interval="1" modulate="true" />
</Policies>
</RollingFile>
</Appenders>
<Loggers>
<Logger name="com.project" level="debug" additivity="false">
<AppenderRef ref="console"/>
<AppenderRef ref="rollingFile"/>
</Logger>
</Loggers>
</Configuration>
Actual results from current log file:
[[36mDEBUG[m] 2019-02-05 16:42:09,794 SpellCheck.getResult() - start
[[36mDEBUG[m] 2019-02-05 16:42:10,420 SpellCheck.getResult() - Spelling correction returned no results.
[[36mDEBUG[m] 2019-02-05 16:42:10,420 SpellCheck.getResult() - end
What I want to achieve:
[[36mDEBUG[m] 2019-02-05 16:42:09,794 SpellCheck.getResult() - 1234 - start
[[36mDEBUG[m] 2019-02-05 16:42:10,420 SpellCheck.getResult() - 1234 - Spelling correction returned no results.
[[36mDEBUG[m] 2019-02-05 16:42:10,420 SpellCheck.getResult() - 1234 - end
Where 1234 is for example the session id.
Thanks.
I figured it out, was a lot easier than I thought.
Basically added %X{userSessionId} to the
<PatternLayout pattern= ... />
row in log4j2.xml.
And in the code added
HttpSession session = request.getSession();
org.apache.logging.log4j.ThreadContext.put("userSessionId", session.getId());
I have two log4j2 generated log files. I am generating these log files using FileAppender and now I want to send those log files to AWS cloudwatch and S3 bucket as a log4j2 destination.
I am new to log4j2 and this cloud API. I have searched a lot but not able to find something useful. Though I have found these two links:
http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ec2-configuration-cwl.html and http://docs.aws.amazon.com/AWSSdkDocsJava/latest/DeveloperGuide/java-dg-logging.html
But I am not sure how it will work and whether Is this the only way to send log files to AWS cloudwatch and S3 bucket. And What other settings do I need to do in my log4j2.xml file.
So, how to send log4j2 generated log files to cloud API? I have to use log4j2 and J2EE.
Here is my log4j2.xml file:
<Configuration monitorInterval="30" status="warn" name= "MyApp" packages="" xmlns="http://logging.apache.org/log4j/2.0/config">
<Properties>
<Property name="filename-server1-all">${sys:catalina.home}/logs/server1-all.log</Property>
<Property name="filename-server1-err">${sys:catalina.home}/logs/app.log</Property>
<Property name="pattern_layout">%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n</Property>
</Properties>
<Appenders>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout pattern="%-5p | %d{yyyy-MM-dd HH:mm:ss} | [%t] %C{2} (%F:%L) - %m%n"/>
</Console>
<File name="appender-server-1-all" fileName="${filename-server1-all}">
<PatternLayout pattern="${pattern_layout}" />
</File>
<File name="appender-server1-err" fileName="${filename-server1-err}">
<PatternLayout pattern="${pattern_layout}" />
</File>
</Appenders>
<Loggers>
<Root level="trace">
<AppenderRef ref="STDOUT"/>
<AppenderRef ref="appender-server-1-all" level="all"/>
<AppenderRef ref="appender-server1-err" level="error"/>
</Root>
</Loggers>
</Configuration>
Does Mule ESB support log4j2? I am trying to add log4j2.xml in my esb app, but even after adding log4j2.xml, my mule esb app is defaulting to its own log4j 1.2 implementation. I want my esb app to read my log4j2.xml file and take/consume in the parameters what I am specifying in my log4j2.xml and if log4j2.xml file is present then it should not read its own log4j 1.2 implementation log properties file.
I am having problem in implementing log4j2(.xml) with mule esb app. Any help would be very much appreciated.
The latest version of mule esb is supporting the log4j2 . Hope the version may be tightly coupled that could be the reason it might not work.
Log4j2 has an adapter allows application that are coded against the log4j-1.2 API to use the log4j2 implementation. (See also the FAQ.)
Steps to achieve this:
remove the log4j-1.2.x.jar from the classpath
add the log4j-1.2-api-2.0.jar jar to the classpath.
ensure that log4j-api-2.0.jar and log4j-core-2.0.jar are in the classpath
Now both the log4j-1.2 API and the log4j2 API will delegate to the log4j2 implementation. A sample configuration is here.
Log4j2 is implicitly supported from Mule-3.6.0 onwards. For more info please go through this link Asynchronous Logging in Mule
Mule esb supports log4j.
check if you have imported slf4j libraries.
You need to create/rename log4j2-test.xml
These are my log4j2.xml and my pom.xml files, I´m using mule v7.1.
I hope it helps.
log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="debug">
<Properties>
<Property name="log-path">/my_path/my_logs/my_app</Property>
<Property name="app-id">my_app</Property>
</Properties>
<Appenders>
<RollingFile name="file-log" fileName="${log-path}/${app-id}.log"
filePattern="${log-path}/${app-id}-%d{yyyy-MM-dd}.log">
<PatternLayout>
<pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n
</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy interval="1"
modulate="true" />
</Policies>
</RollingFile>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout
pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n" />
</Console>
</Appenders>
<Loggers>
<Logger name="org.apache.logging.log4j" level="warn" additivity="false">
<appender-ref ref="file-log" />
<appender-ref ref="console" />
</Logger>
<Root level="info" additivity="false">
<appender-ref ref="file-log" />
<appender-ref ref="console" />
</Root>`enter code here`
</Loggers>
</Configuration>
pom.xml
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.0</version>
</dependency>
I have configured Hibernate to use logback logging library. And created an appender that catches logging data from "org.hibernate.SQL" and "org.hibernate.type" loggers. By default, those are set to INFO level.
As the next step I try to change the level of those 2 loggers to DEBUG level using JMX interface of logback. But it does not work and log file contains no data. Only if I set the logging level to DEBUG in the configuration file and then restart the server it works.
Should I do anything additional in order to make Hibernate to start logging?
Here goes the appender/logger configuration:
<configuration debug="false" scan="true" scanPeriod="5 minutes">
<jmxConfigurator />
...
<property name="SQL_LOG_LEVEL" value="DEBUG" />
<appender name="SQL_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_DIRECTORY}/sql_${weblogic.Name}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>${ROTATION_DIRECTORY}/sql_${weblogic.Name}.%i.log.zip</fileNamePattern>
<minIndex>1</minIndex>
<maxIndex>5</maxIndex>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>50MB</maxFileSize>
</triggeringPolicy>
<encoder>
<pattern>${LOG_PATTERN}</pattern>
</encoder>
</appender>
<logger name="org.hibernate.SQL" level="${SQL_LOG_LEVEL}" additivity="false">
<appender-ref ref="SQL_LOG" />
</logger>
<logger name="org.hibernate.type" level="${SQL_LOG_LEVEL}" additivity="false">
<appender-ref ref="SQL_LOG" />
</logger>
...
</configuration>
EDIT: I have several applications (EAR) files deployed on the same container. All applications are using same logging configuration.
Problem appears to be in fact that I deploy several applications on one sever and, basically, each application's class loader has a copy of logback libraries. That's why several logging context are created, but because they all share the same name ("default"), basically, only one get registered to MBean server.
The solution could be either moving logback libraries higher in class loader hierarchy or use logger context separation as proposed by logback documentation.
I was not able to log any output from org.hibernate.SQL and friends until I set my log level to TRACE instead of DEBUG using logback over slf4j.