Nixing screen output with log4j

One of the annoying things with log4j is that he always wants to dump stuff onto the screen. I do not need this if I register a file. I am sure that I have installed the log4j.properties file. Eliminating all of these configuration materials is disappointing! :-)

For the program that I am invoking Balancer, I am initializing my registrar. Perhaps this is wrong or something like that.

static Logger log = Logger.getLogger(Balancer.class); 

Partial dump of my log4j.properties:

 log4j.rootLogger=fatal, stdout log4j.logger.Balancer=fatal, rollingLog # I still don't understand how category stuff works yet log4j.category.Balancer=info, BalancerLog #### First appender writes to console log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%5p %d [%t] (%F:%L) - %m%n #### Second appender writes to a file # Control the maximum log file size # Archive log files (ten backups here) log4j.appender.rollingLog=org.apache.log4j.RollingFileAppender log4j.appender.rollingLog.File=default.log log4j.appender.rollingLog.MaxFileSize=10000KB log4j.appender.rollingLog.MaxBackupIndex=10 log4j.appender.rollingLog.layout=org.apache.log4j.PatternLayout log4j.appender.rollingLog.layout.ConversionPattern=%5p %d [%t] (%F:%L) - %m%n log4j.appender.BalancerLog=org.apache.log4j.RollingFileAppender log4j.appender.BalancerLog.File=Balancer.log log4j.appender.BalancerLog.MaxFileSize=100000KB log4j.appender.BalancerLog.MaxBackupIndex=10 log4j.appender.BalancerLog.layout=org.apache.log4j.PatternLayout log4j.appender.BalancerLog.layout.ConversionPattern=%5p %d [%t] (%F:%L) - %m%n 

I get how rootLogger sends stuff to appdd. Is there a / dev / null appender? You must have at least one application.

In any case, if nothing else, my main job now is to send the screen output to / dev / null. BTW, my Java programs run in a planned batch environment (no GUI). The reason for clearing buffered files (yes, this is on AS / 400) is a bit of a pain, although it can also be automated.

+6
source share
1 answer

Is there a / dev / null appender?

Yes.

 log4j.appender.devnull=org.apache.log4j.varia.NullAppender log4j.rootLogger=fatal, devnull 

I'm not sure where you got log4j.category.* , But this is not what I saw before, I would just use appender and logger .

 log4j.logger.Balancer=fatal, rollingLog, BalancerLog 

Sent fatal messages for a log named Balancer (no package prefix) for both rollLog and BalancerLog applications. If you change the registrar level to info

 log4j.logger.Balancer=info, rollingLog, BalancerLog 

then it will send info level and higher messages for both applications. You cannot restrict it so that BalancerLog receives info and higher, but rollLog receives only fatal messages based on each logger, but you can set a threshold in the rollLog application so that it records only fatal messages (regardless of the logger from which they came)

 log4j.appender.rollingLog=org.apache.log4j.RollingFileAppender log4j.appender.rollingLog.Threshold=fatal log4j.appender.rollingLog.File=default.log # other parameters as before 
+8
source

Source: https://habr.com/ru/post/922230/


All Articles