logging configuration with log4j.properties, cannot exclude package from logging to console - log4j

i have the following log4j.properties file. what i want to do is log everything at the level INFO or above to the console. however, for anything that falls in the demo.* package, i want to log everything at the DEBUG level to a file. my log4j.properties below does not seem to work. what happens is that any DEBUG message from demo.* still gets output to the console. any idea what i am doing wrong?
how can i exclude demo.* from logging to the console?
log4j.rootLogger=INFO, C
log4j.logger.demo=DEBUG, R1
log4j.appender.C=org.apache.log4j.ConsoleAppender
log4j.appender.C.target=System.err
log4j.appender.C.layout=org.apache.log4j.PatternLayout
log4j.appender.C.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{2}: %m%n
log4j.appender.R1=org.apache.log4j.RollingFileAppender
log4j.appender.R1.File=output.log
log4j.appender.R1.MaxFileSize=5MB
log4j.appender.R1.MaxBackupIndex=5
log4j.appender.R1.layout=org.apache.log4j.PatternLayout
log4j.appender.R1.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{2}: %m%n

sorry, never mind. i solved it by setting the threshold of the console appender.
log4j.appender.C.threshold=INFO

Related

Why I have question instead line number when logging with log4j

I try to configure logger to write line number but instead of it I have question.
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%t]:%L - %m%n
I figured out that it is not log4j problem but setting of my project. The most probably missing debug information in my compiled artifacts. (Line number not showing?) But how can I set that in IntellijIdea 2019.1?

How to configure to print out Ignite logs

I want to see the INFO level logs that Ignite prints during its running(so that it will help me on what Ignite is doing). I am using the following log4j.properties to make Ignite print INFO level logs,but the logs are not printed out.
Are there special configuration to make Ignite logs printed out?
Thanks.
log4j.rootCategory=INFO, stdout , R
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%p %d - [TS] %c %M(%L) - %m%n
log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.File=c:/ioc.ignite.log
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %d - [TS] %c %M(%L) - %m%n
log4j.logger.org.apache.ignite=INFO
log4j.logger.org.springframework=WARN
Please follow below steps:
e.g. if you are using log4j for logging
configure ignite/config/ignite-log4j.xml in gridLogger of IgniteConfiguration
e.g.
.........
uncomment "CONSOLE" appender in ignite/config/ignite-log4j.xml
copy ignite/libs/optional/ignite-log4j/log4j.jar and ignite/libs/optional/ignite-log4j/ignite-log4j.jar in ignite/libs/ folder
you can also set IGNITE_LOG_HOME environment variable to redirect the logs to any file
You should use <CLASSPATH>/config/ignite-log4j.xml file instead of log4j.properties.

Is there any way to log all the icefaces logs?

Our view layer are made from JSF 2.1.4,Icefaces 3.3.When we are starting our application we are able to see all the logs in eclipse console is there any way to log all the icefaces logs into a file .
# configure the ice-faces logging
log4j.appender=org.apache.log4j.RollingFileAppender
log4j.appender.File=D:/icefaces.log
log4j.appender.layout=org.apache.log4j.PatternLayout
log4j.appender.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} [%p] %c:%L - %m%n
log4j.appender.com.icesoft.faces.application.D2DViewHandler=FINEST
log4j.appender.com.sun.faces.config.ConfigureListener=FINEST
log4j.appender.org.icepush=FINEST
log4j.appender.org.icepush.application.PushRenderer=FINEST
log4j.appender.org.icepush.application.PortableRenderer=FINEST
log4j.appender.org.icefaces=FINEST
I have added the above code in my log4j.properties file, but it is not working I got from here here it is doing console appender, but I want FileAppender. Without specifying anything how it will decide what to log e.g I have configured other logs and it is logging, in the log4j.properties I have mentioned like
log4j.appender.defalut=org.apache.log4j.RollingFileAppender
log4j.appender.defalut.File=D:/xyz.log
log4j.appender.defalut.MaxFileSize=20MB
log4j.appender.defalut.MaxBackupIndex=5
log4j.appender.defalut.layout=org.apache.log4j.PatternLayout
log4j.appender.defalut.layout.conversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} [%p] %c:%L - %m%n

log4j appender with a file url

I have a problem where log4j is not logging to one of my files and i'm not sure why. I have some code that runs scripts, the scripts can add logging which is logged to a file using log4j, I am trying to create an appender that only logs for a particular script.
log4j.logger.com.my.class=INFO, JS_LOG
log4j.appender.JS_LOG.layout=org.apache.log4j.PatternLayout
log4j.appender.JS_LOG.Encoding=UTF-8
log4j.appender.JS_LOG.File=${log.outputdir}/js_service.log
log4j.appender.JS_LOG.MaxFileSize=2MB
log4j.appender.JS_LOG.MaxBackupIndex=10
log4j.appender.JS_LOG.Append=true
log4j.appender.JS_LOG=org.apache.log4j.RollingFileAppender
log4j.appender.JS_LOG.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n
the above appender works and i get this in my log file
2012-04-18 11:25:52,043 [<MD> Inc Msg Dispatch-1 New] INFO com.my.class.file:/myfile - info
when the script logs something it logs to a logger of the form
com.my.class.file:/myfile this appears in the log using the above config in my log4j.properties file.
if I change the above to:
log4j.logger.com.my.class.file:/myfile=INFO, JS_LOG
log4j.appender.JS_LOG.layout=org.apache.log4j.PatternLayout
log4j.appender.JS_LOG.Encoding=UTF-8
log4j.appender.JS_LOG.File=${log.outputdir}/js_service.log
log4j.appender.JS_LOG.MaxFileSize=2MB
log4j.appender.JS_LOG.MaxBackupIndex=10
log4j.appender.JS_LOG.Append=true
log4j.appender.JS_LOG=org.apache.log4j.RollingFileAppender
log4j.appender.JS_LOG.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n
nothing is logged to the file. I would have thought this should work? I retrieve the file
I managed to solve this problem, its something to do with the file: in my log4j.properties I changed the appender to file_ then in my code I do some manipulation to the file url to make it match the appender.

FileAppender not writing anything in log4j

I have a small problem using log4j and FileAppender. When I am using ConsoleAppender, everything is working well but FileAppender won't ever produce a file (or write into a file). Moreover, I have no errors concerning log4j in the osgi console.
Here's my configuration :
# main link (console or file, depending on what we want)
# log4j.category.com.foo=DEBUG, console
log4j.category.com.foo=DEBUG, file
# log4j.category.com.foo=DEBUG, console, file
# console logging
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%-4r %-5p %c %x - %m%n
# file logging
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=C:\\Users\\foo\\some_file.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%-4r %-5p %c %x - %m%n
Note that the ConversionPattern attributes are exactly the same in the two appenders.
I have tried to change the File argument to write the log in the "run" directory but it didn't do anything.
I also tried to add log4j.appender.file.ImmediateFlush=true without success.
Have I missed something (obvious ?) somewhere ? It sound strange that log4j isn't even able to write a simple log in a file....
Thanks a lot in advance for your help.
Replace :
log4j.category.com.foo=DEBUG, console
By :
log4j.category.com.foo=DEBUG, console, file
I know this is old but for other Googlers...
For me it was simply using wrong package.
I used org.apache.logging.log4j instead org.apache.log4j
If you are using Maven use this:
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>

Resources