| |
Struts Tutorials:
Struts2 Tag CheckBoxList , Checkbox, Iterator, IF
Struts2 Tag Library Example
Struts2 Tiles Example
Struts2 Tiles I18N Example
Struts2 Questions
Struts Tiles I18N Example
Struts Eclipse MVC
Struts2 Tags
Struts2 Example and Tutorial
Struts MVC
Struts2 Validation
Hibernate Tutorials:
Hibernate Case Study
Class Hierarchy Persist Example
Using Hibernate Interceptor
Hibernate Questions with Answer
Hibernate Many-to-Many Mapping Example
Hibernate one-to-many Mapping Example
Hibernate and ORM tools
Spring Hibernate Example
Hibernate SessionFactory Example
Hibernate Mapping Class Hierarchy
Hibernate Questions
Hibernate SessionFactory Questions
Spring Hibernate Example:
Spring Hibernate Case Study
Written By : Amit
Title :
Different logging files Log4j
Description :
configuration time using Log4j More...
|
Written By : Amit
Title :
How to use Log4j
Description :
PatternLayout More...
|
Written By : Amit
Title :
Using NDC and Log4j
Description :
NDC Push with Log4j More...
|
Written By : Amit
Title :
Log4j Example
Description :
Log4j Tutorial More...
|
Written By : guddu
Title :
Apache Commons Logging
Description :
with Log4j Example More...
|
Written By : ISHTEK
Title :
Log4j Example Configuration
Description :
Applying Levels Logger More...
|
| Tags/Keywords : Log4j Appender, Log4j, Appender, Configuration, Logging, Files, Appenders, Example,Apache, Code, Tutorial, Article Author : Amit Date (Year/Month/Date): 2009-01-25
Different logging files at configuration time using Log4j | |
Please be informed that NONE of the design/code from this
page is claiming to be some sort of best practices and we DO NOT expect
any of our visitor/reader of this page to assume this as some sort of
best practice for any context and should not be using this
as it is without appropriate evaluation to their, so to say,
specific programming context.
This page intends only to provide bit and piece of known ways for
doing some sort of example and may not be fit for any other purpose.
Using Log4j How to write different types of log
output to different files, suppose normal debug
information stored in a seperate file and more
specific process related audit information
stored in a separate log file?
Most probable answer (Open for discussion by Reply)
There can be many ways of doing this, one of the
solution is by defining log4j.properties in such
a way so as to have two different Appenders,
with two different log files.
This is statically defined configuration, that is
defining two different Loggers as well, as follows:
Here I am using Apache Log4J
version 1.2.x.
1. Define rootLogger=DEBUG as
log4j.rootLogger=DEBUG
2. As two different types of loggers, here I define
these as DEFAULT_LOGGER and PROCESS_LOGGER,
log4j.logger.DEFAULT_LOGGER=INHERIT, A1
log4j.logger.PROCESS_LOGGER=INHERIT, A2
These two custome loggers are to be inherit from the
root logger, and two appenders A1 and A2 are attached
to each of these loggers.
3. Now these two appenders A1 and A2 are to be set
with respective properties such as type of layout,
patern and file name etc.
log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A1.File=app.log
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
log4j.appender.A1.DatePattern='.'yyyy-MM-dd-HH-mm
log4j.appender.A2=org.apache.log4j.FileAppender
log4j.appender.A2.File=audit_process.log
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
Here default logger has daily rolling file appender,
that means with every system date change, it is going
to create a separate log file with complete date with
timestamp.
And process logger has a simple file appender,
with a specific pattern.
Hope this helps, If you want to share some more
suggestions or ways of doing this, please write to us
By replying to this write up. After review and required
changes made, if any, it will be published in this page.
|
|
| | Replied By -> Girish | Is it required to have two Loggers for this purpose?
Can we have two appenders and call these appenders as per
requirement? |
| | |
Commented By -> siva krishna k | Hi
This is my log4j.xml file but it is not creating file and i m running this in tomcat server.
I couln't find what's the probelm?In tomcat log files i have seen this.
/*log4j:WARN No appenders could be found for logger (org.apache.commons.digester.Digester.sax).
log4j:WARN Please initialize the log4j system properly.*/
How to solve this problem?
I am configuring xml file using DOMConfigurator class in java. This is my java code.
I m importing this package into one jsp page and there i m sending request.
pls send me response. I need it urgent
package logapi;
import org.apache.log4j.*;
import org.apache.log4j.xml.DOMConfigurator;
public class LOGAPI
{
static Logger logger = null;
static
{
logger = Logger.getLogger(LOGAPI.class);
}
public void LOGAPI()
{
DOMConfigurator.configure("log4j.xml");
}
public void debug(Object o)
{
try
{
debug(o);
}
catch (Exception e)
{
logger.debug("Debugging:",e);
}
}
public void info(Object o)
{
try
{
info(o);
}
catch (Exception e)
{
logger.info("Info:",e);
}
}
public void warn(Object o)
{
try
{
warn(o);
}
catch (Exception e)
{
logger.warn("Warn:",e);
}
}
public void error(Object o)
{
try
{
error(o);
}
catch (Exception e)
{
logger.error("Error:");
}
}
public void fatal(Object o)
{
try
{
fatal(o);
}
catch (Exception e)
{
logger.fatal("Fatal",e);
}
}
}
LOG4J.XML
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="true"
xmlns:log4j='http://jakarta.apache.org/log4j/'>
<appender name="xmltest" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="c:/newlog.log"/>
<param name="MaxFileSize" value="10MB"/>
<param name="MaxBackupIndex" value="3"/>
<param name="Append" value="true"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} [%c] - %m%n"/>
</layout>
</appender>
<root>
<appender-ref ref="xmltest"/>
</root>
</log4j:configuration>
|
| | |
Commented By -> Amit | I guess, you might have not placed log4j.xml file inside WEB-INF/classes
folder. As I have written a simple test client Java file to test
your log4j.xml and LOGAPI file, and it is working fine provided I place
your log4j.xml file in the same folder in which I am executing this test
client (as shown below).
TestLOGAPI.java
import org.apache.log4j.*;
public class TestLOGAPI
{
Logger logger = LOGAPI.logger;
public TestLOGAPI() {
test();
}
public void test() {
logger.debug("inside test method....");
}
public static void main(String[] args)
{
new TestLOGAPI();
}
}
|
Hope this helps.
Please let us know if this example way it works. |
| | |
Commented By -> arun | i new to write log4j ?
how to write seperate files information regards
to debug,error or info
thanks in advance |
| | Are you interested in solving a very interesting Technology Stack while Playing this Game 
|
|
| Home >>> Apache Log4j >>> Different logging files Log4j >>> configuration time using Log4j |
|
|
Visitor/User referred related external URL:
(Visible upon review and approved by this site Administrator)
|
|
|
|
|
<- requires login | Log in or Register | |
Copyright © 2008-2009, Interview-Questions-Tips-Forum, All Rights Reserved. | CONTACT PRIVACY POLICY DISCLAIMER |
 |
