Log4J Console Appender

I have the following Log4J Properties file:

log4j.rootLogger=ERROR, fileAppender, consoleAppender

log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender
log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.consoleAppender.layout.ConversionPattern=%m%n
log4j.appender.consoleAppender.Threshold=INFO

log4j.appender.fileAppender=org.apache.log4j.RollingFileAppender
log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.fileAppender.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} - %-5p [%t] - %c#%M: %m%n
log4j.appender.fileAppender.File=/myLogs/server.log
log4j.appender.fileAppender.MaxFileSize=10MB
log4j.appender.fileAppender.MaxBackupIndex=5

log4j.logger.test.class=INFO

The problems that I am currently experiencing are:

1. The console log can grow indefinitely. I came in after the weekend and found the log file was 90gigs....

2. At the bottom of the file I am setting: log4j.logger.test.class=INFO
This ensures that I have the right package level for all by logging, but if I set this to DEBUG everything gets out putted to the Console log, which is obviously not ideal.

What I would like is that I can some how control the max size of the console log and split it to multiple files if needed.
Secondly I want to make sure that only INFO information goes to the logs.

I'm not finding a huge amount on console appenders

Thanks
directxBOBAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
>>What I would like is that I can some how control the max size of the console log

You can only control the size of the file and that's not connected to the console appender - it's the file appender
0
directxBOBAuthor Commented:
That's what I was afraid of, is there any way to prevent DEBUG information from being output to the console log?
0
CEHJCommented:
Try
log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender
log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.consoleAppender.layout.ConversionPattern=%m%n
log4j.appender.consoleAppender.filter=org.apache.log4j.varia.LevelRangeFilter
log4j.appender.consoleAppender.filter.LevelMin=INFO
log4j.appender.consoleAppender.filter.LevelMax=FATAL

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

Mick BarryJava DeveloperCommented:
Use a file appender instead of a console appender, that way you can control the size
Or stop the stdout from being written to a file, that can get hard to manage whatever you set the level to

0
dpearsonCommented:
You actually might want to consider the RollingFileAppender (http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/RollingFileAppender.html).  It logs to a file and when the file reaches a certain size it rolls it over into a new file.  That way you can do things like archive the old logs or delete them, since the file is closed.  You can also control the maximum number of archive logs it keeps, so you can set a maximum total log size this way.

Once you've set this up you can run "tail -f mylog.file" to watch the end of the log file on the console - giving you console like logging behavior, but with file based logs and control over their size.

Doug
0
Amitkumar PSr. ConsultantCommented:
directxBOB,

I would suggest to use log4j.xml rather than log4j.properties to configure Log4j. You will avail advance features of Log4j using log4j.xml.

Refer : http://wiki.apache.org/logging-log4j/Log4jXmlFormat
0
CEHJCommented:
Yes, log4j.xml is better. Better still is to use logback

http://logback.qos.ch/reasonsToSwitch.html
0
Mick BarryJava DeveloperCommented:
changing your logging framework is not necessary to resolve your problem
0
directxBOBAuthor Commented:
Thanks for the help, can't really change the logging API as that would need approval.
0
Mick BarryJava DeveloperCommented:
Wouldn't make any difference if you did :)
0
CEHJCommented:
:)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.