log4j

Logback tutorial

Where can I find a Logback tutorial and/or sample projects? Something similar with this "Log4j Tutorial" would be nice. Note: I am aware of the documentation available on the official Logback website The Logback Manual Logback documentation but is there anything else available? ...

Log4J: Strategies for creating Logger instances

I decided to use Log4J logging framework for a new Java project. I am wondering what strategy should I use for creating/managing Logger instances and why? one instance of Logger per class e.g. class Foo { private static final Logger log = Logger.getLogger( Foo.class ); } one instance of Logger per thread one instance of Logger pe...

Log4J – Runtime variable substitution

Log4J appears to have an annoying restriction – at runtime, variable substitution does not appear to work. In this example File: Log4j.properties file_pattern=%d{ISO8601} %-5p %m%n log4j.rootLogger=DEBUG, FileAppender log4j.appender.FileAppender=org.apache.log4j.FileAppender log4j.appender.FileAppender.layout=org.apache...

Specify time zone of log4j's date

Is it possible to specify the time zone that log4j will use? I need the dates in the log file to be a different time zone than the application's. log4j's PatternLayout uses SimpleDateFormat. Unfortunately there doesn't appear to be a way to control SimpleDateFormat's time zone via the pattern string (DateFormat has setTimeZone method but...

two log4j files for EAR with two modules

Hi, I have an EAR that is made up of two modules. Both expose services and share common code. Imagine that the ear has a common.jar shared by a webservices.war and webapp.war. I use log4j to log the activities. I would like to be able to have two log files (webservices.log and webapp.log) capturing the events that are specific to each o...

argh - can't get spring to log sql

I'm researching spring for a possible switch to a spring stack. One of the things that I thought was cool was the ability for spring jdbc to log all the executed sql. So I put in log4j, set up a log4j.properties file. and no sql. here is the log4j.properties file: log4j.appender.stdout=org.apache.log4j.ConsoleAppe nder log4j.appende...

Using log4j with Web container (part of the J2EE server).

When our application throws errors that we catch, we put the message and stacktrace in a log file created specifically for our application (myapp.log). For example: public class SomeClass { OurLogger log = OurLogger.getLogger ("myapp", SomeClass.class); public void someMethod { try { //code } catch (DataAcce...

is it good to catch error in DAO?

public boolean checkInd() { int dis_ind = 2; HashMap parmMap = new HashMap(); //line below can generate errors getSqlMapClientTemplate().queryForList("authentication.checkInd", parmMap); List results = (List) parmMap.get("Result0"); HashMap resultMap; if (result.size()>0) resultMap = (HashMap)resultMap...

Organizing logs with log4j

Hey all, I'm currently working on a Linux daemon written in Java. What is the common naming scheme for logs? Right now I'm thinking of doing something like: DEBUG = /var/log/myapp.debug INFO = /var/log/myapp.info WARN = /var/log/myapp.warn ERROR = /var/log/myapp.err FATAL = /var/log/myapp.err Does anyone have any opinions / suggestio...

Log4J not adding newlines between logfile entries

I am just starting with log4j. I don't have a problem with it reading my properties file and actually logging events, but it seems to be appending everything to the end of the same line. My properties file looks like this: # A1 is set to be a ConsoleAppender. log4j.appender.A1=org.apache.log4j.ConsoleAppender # A2 is set to be a Consol...

log4j, fileappender and tomcat6 logs question

Hi, I have seen many questions about the above topics but none that address this. I am trying to use log4j to log to a custom file in $CATALINA_BASE/logs/ directory. I configured the log4j.xml file and copied it into the $CATALINA_BASE/lib/ directory. I use the following lines to create the logger - PatternLayout layout = new Pattern...

What should I do with custom Log4j appender dependancies.

I've written a custom log4j appender that creates a new Solr document for each log entry and I'm having problems deploying it to JBoss. The source is viewable on github but the real problem is trying to use the appender from JBoss. The relevent bits of jboss-log4j.xml look like this: <appender name="SOLR" class="com.stuartgrimshaw.sol...

How to control logging level in client library?

We'd like clients to be able to control logging levels in our client JAR. What is the best way to do this? Currently we just have a handful of log statements that write to System.out. I realize that using Log4J would solve this problem although one of our biggest clients doesn't use Log4J and uses their own custom logging implementati...

Is it possible to read the log file using Chainsaw?

I am having several log files [ generated via log4j ]. I got to know that we can use Chainsaw to read those logs [ though we can reads those logs in notepad as well ]. But i am unable to figure out how to open a stored log file to see its content. So the simple question is, Is it possible to read the log file using Chainsaw? ...

Grails 1.1.1 log4j DSL throws MissingMethodException for PatternLayout configuration

I've upgraded a Grails 1.0.3 app to Grails 1.1.1. I've upgraded the log4j configuration in Config.groovy to conform to the new DSL. However, after defining a ConsoleAppender with a PatternLayout, the application won't start, and instead throws a MissingMethodException with the message: groovy.lang.MissingMethodException: No signature of...

How to configure log4j to log different log levels to different files for the same logger

I have a normal INFO level log for application. What I need is to additionally log all ERROR level events to separate error log. I am using configuration like this: <logger name="com.acme"> <level value="error"/> <appender-ref ref="error"/> </logger> <logger name="com.acme"> <level value="info"/> </logger> <root> <level value=...

How can I disable log4j RollingFileAppender buffering for a demo?

I have a Java programming lab-exercise in a course with students that I'd like to artificially write to disk in an inefficient manner. What I thought would be a mildly hard-to-find (as an exercise) would be having the app's log4j statements writing to disk in an unbuffered fashion. The app intentionally has prolific log statements. Wh...

Plugin version on log4j log file

I'm developing an RCP application and use log4j to generate logs. Whenever an exception is logged, I want to include a line on the log file to identify the application version. I could do that by force on the log4j.appender.file.layout.ConversionPattern line on the log4j.properties file, simply writing it down, but then I'd have to rem...

Unable to checkout log4j repository

I'm using tortoiseSVN to checkout the log4j v1.2 source from - http://svn.apache.org/repos/asf/logging/log4j/trunk But i keep getting this error: Error: OPTIONS of '': Could not Error: resolve hostname `svn.apache.org': No such host is known. The funny thing is that i can access 'svn.apache.org' from my browser but if i try to ping ...

Script to convert log4j.properties to log4j.xml

I need to use custom filters, so I need to convert some long log4j.properties files to log4j.xml. Is anyone aware of a tool to do this, or willing to contribute one they have used? Searching has thus far turned up no such tool. ...