Configure log4j to write to different log files conditionally

Hi folks,
Is there is way log4j could be configured to write to multiple log files conditionally? Let me try to explain what i am trying to do.
I have two classes DatabaseChecker and FTPChecker extends Checker class. Within Checker class, there is a method logTestResult(CheckerType c, boolean isFailed, int retry, int isMaxRetryExceeded). Depending on the CheckerType(database or FTP), I need to write log outputs to different files (dbchecker.log or ftpchecker.log). How do i configure log4j to do this?
I've seen how to configure log4j based on classes from different package, but not sure on this one. Any clue would be much appreciated.

lgmqy2000 wrote:
I have two classes DatabaseChecker and FTPChecker extends Checker class. Within Checker class, there is a method logTestResult(CheckerType c, boolean isFailed, int retry, int isMaxRetryExceeded). Depending on the CheckerType(database or FTP), I need to write log outputs to different files (dbchecker.log or ftpchecker.log). How do i configure log4j to do this?
if (checker.isType(CheckerType.DATABASE)) {
    dbLogger.info(someMessage);
} else if (checker.isType(CheckerType.FTP)) {
    ftpLogger.info(someMessage);
} else {
    defaultLogger.info(someMessage);
}~

Similar Messages

  • How to create different log files for different users in log4j

    I want to create different logs for different users, using different appenders for each user so that logs are created in his file only.
    Confusion:How to direct them to different files in my logger class

    Hi Avi,
    First of all I have given a first reading to log4j and I think there will some more easy way of logging debugging messages than log4j (If you could provide me a detailed explanation of a servlet,jsp,java bean that uses log4j and how to use log4j then it will be very helpful for me). The other easy ways (if I am not using log4j) to my problem i.e creating different log files for each of web applications deployed in oc4j are
    I have created multiple instances of OC4J that are configured to run on different ports and so on each instance I have deployed a single web application . And I started the 2 oc4j instances by transferring thier error/log messages to a file. And the other way is ..
    I have download from jakarta site a package called servhelper . This servhelper is a thread that is started in a startup servlet and stopped in the destroy method of that startup servlet. So this thread will automatically capture all the system.out.println's and will print those to a file. I believe that this thread program is synchronized. So in this method I need not run multiple instances of OC4J instead each deployed web application on single instance of oc4j uses the same thread program (ofcourse a copy of thread program is put in each of the deployed web applications directories) to log messages on to different log files.
    Can you comment on my above 2 approached to logging debugging messages and a compartive explanation to LOG4J and how to use LOG4J using a simple servlet, simple jsp is appreciated ...
    Thanks and Regards,
    Ravi.

  • How to create different log files for each of web applications deployed in OC4J

    Hi All,
    I am using OC4J(from Oracle) v1.0.2.2 and Windows2000. Now I want to know
    1. how to create different log files for each of my deployed web applications ?
    2. what are the advantages in running multiple instances of oc4j and in what case we should run
    multiple instances of OC4J ?
    3. how to run OC4J as Windows2000 Service rather than Windows2000 Application ?
    Thanks and Regards,
    Kumar.

    Hi Avi,
    First of all I have given a first reading to log4j and I think there will some more easy way of logging debugging messages than log4j (If you could provide me a detailed explanation of a servlet,jsp,java bean that uses log4j and how to use log4j then it will be very helpful for me). The other easy ways (if I am not using log4j) to my problem i.e creating different log files for each of web applications deployed in oc4j are
    I have created multiple instances of OC4J that are configured to run on different ports and so on each instance I have deployed a single web application . And I started the 2 oc4j instances by transferring thier error/log messages to a file. And the other way is ..
    I have download from jakarta site a package called servhelper . This servhelper is a thread that is started in a startup servlet and stopped in the destroy method of that startup servlet. So this thread will automatically capture all the system.out.println's and will print those to a file. I believe that this thread program is synchronized. So in this method I need not run multiple instances of OC4J instead each deployed web application on single instance of oc4j uses the same thread program (ofcourse a copy of thread program is put in each of the deployed web applications directories) to log messages on to different log files.
    Can you comment on my above 2 approached to logging debugging messages and a compartive explanation to LOG4J and how to use LOG4J using a simple servlet, simple jsp is appreciated ...
    Thanks and Regards,
    Ravi.

  • Java.util.logging - different log files for different loggers

    I'm having trouble configuring Java logging to use different log files for different loggers.
    In log4j, I would do this by configuring multiple loggers each with a different appender. But how can I do this with Java (java.util.logging) logging?
    This is the basic idea of what I'd like to do:
    com.mycompany.app1.level = FINEST
    com.mycompany.app1.<log file> = logfile1.log
    com.mycompany.app2.level = ALL
    com.mycompany.app2.<log file> = logfile2.log
    Any suggestions?

    This kind of thing?
    import java.io.IOException;
    import java.util.logging.FileHandler;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import java.util.logging.SimpleFormatter;
    public class LogTest {
        private Logger app1;
        private Logger app2;
        public LogTest() {
            // setup loggers
            try {
                // first logger
                app1 = Logger.getLogger("com.mycompany.app1");
                FileHandler filehandler = new FileHandler( "logfile1.log" );
                filehandler.setFormatter(new SimpleFormatter());
                app1.addHandler(filehandler);  
                // second logger       
                app2 = Logger.getLogger("com.mycompany.app2");
                filehandler = new FileHandler( "logfile2.log" );
                filehandler.setFormatter(new SimpleFormatter());
                app2.addHandler(filehandler);  
            } catch(IOException ioex) {
                ioex.printStackTrace();
        private void logStuff() {
            app1.log(Level.SEVERE, "a message for log 1");
            app2.log(Level.SEVERE, "a message for log 2");
            app2.log(Level.WARNING, "another message for log 2");
         * @param args
        public static void main(String[] args) {
            new LogTest().logStuff();
    }

  • Any ways to roll over to a different log file when the current log file big

    How to roll over a log file when it reaches maximum to a different log file?
    any ways of doing this??????

    More info in the new owners....
    http://www.oracle.com/technology/pub/articles/hunter_logging.html
    And more!!!!! here to build a configuration file with filehandler properly setted to an specified size
    http://www.linuxtopia.org/online_books/programming_books/thinking_in_java/TIJ317_021.htm

  • How to write to a log file within a JSP

    Hello everybody,
    do you know how to write to a log file within a JSP.
    my code is (/space/SP/tlf/ExcepcionJava.jsp):
    <html>
    <body bgColor=#C4E1FF>
    <%@ page import="java.io.*" %>
    <%
         FileWriter salida = new FileWriter(response.encodeURL("log.txt"));
         salida.write(request.getParameter("errorMsg"));
         salida.close();
    %>
    </body>
    </html>.. I run under Solaris, Jrun 2.3.3
    I have also test with getServletContext().getRealPath(), but I get /netsrv/nes/docs/ instead of /space/SP/tlf/

    Hi,
    Give the full path of the log file to the FileWriter. Such as;
    FileWriter salida = new FileWriter(response.encodeURL("/usr/local/tomcat/logs/testlogs/log.txt"));
    nurettin

  • Create different log file with different schema by spool

    Hello,
    I want to know a way to create a different log file depend on different schema
    I have two schema on same db server
    1) schema kennam/*****/kennam
    2) schema koonhey/*****/koonhey
    by a way, I want to create a different log file name e.g. kennam.log / koonhey.log on such two schema...
    I always run @showbalance; to run showbalance.sql to create that report..
    I hope you understand what I talking about (english is not my native language........), anyone could help?
    showbalancelog.sql
    spool c:\log.log+
    spool c:\log.log
    select to_char(sysdate,'dd-mm-yyyy hh:mi:ss') from dual;
    column com_name format a20;
    select cus.tid, cus.com_name com_name, cus.com_balance,
    NVL((select sum(invoice_total) from invoice where com_id=cus.tid),0) sum_invoice,
    NVL((select sum(cheque_amount) from income where com_id=cus.tid),0) sum_income,
    cus.com_balance -
    NVL((select sum(invoice_total) from invoice where com_id=cus.tid),0) +
    NVL((select sum(cheque_amount) from income where com_id=cus.tid),0) total_balance
    from customers cus
    order by cus.tid;
    spool off

    okey I solved on this way, is anyone know another simpler way?
    be simpler part
    variable vspoolfile varchar2(20)
    declare
    username varchar2(20);
    spoolfile varchar2(50);
    begin
    select 'c:\' || user || '.log' into spoolfile from dual;
    -- spoolfile := 'c:\' || username || '.log';
    :vspoolfile := spoolfile;
    -- dbms_output.PUT_LINE(spoolfile);
    end;
    -- print :vspoolfile;
    column spoolfilecol new_value definespoolfile noprint
    select :vspoolfile spoolfilecol from dual;full content of my showbalancelog.sql file
    variable vspoolfile varchar2(20)
    declare
    username varchar2(20);
    spoolfile varchar2(50);
    begin
    select 'c:\' || user || '.log' into spoolfile from dual;
    -- spoolfile := 'c:\' || username || '.log';
    :vspoolfile := spoolfile;
    -- dbms_output.PUT_LINE(spoolfile);
    end;
    -- print :vspoolfile;
    column spoolfilecol new_value definespoolfile noprint
    select :vspoolfile spoolfilecol from dual;
    spool &definespoolfile;
    column com_name format a20;
    select cus.tid, cus.com_name com_name, cus.com_balance,
    NVL((select sum(invoice_total) from invoice where com_id=cus.tid),0) sum_invoice,
    NVL((select sum(cheque_amount) from income where com_id=cus.tid),0) sum_income,
    cus.com_balance -
    NVL((select sum(invoice_total) from invoice where com_id=cus.tid),0) +
    NVL((select sum(cheque_amount) from income where com_id=cus.tid),0) total_balance
    from customers cus
    order by cus.tid;
    spool off;

  • How to configure IPS 4240 - K9 to send log file to syslog server

    I am looking for the commands in how to configure IPS 4240-k9 to send log file to SYSLOG server. If anybody has or came across similer issue please advice.
    Thanks in advanced.

    Ali -
    I am sorry to tell you, but the Cisco IPS Sensors do not send Syslog messages. Your only options for sending signature event information are:
    SDEE (an TLS Encrypted XML formatted message) the sensor is the SDEE Host and your event receiver (MARS, IME, Intelitactics, etc) is the client.
    SNMP Traps - You need to set the "Action" on each signature you want the sensor to send a trap.
    - Bob

  • How to create different log files for different levels

    Hi,
    Can some one please help me with my problem I have here?
    I want to send log data to two diffrent files depending on the logging level such as DEBUG and WARN using the same logger instance.
    How can you configure this in log4j.properties.
    Please post sample code for log4j.properties to achieve this.
    Thanks in advance.
    Anurag SIngh

    Hi,
    I have tried your code. the issue is other log file for error is blank. its not writting log to that file.
    following is the code of my log4j.properties
    Please read the code first
    # Set root logger level to DEBUG and its only appender to A1.
    log4j.rootCategory=DEBUG,A1
    #Appender and its layout for A1
    log4j.appender.A1=org.apache.log4j.FileAppender
    log4j.appender.A1.layout=org.apache.log4j.PatternLayout
    log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %log4j.appender.A1.Threshold=DEBUG
    log4j.appender.A1.File=./LogonApplication_Debug.log
    log4j.appender.A1.Append=true
    #Appender and its layout for A2
    log4j.appender.A2=org.apache.log4j.FileAppender
    log4j.appender.A2.layout=org.apache.log4j.PatternLayout
    log4j.appender.A2.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %
    log4j.appender.A2.Threshold=ERROR
    log4j.appender.A2.File=./LogonApplication_Error.log
    log4j.appender.A2.Append=true
    In my logger class i have written something like this:
    public static Logger myLogger = Logger.getLogger (LoggerTest.class.getName());
         public static void main(String args[]){
              myLogger.debug("I have logged a debug message");
              myLogger.error("I have logged an error message");
    Issue:
    Now the problem is that it is creating two files specified in the configuration but it is logging messages both the messages debug and error in only ./LogonApplication_Debug.log file.
    Though it is creating the ./LogonApplication_Error.log file, but it is only blank.
    Can you please trace whats missing/wrong.
    Thanks a lot.
    Shanu

  • Java.util.logging: write to one log file from many application (classes)

    I have a menuapp to launch many applications, all running in same JVM and i want to add logging information to them, using java.util.logging.
    Intention is to redirect the logginginfo to a specific file within the menuapp. Then i want all logging from all applications written in same file. Finally, if needed (but i don't think it is), i will include code to write logging to specific file per app (class). The latter is probably not neccessary because there are tools to analyse the logging-files and allow to select filters on specific classes only.
    The applications are in their own packages/jars and contain following logging-code:
            // Redirect error output
            try {
                myHandler = new FileHandler("myLogging.xml",1000000,2);
            } catch (IOException e) {
              System.out.println("Could not create file. Using the console handler");
            myLogger.addHandler(myHandler);
            myLogger.info("Our first logging message");
            myLogger.severe("Something terrible happened");
            ...When i launch the menuapplication, it writes info to "myLogging.xml.0"
    but when i launch an application, the app writes info to "myLogging.xml.0.1"
    I already tried to leave out the creation of a new Filehandler (try/catch block in code above) but it doesn't help.
    Is it possible to write loginfo to same specific file?

    You should open/close it somehow at every write from different processes.
    But I personally prefer different file names to your forced merging, though.

  • Need example with write to DATA log file programmatically?

    Hi all,
    I would like to request for an example of writing a datalog (*.DAT) file which could do this.
    Datalog file.
    NAME: AGE: SEX: (header)
    john 16 M (data)
    marie 55 F
    Dolah 34 M
    The program can also let me to add in new data and then store in the same file.dat. The data (hopefully) can be written to the bottom of the last saved entry of data. (eg. after the row Dolah).
    I need to do this so that I can open and read back the datalog file and use the data for other purpose.
    Please help,
    juni

    You've got some examples in Fundamentals>File Input and Output but one of the easiest things to do is to modify Write Strings to Spreadsheet File.vi to write strings as detailed at the bottom of the diagram and then save it to a different place and with a different name.
    Attachments:
    Spreadsheet_File_Write.jpg ‏17 KB

  • How to write into ldt log file in case of custom lct file

    Hi Experts,
    I have created one custom lct file for one of my requirement, from that I am calling database package for  UPLOAD.
    I want to write message into ldt log file if some validation fails.
    Can anyone suggest how can I write messages into ldt log file.
    Regards,
    Brajesh

    user13537002 wrote:
    Hi,
    After some search I got the solution
    api  FND_SEED_STAGE_UTIL.INSERT_MSG('Message'); works for me....it write message into ldt log file
    Regards,
    Brajesh
    Thanks for the update and for sharing the solution!
    Regards,
    Hussein

  • Different log file name in the Control file of SQL Loader

    Dear all,
    I get every day 3 log files with ftp from a Solaris Server to a Windows 2000 Server machine. In this Windows machine, we have an Oracle Database 9.2. These log files are in the following format: in<date>.log i.e. in20070429.log.
    I would like to load this log file's data to an Oracle table every day and I would like to use SQL Loader for this job.
    The problem is that the log file name is different every day.
    How can I give this variable log file name in the Control file, which is used for the SQL Loader?
    file.ctl
    LOAD DATA
    INFILE 'D:\gbal\in<date>.log'
    APPEND INTO TABLE CHAT_SL
    FIELDS TERMINATED BY WHITESPACE
    TRAILING NULLCOLS
    (SL1 DATE "Mon DD, YYYY HH:MI:SS FF3AM",
    SL2 char,
    SL3 DATE "Mon DD, YYYY HH:MI:SS FF3AM",
    SL4 char,
    SL5 char,
    SL6 char,
    SL7 char,
    SL8 char,
    SL9 char,
    SL10 char,
    SL11 char,
    SL12 char,
    SL13 char,
    SL14 char,
    SL15 char)
    Do you have any better idea about this issue?
    I thought of renaming the log file to an instant name, such as in.log, but how can I distinguish the desired log file, from the other two?
    Thank you very much in advance.
    Giorgos Baliotis

    I don't have a direct solution for your problem.
    However if you invoke the SQL loader from an Oracle stored procedure, it is possible to dynamically set control\log file.
    # Grant previleges to the user to execute command prompt statements
    BEGIN
    dbms_java.grant_permission('bc4186ol','java.io.FilePermission','C:\windows\system32\cmd.exe','execute');
    END;
    * Procedure to execute Operating system commands using PL\SQL(Oracle script making use of Java packages
    CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Host" AS
    import java.io.*;
    public class Host {
    public static void executeCommand(String command) {
    try {
    String[] finalCommand;
    finalCommand = new String[4];
    finalCommand[0] = "C:\\windows\\system32\\cmd.exe";
    finalCommand[1] = "/y";
    finalCommand[2] = "/c";
    finalCommand[3] = command;
    final Process pr = Runtime.getRuntime().exec(finalCommand);
    new Thread(new Runnable() {
    public void run() {
    try {
    BufferedReader br_in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
    String buff = null;
    while ((buff = br_in.readLine()) != null) {
    System.out.println("Process out :" + buff);
    try {Thread.sleep(100); } catch(Exception e) {}
    catch (IOException ioe) {
    System.out.println("Exception caught printing process output.");
    ioe.printStackTrace();
    }).start();
    new Thread(new Runnable() {
    public void run() {
    try {
    BufferedReader br_err = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
    String buff = null;
    while ((buff = br_err.readLine()) != null) {
    System.out.println("Process err :" + buff);
    try {Thread.sleep(100); } catch(Exception e) {}
    catch (IOException ioe) {
    System.out.println("Exception caught printing process error.");
    ioe.printStackTrace();
    }).start();
    catch (Exception ex) {
    System.out.println(ex.getLocalizedMessage());
    public static boolean isWindows() {
    if (System.getProperty("os.name").toLowerCase().indexOf("windows") != -1)
    return true;
    else
    return false;
    * Oracle wrapper to call the above procedure
    CREATE OR REPLACE PROCEDURE Host_Command (p_command IN VARCHAR2)
    AS LANGUAGE JAVA
    NAME 'Host.executeCommand (java.lang.String)';
    * Now invoke the procedure with an operating system command(Execyte SQL-loader)
    * The execution of script would ensure the Prod mapping data file is loaded to PROD_5005_710_MAP table
    * Change the control\log\discard\bad files as apropriate
    BEGIN
    Host_Command (p_command => 'sqlldr system/tiburon@orcl control=C:\anupama\emp_join'||1||'.ctl log=C:\anupama\ond_lists.log');
    END;Does that help you?
    Regards,
    Bhagat

  • Problem with java.util.logging - write to multiple log files

    Hi guys,
    I'm having trouble with logging to multiple files - i am using the constructor for creating multiple files with size limitation - FileHandler(String pattern, int limit, int count, boolean append).
    The problem i encounter is that it writes to the next log file before exceeding the limit, can it be because of file lock or something? what can i do in order to fill log files in a given limit and then write to the next?

    I thought it is synchronized by definition - i'm just creating loggers that write to
    the same file(s). When i used 1 file instead of using the limit and several
    files - all went well.Just a small question: all these loggers do use the same FileHandler don't they?
    I bet they do, just asking ...
    The problem started when i wanted each file to reach a limit before start writing
    to a new file. Should i synchronize the log somehow? That's what I suggested in my previous reply, but IMHO it shouldn't be necessary
    given what I read from the sources ...
    What could be the reason for not reaching the limit before opening a new file?Sorry I don't have an answer (yet), still thinking though ... it's a strange problem.
    kind regards,
    Jos (hrrmph ... stoopid problem ;-)

  • How to disable write to redo log file in oracle7.3.4

    in oracle 8, alter table no logged in redo log file like: alter table tablename nologging;
    how to do this in oracle 7.3.4?
    thanks.

    user652965 wrote:
    Thanks very much for your help guys. I appreciate it. unfortunately none of these commands worked for me. I kept getting error on clearing logs that redo log is needed to perform recovery so it can't be cleared. So I ended up restoring from earlier snapshot of my db volume. Database is now open.
    Thanks again for your input.And now, as a follow-up, at a minimum you should make sure that all redo log groups have at least 3 members. Then, if you lose a single redo log file, all you have to do is shutdown the db and copy one of the good members (of the same group as the lost member) over the lost member.
    And as an additional follow-up, if you value your data you will run in archivelog mode and take regular backups of the database and archivelogs. If you fail to do this you are saying that your data is not worth saving.

Maybe you are looking for