Terms of Use and Disclaimer :
This web site provides some of the information about various technologies, example
code, tips, tutorials etc. Like any printed materials, content of these pages may
become out of date over a period of time. Therefore all visitor/users of this web
site are requested/advised to refer to the originating parties/sources for the
latest changes and happenings for detailed information. This information is not
intended to be a substitute for the original reference provided by the originating
parties/sources.
By accessing and using this website in any ways, including, without
limitation, browsing the website pages, using any information, using any content and/or
downloading any materials, you agree to and are bound by the terms of use
described in this page and Usage Terms and Conditions.
If you do not agree to all of
the terms and conditions contained in the terms of use described in this
page and Usage Terms and Conditions, do not use this
website in any manner. If you are using the website on behalf of your
employer, you represent that you are authorized to accept these Terms of Use
on your employer's behalf.
All Trademarks are property of their respective owner. Appropriate measure is being
taken for providing accurate and up-to-date information but like any printed materials,
these blog(s)/contents may eventually be outdated one day, so if you are using any
of these information, please refer original content/documentation from respective sources.
And under no circumstances shall the Author of these contents and/or this web site
be liable for any loss, damage, expense incurred or suffered which is claimed to have
occurred because of usage of the contents of this web site.
If you have any questions/queries/feedback/suggestions then please write to this web
site owner at contact.
|  |
|
|
|
|
|