log4j - openning a new file

Discussion in 'Java' started by ER, Jul 1, 2007.

  1. ER

    ER Guest

    Hi,

    I need to open a new log file in a specific location in the code, how
    can I do that?
    Log file size and number of records are unknown so I cannot use this
    information.
    ER, Jul 1, 2007
    #1
    1. Advertising

  2. ER

    timjowers Guest

    On Jul 1, 11:54 am, ER <> wrote:
    > Hi,
    >
    > I need to open a new log file in a specific location in the code, how
    > can I do that?
    > Log file size and number of records are unknown so I cannot use this
    > information.


    Not sure about log4j but probably the same as Java logging. You can
    create a new handler at any time. That handler can be a file handler.
    Is something like this waht you need?
    FileHandler handler = new FileHandler("another.log",
    appendToFile);
    Logger logger = Logger.getLogger("examples.LogExample");
    logger.addHandler(handler);
    Best,
    TimJowers
    timjowers, Jul 2, 2007
    #2
    1. Advertising

  3. ER wrote:
    > I need to open a new log file in a specific location in the code, how
    > can I do that?
    > Log file size and number of records are unknown so I cannot use this
    > information.


    Simple example:

    log4j.category.test = debug, logfile
    log4j.appender.logfile.threshold = debug
    log4j.appender.logfile = org.apache.log4j.FileAppender
    log4j.appender.logfile.file = C:/first.log
    log4j.appender.logfile.layout = org.apache.log4j.PatternLayout
    log4j.appender.logfile.layout.ConversionPattern = %d %C %M %p: %m%n

    import org.apache.log4j.*;

    public class SwitchFile {
    public static void main(String[] args) {
    PropertyConfigurator.configure("C:\\log4j.properties");
    Logger log = Logger.getLogger("test");
    log.info("1");
    log.info("2");
    FileAppender fa = (FileAppender)log.getAppender("logfile");
    fa.setFile("C:/second.log");
    fa.activateOptions();
    log.info("3");
    log.info("4");
    }
    }

    Arne
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=, Aug 12, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. HVG
    Replies:
    2
    Views:
    337
  2. Alexandra Stehman

    eclipse, junit, log4j, & finding log4j.xml

    Alexandra Stehman, Jan 19, 2004, in forum: Java
    Replies:
    0
    Views:
    5,751
    Alexandra Stehman
    Jan 19, 2004
  3. janaka44
    Replies:
    1
    Views:
    117
    Patrice
    Jun 1, 2005
  4. Fang

    problem with openning a new window

    Fang, Jun 21, 2005, in forum: Javascript
    Replies:
    3
    Views:
    130
    Thomas 'PointedEars' Lahn
    Jul 10, 2005
  5. Yaqian

    need help on openning a new window

    Yaqian, Jun 22, 2005, in forum: Javascript
    Replies:
    3
    Views:
    88
    GĂ©rard Talbot
    Aug 19, 2005
Loading...

Share This Page