I am trying to make my Web Services Application Log using Wildfly 8.1 Final Log System Categories.
My App declares
private static final Logger LOGGER = Logger.getLogger("myapp");
It calls in parts of the code for
LOGGER.debug("something");
Using the log4j property file definition below it behaves as expected. The problem is when I access the Wildfly console (http://localhost:9990/console/App.html#logging) and update the Log Category named "myapp" from INFO to DEBUG. After tha I call my Web Service that calls the instruction LOGGER.debug("something"); inside it´s code.
The expected behavior is to show the "something" message written in my log file, but it does not happens because it behaves obeying only the log4j property file supplied below.
How to fix this?
#------------------------------------------------------------------------------
#log4j.rootLogger=DEBUG, stdout
log4j.logger.org.hibernate=INFO, stdout, myapp
log4j.logger.org.hibernate.SQL=INFO, stdout, myapp
log4j.logger.org.hibernate.type.descriptor.sql=ALL, stdout, myapp
log4j.logger.myappaudit=INFO, myappaudit
log4j.logger.myapp=INFO, stdout, myapp
log4j.logger.performance=INFO, myapp
#
# default Appender
#------------------------------------------------------------------------------
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{yyyy-MM-dd HH:mm:ss.SSS} %c{1} [%p] %C{1}.%M - %m%n
#
# Appender for myappaudit
#------------------------------------------------------------------------------
log4j.appender.myappaudit = org.apache.log4j.DailyRollingFileAppender
log4j.appender.myappaudit.File = ${jboss.server.log.dir}/logs/myappaudit.log
log4j.appender.myappaudit.Append = true
log4j.appender.myappaudit.DatePattern = '.'yyy-MM-dd
log4j.appender.myappaudit.layout = org.apache.log4j.PatternLayout
log4j.appender.myappaudit.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss.SSS} %c{1} [%p] %m%n
#
# Appender for application
#------------------------------------------------------------------------------
log4j.appender.myapp = org.apache.log4j.DailyRollingFileAppender
log4j.appender.myapp.File = ${jboss.server.log.dir}/logs/console.log
log4j.appender.myapp.Append = true
log4j.appender.myapp.DatePattern = '.'yyy-MM-dd
log4j.appender.myapp.layout = org.apache.log4j.PatternLayout
log4j.appender.myapp.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss.SSS} %c{1} [%p] %m%n
#Spring logs
log4j.logger.org.springframework=DEBUG
log4j.logger.org.springframework.security=DEBUG
log4j.logger.org.springframework.ws=DEBUG
#Spring Transaction Logs
log4j.logger.org.springframework.orm.jpa=DEBUG
log4j.logger.org.springframework.transaction=DEBUG
#Spring Async Logs
log4j.logger.org.springframework.scheduling=ERROR
You will not be able to use the logger options in the console. The reason is that if you include a log4j config an entirely isolated logging instance is created for that deployment. If you want to use jboss's tools, you must remove your logging config and define in the standalone or domain xml. Alternatively, you can create your own servlet or mbean that is part of your deployment to make runtime adjustments to the logging level or any other changes, e.g adding or removing appenders
So, to be clear, are you packaging a log4j.properties file with your application? It that being respected correctly, but you hoped to use the jboss console to amend the logging level at runtime?
Related
I'm using org.apache.log4j.Logger and want to turn off debug messages for htmlunit. Nothing I do seems to work. I keep getting Http.wire, Http.headers, etc debug messages. I have the root logger set to debug
I tried placing this line in my code:
org.apache.log4j.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(org.apache.log4j.Level.OFF);
I also tried placing this line in my log4j.properties file:
log4j.logger.com.gargoylesoftware.htmlunit=WARN
This is the contents of my log4j.properties file:
log4j.logger.com.gargoylesoftware.htmlunit=ERROR
log4j.logger.org.apache.commons.httpclient=ERROR
# Tell the root lodger what appenders and level to use
log4j.rootLogger=DEBUG, A1, A2
##### Console Appender #####
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d %-5p [%t] %-17c{2} (%13F:%L) %3x - %m%n
##### File Appender #####
log4j.appender.A2=org.apache.log4j.FileAppender
log4j.appender.A2.File=/var/log/mylogfile.log
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=%d %-5p [%t] %-17c{2} (%13F:%L) %3x - %m%n
log4j.appender.A2.Append=false
Any help would be appreciated.
Edit 11/15/16 (Adding test code)
import com.gargoylesoftware.htmlunit.*;
import com.gargoylesoftware.htmlunit.html.*;
import org.junit.*;
import static org.junit.Assert.*;
import org.apache.commons.logging.*;
import org.apache.log4j.*;
public class Test01
{
#Test
public void homePage() throws Exception
{
LogFactory.getFactory().setAttribute("com.gargoylesoftware.htmlunit", "org.apache.commons.logging.impl.Log4JLogger");
LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Log4JLogger");
org.apache.log4j.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(Level.WARN);
org.apache.log4j.Logger.getLogger("org.apache.commons.httpclient").setLevel(Level.WARN);
Logger.getRootLogger().setLevel(Level.DEBUG);
Logger.getRootLogger().debug("Start");
WebClient webClient = new WebClient()
HtmlPage page = webClient.getPage("https://google.com");
Logger.getRootLogger().debug("End");
}
For log4j, you should set log4j.logger.com.gargoylesoftware.htmlunit to ERROR:
log4j.logger.com.gargoylesoftware.htmlunit=ERROR
Second option : in your code, add this after declaring your web client:
LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");
java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(Level.OFF);
java.util.logging.Logger.getLogger("org.apache.commons.httpclient").setLevel(Level.OFF);
So after much experimenting and observation of the log output I have figured this out. As it turns out the documentation for HttpClient on the Apache HTTPCLient website is not correct (as a matter of fact there are broken links). It turns out the names of the loggers used by HTTPClient are not as specified in the doc. The correct logger root name is "http" not "httpclient" which means all the trials I was performing had zero effect.
I am using org.apache.httpcomponents.httpclient_4.5.2 and org.apache.httpcomponents.httpcore_4.4.5 which as of today (11/15/16).
Here is an example log4j.properties file that will allow fine control of the HTMLClient logging
# Tell the root logger what appenders and level to use
log4j.rootLogger=DEBUG, A1, A2
# Controls detailed wire protocol
log4j.logger.org.apache.http.wire=WARN
# Controls headers (good for debugging)
log4j.logger.org.apache.http.headers=WARN
# Controls http context (what you are sending and geting)
log4j.logger.org.apache.http=WARN
# Controls htmlunit details
log4j.logger.com.gargoylesoftware.htmlunit=WARN
##### Console Appender #####
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d %-5p [%t] %-17c{2} (%13F:%L) %3x - %m%n
##### File Appender #####
log4j.appender.A2=org.apache.log4j.FileAppender
log4j.appender.A2.File=mylogfile.log
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=%d %-5p [%t] %-17c{2} (%13F:%L) %3x - %m%n
log4j.appender.A2.Append=false
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
I have a single log4j.properties file in the server and to applications deployed in the server.The requirement is to create separate loggers for the application
I defined this in my application
# Root logger option
log4j.rootLogger=INFO, file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=/opt/ibm/WebSphere/AppServer/profiles/MDMServer/logs/damcoLoging.log
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
#logging for jbpm
log4j.logger.jbpmLogger=INFO, jbpmLogger
log4j.appender.jbpmLogger=org.apache.log4j.RollingFileAppender
log4j.appender.jbpmLogger.maxFileSize=1MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.jbpmLogger.layout=org.apache.log4j.PatternLayout
log4j.appender.jbpmLogger.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
log4j.appender.jbpmLogger.File=/opt/ibm/WebSphere/AppServer/profiles/MDMServer/logs/jbpmLogging.log
log4j.additivity.jbpmLogger=false
In my java class I have done this for the secondary logger
Logger logger=Logger.getLogger("jbpmLogger");
Now the logs are getting generated properly.But for the secondary logger I want to set the class name as well.So that I can know from which class the log is generating.
Currently the log for the secondary logger looks like this
INFO jbpmLogger:8 - Hi
Is it possible to set the class name as well?
You can add the class name to the output Pattern with %C, although the docs warn that this is slow. Is this what you want?
Or since onegetLogger() method takes a String, you could concatenate the class and your "jbpmLogger" if you wanted to. And since the naming is hierarchical, still just using your single logger in the configuration file. e.g.
Logger logger = getLogger("jbpmLogger." + this.getClass().getName());
I am running a Storm cluster which uses log4j for logging. I want to add a kafka appender in addition to the standard file-based logging.
My log4j config file looks like this:
log4j.rootLogger=INFO, A1
log4j.appender.A1 = org.apache.log4j.DailyRollingFileAppender
log4j.appender.A1.File = /var/log/storm/logs/${logfile.name}
log4j.appender.A1.Append = true
log4j.appender.A1.DatePattern = '.'yyy-MM-dd
log4j.appender.A1.layout = org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %c{1} [%p] %m%n
log4j.appender.KAFKA=kafka.producer.KafkaLog4jAppender
log4j.appender.KAFKA.Host=<kafka.ip>
log4j.appender.KAFKA.Port=9092
log4j.appender.KAFKA.Topic=storm_log
log4j.appender.KAFKA.SerializerClass=kafka.producer.DefaultStringEncoder
log4j.appender.KAFKA.layout=org.apache.log4j.PatternLayout
log4j.appender.KAFKA.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %c{1} [%p] %m%n
log4j.logger.my.package.name=INFO, KAFKA
Everything works fine, except that the kafka appender doesn't use the defined ConversionPattern, even though the definition is exactly the same as in the file appender, which works as intended. How do I have to change the configuration to make the kafka appender work?
I had the same issues with Kafka version 0.7.
There were some changes done to KafkaLog4jAppender in version 0.7.1 and after upgrading, the ConversionPattern works fine for me with a config similar to the one above.
i have been trying to log to a text file with log4j from a simple jsf web application, but no success. Every time i open the file at location, nothing was written to it. I am deploying with glassfish. Below is my log4j.properties configuration
log4j.rootLogger = debug, stdout, FILE
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{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.appender.FILE = org.apache.log4j.RollingFileAppender
log4j.appender.FILE.maxFileSize = 100kb
log4j.appender.FILE.maxBackupIndex = 2
log4j.appender.FILE.File = C:\temp\mylog.txt
log4j.appender.FILE.Threshold = debug
log4j.appender.FILE.layout = org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern = %d{ABSOLUTE} %5p %c{1}:%L - %m%n
i realise that the file mylog.txt gets created in ....\domains\domain1 directory of the glassfish application server.How do i get it to direct to C:\temp\mylog.txt
Got it fixed. Actually my line seperator for file location was in the wrong direction "\" backslash and log4j expected "/" a forward slash line seperator - probably because it expects a url pattern file location address.
So i just changed C:\temp\mylog.txt to C:/temp/mylog.txt and voila! This also applies to a any other file location you want log4j to target