Reputation: 15755
I am using log4j1.2, and I am new to log4j.
I hope that when I am debugging in my local machine ,the logs will be printed to console. But when it is running in PROD , it just logs to file, since I hope to have the least overhead.
I hope that I can achieve this(only print to console when in local machine rather than the prod env) without modifying the properties file every time when I deploy.
Here is what my log4j.properties looks like:
log4j.rootLogger=DEBUG,BAE,console,error
##################production logs###############
log4j.appender.BAE=org.apache.log4j.FileAppender
log4j.appender.BAE.encoding=utf-8
log4j.appender.BAE.Append=true
log4j.appender.BAE.Threshold=INFO
log4j.appender.BAE.layout=org.apache.log4j.SimpleLayout
####################Conole logs####################
##(hope only enable when debuging in local machine)
log4j.appender.console= org.apache.log4j.ConsoleAppender
log4j.appender.console.encoding=utf-8
## DEBUG logs
log4j.appender.console.Threshold = Trace
log4j.appender.console.layout=org.apache.log4j.SimpleLayout
##################error logs##########################
log4j.appender.error=org.apache.log4j.FileAppender
log4j.appender.error.File=/home/bae/log/error.log
log4j.appender.error.Threshold = ERROR
log4j.appender.error.Append=true
log4j.appender.error.layout=org.apache.log4j.SimpleLayout
Upvotes: 4
Views: 20364
Reputation: 11
If you do not have the log4j file in your path, you'll need to add something like this:
-Dlog4j.configuration="file:///C:/<path>/<nameifLog4jFile>"
Also if you use an environment variable in the log4j file, you need to declare it in the arguments. I have an env var by the name MAS_HOME that I use to specify the path to the log file. I then had to add this parameter to VM args:
-DMAS_HOME="c:\EE"
Upvotes: 1
Reputation: 42010
You can configure another log4j configuration file in your environment in eclipse:
Enjoy!
See more in Apache log4j 1.2 - Short introduction to log4j
Upvotes: 6
Reputation: 929
You could use jvm param (answer from Brian Agnew : log4j configuration via JVM argument(s)?) :
Do you have a log4j configuration file ? Just reference it using
-Dlog4j.configuration={path to file}
where {path to file} should be prefixed with
file:
Upvotes: 0
Reputation: 4982
I wanted to put this as comment but there is not enough reputation :P
This might help if you are using Maven.
And also take a look at this question for another solution.
Upvotes: 0