Log4j help

Hi,
I am running a program and it will create 4 threads (and may be 10-15 class files) and process those threads.. I am using log4j for logging the messages.. But, i was unable to create one log file for each thread.. Can someone help me how to create 4 log files from the same process?
Thanks in advance..
Regards
Praveen Padala

Each thread could use a different named Logger. Those Loggers could be configured to use different Appenders, each configured to point to a different file.

Similar Messages

  • How to include log4j in servlet

    hai
    i want to know what are the steps neccessary for including log4j .How to do with xml.
    Please give me some useful sites about log4j. which will guide me to work in webapplication

    http://www.google.com/search?hl=en&lr=&q=log4j+help
    :)

  • Problem with log4j.properties and level DEBUG

    Hi,
    I need some log4j help.
    I create 2 different appenders in the log4j.properties file
    and it works.
    This is my complete log4j.properties:
    log4j.logger.log1=DEBUG, log1
    log4j.logger.log2=DEBUG, log2
    log4j.appender.log1=org.apache.log4j.DailyRollingFileAppender
    log4j.appender.log1.File=${StandardLogPath}
    log4j.appender.log1.DatePattern='.'yyyy-MM-dd
    log4j.appender.log1.Append=true
    #log4j.appender.log1.Threshold=DEBUG
    log4j.appender.log1.layout=org.apache.log4j.PatternLayout
    log4j.appender.log1.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss} [%-5p] %-25c{1} %m%n
    log4j.appender.log2=org.apache.log4j.DailyRollingFileAppender
    log4j.appender.log2.File=${StandardLogQueryPath}
    log4j.appender.log2.DatePattern='.'yyyy-MM-dd
    log4j.appender.log2.Append=true
    log4j.appender.log2.layout=org.apache.log4j.PatternLayout
    log4j.appender.log2.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss} [%-5p] %-25c{1} %m%nAnd here's my logging code:
    import org.apache.log4j.Logger;
    Logger log = Logger.getLogger("log1");
    Logger logQuery = Logger.getLogger("log2");
    log.debug("loggerDebug");
    logQuery.debug("loggerDebug");
    log.info("loggerInfo");
    logQuery.info("loggerInfo");The problem is that "loggerDebug" is not written to all appenders (only "loggerInfo").
    In fact if I print:
    System.out.println( log.getEffectiveLevel().toString() );result that the level is INFO and I known that if level is INFO then DEBUG is disable.
    But why the level is INFO????
    Someone can suggest me a solution?
    Thank you very much

    You're so over-sensitive you: when an OP doesn't respond anymore
    to your last reply it implies that you've solved the problem and
    (implicitly) that the OP is very grateful to you. Why do you always
    have to be so explicit about matters? ;-)
    Because I'm not one of those Dutch people ;-)Yes, that's us, the Dutch: mysteriously smiling and keeping silent all the
    time. That's why they call us the Asians of Western Europe ;-)
    ps. There are nice exception to the rule sometimes though.
    Yes, and unfortunately they do seem to be the exception rather than
    the rule. It would be nice to catch one a bit more often.True; that's the internet generation: grab all the information that you can
    and don't give a f*ck about the guy who supplied the information. It's sad
    indeed.
    Maybe we should start a support group where we could thank each
    other now and then 'on behalf' of those little spoiled brats and complain
    about all those bad manners nowadays ;-)
    kind regards,
    Jos

  • Log4j appender question

    I need some log4j help. Hope anyone can help me.
    Question 1:
    I need to log information to 4 different files. As far as I can tell from the log4j docs, I will then need to create 4 different appenders in the log4j.properties file. How can I do that?
    Looking at examples, it looks like I will need to add 4 new sections similar to this one. Is that correct?
    # Logfile 1
    log4j.appender.log1=org.apache.log4j.RollingFileAppender
    log4j.appender.log1.File=C:/Sun/logs/logme1.log
    Question 2:
    After that is done, how can I actually write to the files? When logging I was thinking just using: logger.info("log something").
    How can I specify which file that will log to? Is that even the correct way to log?
    Hope someone can help!

    After that is done, how can I actually write to the files? When logging I
    was thinking just using: logger.info("log something").
    How can I specify which file that will log to? Is that even the correct
    way to log?apperantly, it doesn't seem like you have understand how log4j works. that's probably why warnerja tell you to perform some search.
    understand the technology first..then ask specific question here.
    it will be useless just handling out answers to everyone. i think they're here just not to provides answers, but to educate other along the way...but they need to see an effort was made first.
    you're right..there are time when one doesn't have enough time to understand the whole technology..or the technology is too difficult to comprehend..or the documentation is poor., but i think there are plenty of good documentation on log4j. Futhermore..what you are asking is not usually shown in the documentation, but a google search would probably provides you with the answer you seek..you just need to find a good keyword.
    Futhermore, I suggest you read some tutorial on log4j if you plan to use the technology..it will not takes all day..maybe an hour or so..just to get how the technology works
    anyway,
    your appender tell the logger where the log the message to (depends on the level you specified) .. so if you have 3 appender that specified
    the level to be INFO, and you have logger.info("This is an INFO message"), then the message will be log to all three files.
    log4j.threshold=ALL
    log4j.rootLogger=ALL, stdout, DebugAppender, InfoAppender,
    log4j.appender.stdout=org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
    log4j.appender.stdout.layout.ConversionPattern=%c %d{ISO8601} -- %p -- %m%n
    log4j.logger.DebugAppender.access=DEBUG
    log4j.appender.DebugAppender=org.apache.log4j.RollingFileAppender
    log4j.appender.DebugAppender.File=.${file.separator}log${file.separator}ex_debug.log
    log4j.appender.DebugAppender.MaxFileSize=10KB
    log4j.appender.DebugAppender.MaxBackupIndex=1
    log4j.appender.DebugAppender.layout=org.apache.log4j.PatternLayout
    log4j.appender.DebugAppender.layout.ConversionPattern=%c %d{ISO8601} -- %p --
    %m%n
    log4j.logger.InfoAppender.access=INFO
    log4j.appender.InfoAppender=org.apache.log4j.RollingFileAppender
    log4j.appender.InfoAppender.File=.${file.separator}log${file.separator}ex_info.log
    log4j.appender.InfoAppender.MaxFileSize=10MB
    log4j.appender.InfoAppender.MaxBackupIndex=2
    log4j.appender.InfoAppender.layout=org.apache.log4j.PatternLayout
    log4j.appender.InfoAppender.layout.ConversionPattern=%c %d{ISO8601} -- %p -- %m%nthe
    log4j.rootLogger=
    tell what appender to use...so include all your appender in this property.
    you appender specified the logging level INFO, WARN, DEBUG,
    ERROR, or FATAL. I'm not sure how to specified the min and max level
    for an appender using a property file..for xml configuartion file..look at
    the example provide in previous reply.
    now if you do :
    logger.info("This is an info message") and want it to log to file1 and file2
    and log.info("This is another info message") and you want this to log to file3
    you can't do that...a way around this is to create your own level..and the
    appender will specifies that level.
    if you plan to use an XML configuration file, then make sure you include the <root> node
    <root>
       <priority value="debug"/>
       <appender-ref ref="DEBUG"/> 
       <appender-ref ref="INFO"/>
       <appender-ref ref="MY_APPENDER_NAME"/>
    </root>
    </log4j:Configuration>

  • Problems with log4j in jboss please help

    Please i need help because i can't anywhere else.
    Below is the log4j properties file
    # initialise root logger with level INFO and call it
    log4j.rootLogger=INFO, BLAH
    # add a Appender to the logger BLAH
    log4j.appender.BLAH=org.apache.log4j.RollingFileAppender
    # set the layout
    log4j.appender.BLAH.layout=org.apache.log4j.PatternLayout
    #log4j.appender.BLAH.layout.ConversionPattern=%p %c - %m%n
    log4j.appender.BLAH.layout.ConversionPattern=%d{dd-MMM-yyyy HH:mm:ss:SSS}: %m%n
    log4j.appender.BLAH.File=c:/testing.log
    log4j.appender.BLAH.MaxFileSize=10000KB
    # Keep one backup file
    log4j.appender.BLAH.MaxBackupIndex=10
    Below is the code in which i am using log4j logging
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.PrintWriter;
    import java.io.IOException;
    import org.apache.log4j.Logger;
    import org.apache.log4j.PropertyConfigurator;
    public class rectest extends HttpServlet
    private static final String CONTENT_TYPE = "text/html; charset=windows-1252";
    public void init(ServletConfig config) throws ServletException
    super.init(config);
    String prefix = "D:/jdkwork/work/App/testing";
    String file = getInitParameter("log4j-init-file");
    // if the log4j-init-file is not set, then no point in trying
    if(file != null) {
    PropertyConfigurator.configure(prefix+file);
    private static Logger log =Logger.getLogger(rectest.class);
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    doPost(request,response);
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    response.setContentType(CONTENT_TYPE);
    PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<head><title>rectest</title></head>");
    out.println("<body>");
    log.info("this is a test");
    out.println("<p>The servlet has received a POST. This is the reply.</p>");
    out.println("</body></html>");
    out.close();
    I deploy the war file in jboss4 and run it. It runs smoothly and when deploys the war file, all the info messages in the console are then logged to the log file of my application which is deployed in it. i am new to log4j and couldn't find solution for that. please help

    should i assume that there will be no help for this or there is no solution for which is offcourse not possible.

  • Help on Configuring Log4j for Websphere

    Hi All,
    I want to disable logging for my application.its writing huge output.
    i changed log4j.properties file but no effect,even if i am completely removing this prop file ,its writing.wat could be the reason?.I think its taking from some other location but couldnt find.i am new to websphere so please help me.is it posible that its not using log4j at all??
    Cheers:
    Akash.

    Hello,
    the ´ip address dhcp´ command was introduced in IOS version 12.1(2)T. You are running 12.0, so you would have to upgrade your IOS in order for the command to be supported...
    Regards,
    Nethelper

  • Log4j.xml ----timestamp error-the hour is not correct in the logs. HELP !!!

    I need your help to correct the following issue:
    -timestamp in logs is one hour ahead than the server time.
    I am using jboss-4.0.3SP1 and jdk1.5.0_10
    In order to solve this problem I have tried almost everything that I could find about this on internet:
    1) I have used the tzdupdate()
    tzupdater version 1.3.40-b01
    JRE time zone data version: tzdata2011h
    Embedded time zone data version: tzdata2011h
    2) copied the log4j.properties to WEB-INF/classes
    /opt/jboss-4.0.3SP1/server/mcdp-std/deploy/axis2.war/WEB-INF/classes/log4j.properties
    3) also I've checked to have the same log4j.jar
    The log4j.xml looks like this:
    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
    &lt;!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"&gt;
    &lt;!-- ================================================== --&gt;
    &lt;!-- --&gt;
    &lt;!-- Log4j Configuration --&gt;
    &lt;!-- --&gt;
    &lt;!-- ================================================== --&gt;
    &lt;log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false"&gt;
    &lt;!-- Default server.log file containing the error messages for all clients --&gt;
    &lt;appender name="SERVER_LOG" class="org.jboss.logging.appender.RollingFileAppen der"&gt;
    &lt;errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler "/&gt;
    &lt;!-- Change this value before load test --&gt;
    &lt;param name="Threshold" value="DEBUG"/&gt;
    &lt;param name="File" value="${jboss.server.home.dir}/log/server.log"/&gt;
    &lt;param name="Append" value="true"/&gt;
    &lt;param name="MaxFileSize" value="10MB"/&gt;
    &lt;param name="maxBackupIndex" value="5"/&gt;
    &lt;param name="bufferedIO" value="false"/&gt;
    &lt;layout class="org.apache.log4j.PatternLayout"&gt;
    &lt;param name="ConversionPattern" value="%d{MM/dd HH:mm:ss,SSS} %-5p [%c] %t: %m%n"/&gt;
    &lt;/layout&gt;
    &lt;!-- Exclude partition crap logged in cluster.log --&gt;
    &lt;filter class="org.apache.log4j.varia.StringMatchFilter"&gt;
    &lt;param name="StringToMatch" value="org.jboss.ha"/&gt;
    &lt;param name="AcceptOnMatch" value="false"/&gt;
    &lt;/filter&gt;
    &lt;filter class="org.apache.log4j.varia.StringMatchFilter"&gt;
    &lt;param name="StringToMatch" value="org.jgroups"/&gt;
    &lt;param name="AcceptOnMatch" value="false"/&gt;
    &lt;/filter&gt;
    &lt;/appender&gt;
    &lt;!-- Clustering logging --&gt;
    &lt;appender name="CLUSTER" class="org.jboss.logging.appender.RollingFileAppen der"&gt;
    &lt;errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler "/&gt;
    &lt;!-- Change this value before load test --&gt;
    &lt;param name="Threshold" value="INFO"/&gt;
    &lt;param name="File" value="${jboss.server.home.dir}/log/cluster.log"/&gt;
    &lt;param name="Append" value="true"/&gt;
    &lt;param name="MaxFileSize" value="500KB"/&gt;
    &lt;param name="MaxBackupIndex" value="1"/&gt;
    &lt;layout class="org.apache.log4j.PatternLayout"&gt;
    &lt;param name="ConversionPattern" value="%d{MM/dd HH:mm:ss,SSS} (%t) %-5p [%c] %m%n"/&gt;
    &lt;/layout&gt;
    &lt;/appender&gt;
    and log4.properties is like this:
    # Set root category priority to INFO and its only appender to CONSOLE.
    log4j.rootCategory=INFO, CONSOLE
    #log4j.rootCategory=INFO, CONSOLE, LOGFILE
    # Set the enterprise logger priority to FATAL
    log4j.logger.org.apache.axis2.enterprise=FATAL
    log4j.logger.de.hunsicker.jalopy.io=FATAL
    log4j.logger.httpclient.wire.header=FATAL
    log4j.logger.org.apache.commons.httpclient=FATAL
    # CONSOLE is set to be a ConsoleAppender using a PatternLayout.
    log4j.appender.CONSOLE=org.apache.log4j.ConsoleApp ender
    log4j.appender.CONSOLE.layout=org.apache.log4j.Pat ternLayout
    log4j.appender.CONSOLE.layout.ConversionPattern=%p [%d{ISO8601}] %c{2} %x - %m%n
    # LOGFILE is set to be a File appender using a PatternLayout.
    log4j.appender.LOGFILE=org.apache.log4j.FileAppend er
    log4j.appender.LOGFILE.File=axis2.log
    log4j.appender.LOGFILE.Append=true
    log4j.appender.LOGFILE.layout=org.apache.log4j.Pat ternLayout
    log4j.appender.LOGFILE.layout.ConversionPattern=%p [%d{ISO8601}] %c{2} %x - %m%n

    Did you check http://www.oracle.com/technetwork/java/javase/dst-faq-138158.html in particular 27 about Cached instances of timezone data? I suggest to post this issue in the Application Server forum Oracle Application Server - General

  • [help~~~~]log4j dailyrollingfileappender problem

    I'm feeling very confused when I use log4j.I want to get log output everyday to files whose names are with time postfix.the java property file is in the below:
    log4j.logger.DEL=WARN,Dellog4j.appender.Del=org.apache.log4j.DailyRollingFileAppender
    log4j.appender.Del.File=LOG/20
    log4j.appender.Del.DatePattern=yyMMdd-'deleteLog.txt'log4j.appender.Del.layout=org.apache.log4j.PatternLayout
    log4j.appender.Del.layout.ConversionPattern=%-d [%c]-[%p] %m %-d{yyyy-MM-dd HH:mm:ss}%n
    But I can't get what I want,instead I got error like this:
    log4j:ERROR Failed to rename [LOG/20] to [LOG/20.2006-03-28]
    when I run the project under Linux system,I can get the right result.But I really want to use it under Windows system.Could somebody do me a favor to help me??

    I don't use the slash second time,I just don't want to rewrite the same thing once more.I think the slash is ok,when I run it a folder would be create,therefore I followed you to delete that slash,but I still have that problem.If you don't want to help me,you can keep silent,why do you say those words??I saw one person asked about log4j,but it's of year2005,so I think maybe I can get help here,but you made me so upset.I think to a programmer,to be patient is very important,I am patient,but I can't keep patient for 3 days to solve only one problem with so many things left to do!

  • Log4j Error - Help needed

    Hi All,
    I am getting this following stack trace when i execute a test on an application on the remote server from the client. THe stack trace is as follows. It says error in the java.lang.NoClassDefFoundError: org/apache/log4j/Layout.... Thanks in advance...
    <24-May-2006 11:50:45 o'clock BST> <Info> <WebLogicServer> <BEA-000213> <Adding address: 10.38.86.71 to licensed client list>
    274.593: [GC 274.594: [DefNew: 15999K->448K(16448K), 0.1619128 secs] 95096K->79829K(148280K), 0.1620925 secs]
    [Pool] : Returning bean from the pool: 'null'
    [StatelessSessionPool] : allocate new: 'com.ba.cap.customer.enrolmentmanager.utilization.ULEnrolmentManagerBean_nnzhyo_Impl@48563c'
    Inside the ULEnrolmentManagerBean ********************* enrolBARegisteredCustomer
    com.ba.cap.framework.corebusiness.utilities.Profiling: capprofiling library loaded
    Inside the ULEnrolmentManagerBean --------------- 1
    <24-May-2006 11:50:50 o'clock BST> <Info> <EJB> <BEA-010051> <EJB Exception occurred during invocation from home: com.ba.cap.customer.enrolmentmanager.utilization.ULEnrolmentManagerBean_nnzhyo_HomeImpl@bb120d threw exception: java.lang.NoClassDefFoundError: org/apache/log4j/Layout
    java.lang.NoClassDefFoundError: org/apache/log4j/Layout
    at com.ba.cap.customer.enrolmentmanager.utilization.ULEnrolmentManagerBean.log(ULEnrolmentManagerBean.java:910)
    at com.ba.cap.customer.enrolmentmanager.utilization.ULEnrolmentManagerBean.enrolBARegisteredCustomer(ULEnrolmentManagerBean.java:187)
    at com.ba.cap.customer.enrolmentmanager.utilization.ULEnrolmentManagerBean_nnzhyo_EOImpl.enrolBARegisteredCustomer(ULEnrolmentManagerBean_nnzhyo_EOImpl.java:424)
    at com.ba.cap.customer.enrolmentmanager.utilization.ULEnrolmentManagerBean_nnzhyo_EOImpl_WLSkel.invoke(Unknown Source)
    at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:492)
    at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:108)
    at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:435)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:147)
    at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:430)
    at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:35)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183)
    >
    [StatelessSessionPool] : Destroying a bean in: 'weblogic.ejb20.pool.StatelessSessionPool@1924ee5 - ejb name: 'com.ba.cap.customer.enrolmentmanager.utilization.ULEnrolmentManagerHome''

    Hi Murali,
    Sorry for the delay!
    Based on the error message, I found this Microsoft KB article which is talking about the similar problem. It has also given some resolution in it. I think you could try it first.
    http://support.microsoft.com/kb/269495
    By the way, this forum is for Excel development questions. If you run into some problems when you manually manipulate the Excel workbook without code,
    Office IT Pro forum is a better place for you.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Weblogic 10 - Help me configure Log4j ????

    I have deploy an Application and using Weblogic 10.3. I want using Log4j to control debug but i don't know configure it. Who was using it please help me.

    Re: How to use log4j into weblogic 10.3

  • HELP REQUIRED VERY URGENT!!  LOG4J

    if my understanding is not wrong while using LOG4J JDBCappender to write to a DataBase using configurator file(Property file), the SQL will be written in the property file and the message to be logged into the DB will be passed from the program(java file ) to the log4J system using the log.debug or any other way.
    for eg: INSERT INTO JDBCTEST (Date, Logger, Priority, Message) VALUES ('%d', '%c', '%p', '%m')
    here the only message passed t th eLOG4J system is the Message field value which is
    represnted by the %m field(inside the value block) and rest are kind of constants , like for date (where we can use sysdate) and the logger and priority level which all are constants and not part of the message passed to the system(LOG4J system).
    the trouble we found was in separating the single message we send to the LOG4J system
    for eg: suppose if the message we send to the LOG4J system is
    " methodname=ABC() timetaken=1.5secs date=28/7/2006 "
    i am confused about the way to split the message into say 3 parts
    like
    methodname=ABC()
    methodname=ABC()
    date=28/7/2006
    and insert into different columns of the table
    Hope you got a goog broader view of the problem i am facing.

    Have you tried PreparedStatement?
    Here's an example (from the O'REILLY Java Servlet Programming book)
    PreparedStatement pstmt = con.prepareStatement("INSERT INTO ORDERS (ORDER_ID, CUSTOMER_ID, TOTAL) VALUES(?,?,?)");
    //Other code
    pstmt.clearParameters(); //clear any previous parameter values
    pstmt.setInt(1, 2); //set ORDER_ID
    pstmt.setInt(2, 4); //set CUSTOMER_ID
    pstmt.setDouble(3, 53.43); //set TOTAL
    pstmt.executeUpDate(); //execute the stored SQL
    If you want to set a String value, use the setString method.
    Does that help?

  • Log4j problem, pls help.

    Sorry this must be trivia to some of you. I am a newbie in this area.
    I want my log file to be appeared in some specific directory, say, c:\temp\
    This is my code :
    static Category cat = Category.getInstance(MyClass.class.getName());
    cat.info("blah....");No problem in compilation. But I couldn't find my log file when run. Where is my log directory by default? And how to set to some specific directory?
    I tried to refer to its example code and documentation but couldn't find any clue.
    Please help.

    You need to configure log4j. Make a log4j.properties file that you put in a directory that's in your classpath. The contents of the file should look something like this:
    log4j.rootCategory=DEBUG,file
    log4j.appender.file=org.apache.log4j.FileAppender
    log4j.appender.file.File=C:/temp/zerg2000.log
    log4j.appender.file.layout=org.apache.log4j.PatternLayout
    log4j.appender.file.layout.ConversionPattern=%d %-5p [%t] %c.%M (%F:%L) - %m%n
    Read the documentation of log4j a bit better, it is really in there, including examples.
    Jesper

  • Need help with log4j logging tool (org.apache.log4j.*) to log into database

    Hi,
    I need help with log4j logging tool (org.apache.log4j.*) to log into database using JDBCAppender. Have look at my logger code and corresponding log4j.properties file stated below. I'm running this program using Eclipse IDE and it's giving me the following error (highlighted in red) at the end:
    log4j: Parsing for [root] with value=[debug, stdout, Roll, CRSDBAPPENDER].
    log4j: Level token is [debug].
    log4j: Category root set to DEBUG
    log4j: Parsing appender named "stdout".
    log4j: Parsing layout options for "stdout".
    log4j: Setting property [conversionPattern] to [%x %d{HH:mm:ss,SSS} %5p [%t] (%c:%-4L %M) - %m%n].
    log4j: End of parsing for "stdout".
    log4j: Parsed "stdout" options.
    log4j: Parsing appender named "Roll".
    log4j: Parsing layout options for "Roll".
    log4j: Setting property [conversionPattern] to [%x %d{yyyy.MM.dd HH:mm:ss,SSS} %5p [%t] (%c:%-4L %M) - %m%n].
    log4j: End of parsing for "Roll".
    log4j: Setting property [file] to [HelloWorld.log].
    log4j: Setting property [maxBackupIndex] to [10].
    log4j: Setting property [maxFileSize] to [20KB].
    log4j: setFile called: HelloWorld.log, true
    log4j: setFile ended
    log4j: Parsed "Roll" options.
    log4j: Parsing appender named "CRSDBAPPENDER".
    {color:#ff0000}
    Can't find class HelloWorld{color}
    import org.apache.log4j.*;
    public class HelloWorld {
    static Logger log = Logger.getLogger(HelloWorld.class.getName());
    public static void main(String[] args) {
    try{
    // Now, try a few logging methods
    MDC.put("myComputerName", "Ravinder");
    MDC.put("crsServerName", "ARNDEV01");
    log.debug("Start of main()");
    log.info("Just testing a log message with priority set to INFO");
    log.warn("Just testing a log message with priority set to WARN");
    log.error("Just testing a log message with priority set to ERROR");
    log.fatal("Just testing a log message with priority set to FATAL");
    catch(Exception e){
    e.printStackTrace();
    ------------------------- log4j.properties file ------------------------------
    #### Use three appenders - log to console, file and database
    log4j.rootCategory=debug, stdout, Roll, CRSDBAPPENDER
    log4j.debug=true
    # Print only messages of priority WARN or higher for your category
    # log4j.category.your.category.name=WARN
    # Specifically inherit the priority level
    # log4j.category.your.category.name=INHERITED
    #### stdout - First appender writes to console
    log4j.appender.stdout=org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
    log4j.appender.stdout.layout.ConversionPattern=%x %d{HH:mm:ss,SSS} %5p [%t] (%c:%-4L %M) - %m%n
    #### Roll - Second appender writes to a file
    log4j.appender.Roll=org.apache.log4j.RollingFileAppender
    ##log4j.appender.Roll.File=${InstanceName}.log
    log4j.appender.Roll.File=HelloWorld.log
    log4j.appender.Roll.MaxFileSize=20KB
    log4j.appender.Roll.MaxBackupIndex=10
    log4j.appender.Roll.layout=org.apache.log4j.PatternLayout
    log4j.appender.Roll.layout.ConversionPattern=%x %d{yyyy.MM.dd HH:mm:ss,SSS} %5p [%t] (%c:%-4L %M) - %m%n
    #### CRSDBAPPENDER - third appender writes to the database
    log4j.appender.CRSDBAPPENDER=org.apache.log4j.jdbc.JDBCAppender
    log4j.appender.CRSDBAPPENDER.Driver=net.sourceforge.jtds.jdbc.Driver
    log4j.appender.CRSDBAPPENDER.URL=jdbc:jtds:sqlserver:/arncorp15:1433;DatabaseName=LOG
    log4j.appender.CRSDBAPPENDER.USER=sa
    log4j.appender.CRSDBAPPENDER.PASSWORD=p8ss3doff
    log4j.appender.CRSDBAPPENDER.layout=org.apache.log4j.PatternLayout
    log4j.appender.CRSDBAPPENDER.sql=INSERT INTO LOG (computername, crsservername, logtime, loglevel, threadname, filename, linenumber, logtext) VALUES ('%X{myComputerName}', '%X{crsServerName}', '%d{dd MMM yyyy HH:mm:ss,SSS}', '%p', '%t', '%F', '%L', '%m')
    #log4j.appender.CRSDBAPPENDER.sql=INSERT INTO LOG(COMPUTERNAME,CRSSERVERNAME,LOGTIME,LOGLEVEL,THREADNAME,FILENAME,LINENUMBER,LOGTEXT) select host_name(),'${CRSServerName}${InstanceName}','%d','%5p','%t','%F','%L','%m%n'
    #log4j.appender.CRSDBAPPENDER.sql=INSERT INTO LOG (computername, crsservername, logtime, loglevel, threadname, filename, linenumber, logtext) VALUES ("%X{myComputerName}", "%X{crsServerName}", "%d{dd MMM yyyy HH:mm:ss,SSS}", "%p", "%t", "%F", "%L", "%m")
    ------------------------------- end of log4j.properties file ------------------------------
    Here is the directory structure of my program. My log4j.properties file and HelloWorld.class file are residing in folder HelloWorld\bin.
    HelloWorld\bin
    HelloWorld\lib
    HelloWorld\src
    Please note - The same program works fine for console and file appender when I comment the database appender part in my properties file.
    Thanks
    Ravinder

    try this :
    log4j.appender.PROJECT.Append=false

  • Can anyone help how to print stack trace messages using log4j?

    Can anyone help how to print stack trace messages using log4j?

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
    <log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
    <appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
    <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern" value="%d %-5p %m%n"/>
    </layout>
    </appender>
    <appender name="DEBUG" class="org.apache.log4j.RollingFileAppender">
    <param name="File" value="/usr/local/dice/d2jbin/cmdToNetJobs/app-debug.log"/>
    <param name="Append" value="true"/>
    <param name="MaxFileSize" value="1000KB"/>
    <param name="MaxBackupIndex" value="5"/>
    <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern" value="%d %-5p %m%n"/>
    </layout>
    <filter class="org.apache.log4j.varia.LevelRangeFilter">
    <param name="LevelMin" value="DEBUG" />
    <param name="LevelMax" value="DEBUG" />
    </filter>
    </appender>
    <appender name="INFO" class="org.apache.log4j.RollingFileAppender">
    <param name="File" value="/usr/local/dice/d2jbin/cmdToNetJobs/app-info.log"/>
    <param name="Append" value="true"/>
    <param name="MaxFileSize" value="1000KB"/>
    <param name="MaxBackupIndex" value="5"/>
    <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern" value="%d %-5p %m%n"/>
    </layout>
    <filter class="org.apache.log4j.varia.LevelRangeFilter">
    <param name="LevelMin" value="INFO" />
    <param name="LevelMax" value="INFO" />
    </filter>
    </appender>
    <appender name="WARN" class="org.apache.log4j.RollingFileAppender">
    <param name="File" value="/usr/local/dice/d2jbin/cmdToNetJobs/app-warn.log"/>
    <param name="Append" value="true"/>
    <param name="MaxFileSize" value="1000KB"/>
    <param name="MaxBackupIndex" value="5"/>
    <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern" value="%d %-5p %m%n"/>
    </layout>
    <filter class="org.apache.log4j.varia.LevelRangeFilter">
    <param name="LevelMin" value="WARN" />
    <param name="LevelMax" value="WARN" />
    </filter>
    </appender>
    <appender name="ERROR" class="org.apache.log4j.RollingFileAppender">
    <param name="File" value="/usr/local/dice/d2jbin/cmdToNetJobs/app-error.log"/>
    <param name="Append" value="true"/>
    <param name="MaxFileSize" value="1000KB"/>
    <param name="MaxBackupIndex" value="5"/>
    <layout class="org.apache.log4j.PatternLayout">
    <param name="ConversionPattern" value="%d %-5p %m%n"/>
    </layout>
    <filter class="org.apache.log4j.varia.LevelRangeFilter">
    <param name="LevelMin" value="ERROR" />
    <param name="LevelMax" value="ERROR" />
    </filter>
    </appender>
    <root>
    <priority value="debug"/>
    <!--<appender-ref ref="STDOUT"/>
    --><appender-ref ref="DEBUG"/>
    <appender-ref ref="INFO"/>
    <appender-ref ref="WARN"/>
    <appender-ref ref="ERROR"/>
    </root>
    </log4j:configuration>
    I ve written like this
    and to print stack trace I used
    log.error(Throwable(e))
    but does nt display printstacktrace how to do it

  • Need Some Help in Using Log4j for logging

    Hi
    I am using Log4j for logging in my application . i have problem some areas .
    I want to rotate my file on basis of Time. means if my log file name format is HH:MM then after every minute new log file should be created , i am using Size based rotation its working fine.
    Plz Tell me which propety i used to set my logfile name like DATeFormat
    i tried with this Property but failed
    log4j.appender.R.File=%d{HH:MM}
    Simlarly i dont want to bound BackupSize
    log4j.appender.R.MaxBackupIndex=1000
    i want that suppose after 2 Mb automatically start new file and there is no upper bound on that
    how can i do that or from where i can see all properties of Log4j Thanks

    Thanks
    But in this case i cannot do Size based rotation
    These properties not belong to DialyRolling.. class
    log4j.appender.R.MaxFileSize=1KB
    log4j.appender.R.MaxBackupIndex=1000
    what i want is if file size grow with in one minute i create new file using RollingFileApender and if size doesnt grow in one minute and minute cross then next minute file should be created , how can i acheive both of these

Maybe you are looking for

  • How to markup a layout so each area is exported as a different page on the pdf using the crop and bleeds

    Hi, I work in the sign industry and I am looking at a way to streamline our preprint setup for artworks the issue is that we will get an artwork that is 6m x 2m. This is to big to do in one print so we will chop it into 2-3 pieces and then print thos

  • Data base tables for delivery & post goods issue

    Hi,   can u plz tell me which database tables are going to update after the delivery is completed? which database tables are going to update after post goods issue. Thanks for ur help. Regards pabitra

  • Acrobat 7 va in crash aprendo un documento pdf in Explorer 7

    Posto la mia richiesta qui in quando Adobe non supporta l'asssistenza alla mia versione via telefono. Mi succede quanto ho indicato nel titolo del Thread, ma non riesco a capire il motivo. Il mio sistema è XP, Acrobat gira regolarmente ma l'unico pro

  • Font Book - OS X Lion Default Fonts

    I'm trying to find out what fonts were added to OS X in Lion (compared to Snow Leoaprd). I've compiled my own list. I think that Apple added 79 fonts in OS X Lion. Here's what they are. Please correct me if I'm wrong: • Al Bayan • Arial Hebrew • Ayut

  • Excel generation

    Hi all, I created an excel sheet  using openxml and i wanted to retrieve list items and corresponding permission levels into excel.Iam using client object model.But iam able to get single item not all items in a list and iam not able to bind permissi