log4j logs not creating in ubuntu - java

I created java maven application with log4j logging.
In windows it is working. Log files are created in the path which is given the log4j.properties. log4j.properties is in maven resource folder.
But when buliding jar with maven install from eclipse, and running it from ubuntu, log files are not creating. Modified the log4j.properties with linux path.
# Root logger option, logs messages for the all classes in the application
log4j.rootLogger=DEBUG, stdout
# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# log for myproj.sample.Aaa class
log4j.logger.myproj.sample.Aaa = DEBUG,aaa
log4j.appender.aaa = org.apache.log4j.RollingFileAppender
log4j.appender.aaa.file = /home/ushusadmin/aaa.log
log4j.appender.aaa.layout = org.apache.log4j.PatternLayout
log4j.appender.aaa.append = true
log4j.appender.aaa.MaxFileSize=50MB
log4j.appender.aaa.MaxBackupIndex=7
log4j.additivity.aaa=false
Below given the code for logging in Aaa class.
public static final Logger LOG = Logger.getLogger(Aaa.class.getName());
LOG.debug("haiii");

Related

Log4j not writing logs to file on one Websphere server and writing to file on other

I have maven application with log4j.properties in it with setting to write the logs to a specified file instead of console. When I run the EAR on one of the websphere servers it is creating the file as expected and writing logs to it. But, when I am running the same EAR on other webspehere server it is writing to console instead of writing the logs to the specified file. I have checked the permissions and everything seems to be fine. Please help me in identifying what the issue is. Thanks in advance.
# CONSOLE APPENDER (stdout)
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Threshold=DEBUG
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%d] [%t] %-5p %20c - %m%n
# ROLLING FILE APPENDER (on the file system) for memberpolicyattributesservice code
log4j.appender.xxxxService=org.apache.log4j.RollingFileAppender
log4j.appender.xxxxService.Threshold=DEBUG
log4j.appender.xxxxService.File=/var/logs/xxxServer1/xxxServiceLog.log
log4j.appender.xxxxService.layout=org.apache.log4j.PatternLayout
log4j.appender.xxxxService.layout.ConversionPattern=%d{MM-dd#HH:mm:ss} %-5p (%13F:%L) %3x - %m%n
log4j.appender.xxxxService.MaxFileSize=10000KB
log4j.appender.xxxxService.MaxBackupIndex=30
log4j.appender.xxxxService.layout=org.apache.log4j.PatternLayout
log4j.appender.xxxxService.layout.ConversionPattern=[%d] [%t] %-5p %20c - %m%n
# ROLLING FILE APPENDER (on the file system) for hiberate, open source code log files
log4j.appender.open_source_code=org.apache.log4j.RollingFileAppender
log4j.appender.open_source_code.layout=org.apache.log4j.PatternLayout
log4j.appender.open_source_code.Threshold=DEBUG
#message format:YYYY-MM-DD HH:mm:ss,ms [ThreadId] <PRIORITY> classname.message
log4j.appender.open_source_code.layout.ConversionPattern=%d [%t]<%-5p> %c.%m \r\n
#file that will be logged to
log4j.appender.open_source_code.File=/var/logs/xxxServer1/open_source_code.log
log4j.appender.open_source_code.Append=true
log4j.appender.open_source_code.MaxFileSize=1024KB
log4j.appender.open_source_code.MaxBackupIndex=5
#turn on log4j verbose mode
log4j.debug = true
# Set root logger level to INFO and its appender to DSInstrumentor,stdout.
log4j.rootLogger=DEBUG,stdout,xxxxService
# YOUR CATEGORIES (to customize logging per class/pkg/project/etc)
log4j.category.fatal=FATAL,xxxxService
log4j.category.error=ERROR,xxxxService
#This will also enable the logging for all the children (packages and classes) of this package
log4j.logger.com.xxxxx=ALL,xxxxService
# Print only messages of level INFO in the open source code
log4j.logger.org=INFO,open_source_code
You have multiple loggers defined in your root logger (DEBUG, stdout, xxxxService) but the xxxxService loggers look like they're bound to the file system on one of the systems:
log4j.appender.open_source_code.File=/var/logs/xxxServer1/open_source_code.log
Make sure that path is valid for each server in your WAS cluster.
As a side note, you should probably avoid using debug and stdout on a remote server. This is fine for local development in your workstation, but not on a remote box. Instead, provide different log4j properties on your various deployment tiers. This lets you customize the log location or appender (say c:\temp or CONSOLE on your desktop, but /var/logs ... on all remote machines) as well as your log levels (DEBUG for desktop, maybe INFO for QA or Staging, and WARN or ERROR for Production).

Can not understand the warning thrown on running selenium script

Whenever I ran my webdriver script in eclipse, using java, I got following warning:
log4j:WARN No appenders could be found for logger (org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager).
log4j:WARN Please initialize the log4j system properly.
When I looked into Referenced Libraries I saw a 'log4j-1.2.14.jar'. This must have come along with default selenium download. What's its use??
Log4j configuration is missing. Log4j scans for configuration files log4j.xml or log4j.properties on the classpath and cannot find either.
For details, have a look at No appenders could be found for logger(log4j)? .
Example:
To setup a console appender, create file log4j.properties with the following contents and put it on the classpath:
log4j.rootLogger=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p %c - %m%n

Disable Struts2 logs

How can I disable Struts2 zillions of logs?
I constantly get logs like this:
2012-04-12 23:20:31,487 DEBUG [XWorkConverter.java:388] : Property: menuExpandedOps
I'm using struts 2.0 and standard java logging (I'm not using log4j).
The logging.properties file of the JVM is set by default to INFO, and I already have struts.devMode = false in my struts.properties file.
If you are free to use log4j, i suggest you to use that, since Log4j has the ability to set different log levels for different packages and hence using the log level OFF we can disable logging for a particular package.
In S2 most of the log messages will be from these packages
xwork2
struts2
freemarker
ognl
and a simple property file/xml file in class-path can help you to turn on or off the logging information.
and a simple property file/xml file in class-path can help you to turn on or off the logging information.
For those who want an example:
1) Put log4j.properties inside src (where your packages are):
2) Turn OFF low-level logging:
# root logger option
log4j.rootLogger=DEBUG, stdout, file
# direct log messages to console
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=[%p: %d{yyyy-MM-dd HH:mm:ss} %F:%L] %m%n
# direct log messages to a log file, support file rolling
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.File=${catalina.home}/logs/sortingmonitor.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=[%p: %d{yyyy-MM-dd HH:mm:ss} %F:%L] %m%n
# disable apache low level logging
log4j.category.com.opensymphony.xwork2=OFF
log4j.category.org.apache.struts2=OFF
log4j.category.freemarker.beans=OFF
log4j.category.freemarker.cache=OFF
Further reading for XML: http://deepaksrivastav.github.io/blog/2011/01/06/disable-struts-2-log-messages/

