I have an ANT based application and I have used slf4j logger to log at the exception, info, fatal etc. It is working fine. I am using log4j configuration for logging details. I used slf4j-log4j12-1.5.2.jar for this. Below is the configuration for logs.
log4j.rootLogger=info, file, stdout, stderr
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=cmd.log
log4j.appender.file.MaxFileSize=1024KB
log4j.appender.file.MaxBackupIndex=4
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss,SSS} %-5p (%13F:%L) %3x - %m%n
log4j.appender.errorFile=org.apache.log4j.RollingFileAppender
log4j.appender.errorFile.File=error_stream.log
log4j.appender.errorFile.MaxFileSize=1024KB
log4j.appender.errorFile.MaxBackupIndex=4
log4j.appender.errorFile.layout=org.apache.log4j.PatternLayout
log4j.appender.errorFile.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss,SSS} %-5p (%13F:%L) %3x - %m%n
log4j.appender.errorFile.Threshold=ERROR
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss} %5p - %m%n
log4j.appender.stderr=org.apache.log4j.ConsoleAppender
log4j.appender.stderr.Threshold=WARN
log4j.appender.stderr.Target=System.err
log4j.appender.stderr.layout=org.apache.log4j.PatternLayout
log4j.appender.stderr.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss} %5p - %m%n
I am calling my application through ant script as ant -f build.xml 1>out.txt 2>err.txt
Now it should stream all errors to err.txt. But its going into out.txt
Note : it is able to create error_stream.log and have errors. But not in err.txt
Do I am using wrong configuration properties?
Are you trying to define logging for your application launched by ANT? Or are you trying to define logging for ANT (the process encapsulating your application)?
If it's the latter, then ANT supports loggers and listeners, for an example:
Real time ant build analyzer
There is an issue with ant Task class. It handleErrorOutput as "warning" and further warning is stream into output stream.
You can modify the ant.jar with below changes. It will work.
Task_before_changes.java
protected void handleErrorOutput(String output) {
log(output, Project.MSG_WARN);
}
Task_after_changes.java
protected void handleErrorOutput(String output) {
log(output, Project.MSG_ERR);
}
Related
I have recently migrated application from log4j1.x to log4j2.17.1. Application logs are printed well in console as well as in Rolling file when start the tomcat server. I could see Tomcat server start up logs are all printing in catalina.log but the same server startup logs and any other server internal logs are not printed in rolling file. Rolling file prints only those logs are coming from class files. Could you anyone of you suggest what can be done to print all application server start up logs like some logs gets printed in console before server start or connection refused logs etc. also get printed into Rolling file? Same things was working well when I had log4j1.x version.It means when I had log4j1.x server start up logs are printed well in catalina as well as in a DailyRollingFileAppender but Now issue is only with log4j2, it means server start up logs are printed in catalain only not in a rolling file which I want. Please suggest.
Here is my log4j2.properties
rootLogger.level = info
property.filename =D:/log/TEST.log
appenders = R, console
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d %5p [%t] (%F:%L) - %m%n
appender.R.type = RollingFile
appender.R.name = File
appender.R.fileName = ${filename}
appender.R.filePattern = ${filename}.%d{yyyy-MM-dd}
appender.R.layout.type = PatternLayout
appender.R.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p [%15.15t]: %c{1}:%L - %m%n
appender.R.policies.type = Policies
appender.R.policies.time.type = TimeBasedTriggeringPolicy
appender.R.policies.time.interval = 1
rootLogger.appenderRef.console.ref = STDOUT
rootLogger.appenderRef.R.ref = File
I use tomcat as server and log4j can work on windows and Linux. When I deploy it with Docker, log4j can't work normally. And I find nothing is created in related folder. I don't find any error in catalina.log. I check the access rights for tmp folder and writing is allowed. Do you have any idea about source of the problem? Thanks.
log4j.rootLogger=INFO, DailyRolling, Terminal, CONSOLE
#log4j.rootLogger=DEBUG, A1, A2, DailyRolling, Terminal, CONSOLE
log4j.appender.DailyRolling=org.apache.log4j.RollingFileAppender
log4j.appender.DailyRolling.layout=org.apache.log4j.PatternLayout
log4j.appender.DailyRolling.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-7p (%c) %m%n
log4j.appender.DailyRolling.DatePattern='.'yyyy-MM-dd-a
#LINUX
log4j.appender.DailyRolling.File=/tmp/RolingLog.log
log4j.appender.DailyRolling.DatePattern=yyyy-MM-dd'.log'
log4j.appender.DailyRolling.Threshold=INFO
log4j.appender.DailyRolling.BufferedIO=true
log4j.appender.DailyRolling.BufferSize=8192
log4j.appender.DailyRolling.MaxFileSize=20MB
log4j.appender.DailyRolling.MaxBackupIndex=100
log4j.appender.DailyRolling.MaxBackupDay=10
log4j.appender.Terminal=org.apache.log4j.RollingFileAppender
log4j.appender.Terminal.MaxBackupDay=10
#LINUX
log4j.appender.Terminal.File=/tmp/LogConsole.log
log4j.appender.Terminal.layout=org.apache.log4j.PatternLayout
log4j.appender.Terminal.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-7p (%c) %m%n
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.encoding=UTF-8
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.conversionPattern=%d [%t] %-5p %c - %m%n
log4j.logger.httpclient.wire=INFO
log4j.logger.org.apache.commons=INFO
log4j.logger.org.hibernate=WARN
log4j.logger.org.oracle=INFO
log4j.logger.com.mchange.v2=INFO
log4j.logger.org.apache.commons.httpclient=WARN
log4j.logger.org.apache.xerces=ERROR
log4j.logger.org.springframework=INFO
Just begin to learn Apache Flume. I follow the instructions on Flume official getting started website:
https://cwiki.apache.org/confluence/display/FLUME/Getting+Started
Almost everything is fine after follow the instructions on above link. But I could not find any log file afterwards. I suppose log file is under {flume.directory}/logs. Any idea to find flume log files?
Here comes my log4j.properties:
flume.root.logger=INFO,LOGFILE
flume.log.dir=./logs
flume.log.file=flume.log
log4j.logger.org.apache.flume.lifecycle = INFO
log4j.logger.org.jboss = WARN
log4j.logger.org.mortbay = INFO
log4j.logger.org.apache.avro.ipc.NettyTransceiver = WARN
log4j.logger.org.apache.hadoop = INFO
log4j.logger.org.apache.hadoop.hive = ERROR
# Define the root logger to the system property "flume.root.logger".
log4j.rootLogger=${flume.root.logger}
# Stock log4j rolling file appender
# Default log rotation configuration
log4j.appender.LOGFILE=org.apache.log4j.RollingFileAppender
log4j.appender.LOGFILE.MaxFileSize=100MB
log4j.appender.LOGFILE.MaxBackupIndex=10
log4j.appender.LOGFILE.File=${flume.log.dir}/${flume.log.file}
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.LOGFILE.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss,SSS} %-5p [%t] (%C.%M:%L) %x - %m%n
# Warning: If you enable the following appender it will fill up your disk if you don't have a cleanup job!
# This uses the updated rolling file appender from log4j-extras that supports a reliable time-based rolling policy.
# See http://logging.apache.org/log4j/companions/extras/apidocs/org/apache/log4j/rolling/TimeBasedRollingPolicy.html
# Add "DAILY" to flume.root.logger above if you want to use this
log4j.appender.DAILY=org.apache.log4j.rolling.RollingFileAppender
log4j.appender.DAILY.rollingPolicy=org.apache.log4j.rolling.TimeBasedRollingPolicy
log4j.appender.DAILY.rollingPolicy.ActiveFileName=${flume.log.dir}/${flume.log.file}
log4j.appender.DAILY.rollingPolicy.FileNamePattern=${flume.log.dir}/${flume.log.file}.%d{yyyy-MM-dd}
log4j.appender.DAILY.layout=org.apache.log4j.PatternLayout
log4j.appender.DAILY.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss,SSS} %-5p [%t] (%C.%M:%L) %x - %m%n
# console
# Add "console" to flume.root.logger above if you want to use this
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.target=System.err
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d (%t) [%p - %l] %m%n
Cause your configuration use a relative path :
flume.log.dir=./logs
log4j.appender.LOGFILE.File=${flume.log.dir}/${flume.log.file}
Flume use your current directory to log.
(the directory where you are when you launch flume)
You can use an absolute path for flume.log.dir if you want to force flume to log in that path, no matter where you launch it.
Based on your log4j.properties, it would be in the same directory where you start your flume-agent, thats what ./ would do.
So, if you run from /home directory, it would be
/home/logs/flume.log
Also, you can use linux commands anytime to find that out,
find / -name flume.log ##search in whole disk
find . -name flume.log ##search in current directory
I have the following file appender and I'm wanting the specific environment to be output to the log file whenever a message is logged:
appenders {
rollingFile name:'mtagradepush_file',
maxFileSize: 2048,
file: "${globalDirs.logDirectory}${appName}.log".toString(),
layout:pattern(conversionPattern: "[Env:${app.log.env}] %d{yyyy-MM-dd HH:mm:ss} %5p %c{1}:%L - %m%n")
}
This conversion pattern worked when I used it in a log4j.properties file in a normal Java app, but now when using it with Grails it's not printing the value of the environment to the log file.
The app.log.env variable is being set in CATALINA_OPTS when the Tomcat 6 server starts up, like this:
export CATALINA_OPTS="-Xms128m -Xmx2000m -XX:MaxPermSize=512m
-Dapp.log.env=DEVL..."
If it's not possible to reference this variable then is there a way to grab the Grails environment variable?
Treat the ${} as a block of Groovy code and do a ${System.getProperty('app.log.env')}
I've been using the javamelody monitoring plugin for a while in Grails with no problem, but lately I had to move my developments to another computer (I'm now using netbeans 7.1.2). After reinstalling the plugins, I run the app flawlessly in my development environment. But when I run the war to my production environment, the following warnings show up:
log4j:WARN No appenders could be found for logger (net.bull.javamelody).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
The appenders section in Config.groovy is:
appenders {
console name:'stdout', layout:pattern(conversionPattern: '%d [%t] %-5p %c{2} %x - %m%n')
appender new DailyRollingFileAppender (
name: 'dailyAppender',
datePattern: "'.'yyyy-MM-dd",
fileName: "logs/${appName}.log",
layout: pattern(conversionPattern:'%d [%t] %-5p %c{2} %x - %m%n')
)
}
My questions are:
Why aren't these warnings present in the development environment's log ?What are possible consecuences on the application ?
I'm running Grails 1.3.9, Melody 1.2, tomcat 7.0.23
Thanks
It might be different form environment to environment if you have
setup a logging appender in the development section of your Grails
Config.groovy file but not for your production section.
The consequences are that you will not have logging. You may have code in your application that says log.error("Critical Error!") but since this is not linked to any appender you will never see it anywhere.
Check out logging in the documentation.