Set differnet levels of logging for loggers in log4j

I am using log4j for my application - there I need to see all log messages, so I defined
# General configuration
log4j.rootLogger = ALL, ConsoleAppender
# Appender configuration
log4j.appender.ConsoleAppender = org.apache.log4j.ConsoleAppender
log4j.appender.ConsoleAppender.layout = org.apache.log4j.PatternLayout
log4j.appender.ConsoleAppender.layout.ConversionPattern = %5p (%c) %m%n
But, after I started using Apache's HTTPClient library (which is awesome btw), my console got clouded up by its logging - everything was logged and I am not able to see the log output from my own application any more.
So how can I tell the HTTPClient library that it should only log WARN messages, while my own application still logs on ALL levels?
I create my application logger using
Logger logger = Logger.getLogger(MyClass.class);
PropertyConfigurator.configure("log4j.properties");
It's quite simple. Just add the below line.
log4j.logger.org.apache.commons.httpclient=WARN
Similarly, you can configure levels for any package com.foo or class com.foo.Bar by appending it to the prefix log4j.logger as follows:
log4j.logger.com.foo=MYLEVEL
log4j.logger.com.foo.Bar=DEBUG

Log a java class using log4j called from a Coldfusion application

I want to be able to log debugging messages from my Java classes in a file on my web server, using log4j. I am able to log messages successfully to a file on the server if the Java classes are run from a JUnit test, using the following settings:
log4j.properties:
log4j.appender.rollingFile=org.apache.log4j.RollingFileAppender
log4j.appender.rollingFile.File=D:/logs/fair.log
log4j.appender.rollingFile.MaxFileSize=2MB
log4j.appender.rollingFile.MaxBackupIndex=2
log4j.appender.rollingFile.layout = org.apache.log4j.PatternLayout
log4j.appender.rollingFile.layout.ConversionPattern=%p %t %c - %m%n
log4j.rootLogger = INFO, rollingFile
FairScheduler.java:
private static Logger logger = Logger.getLogger(FairScheduler.class);
logger.info("initializing Scheduler");
But when I deploy the application to my Coldfusion application, the log messages are no longer logged.
How can I configure my Coldfusion server to log messages to this log file (or view any of my log4j log messages at all)?

Categories