Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2007

Tip: Looking for answers? Try searching our database.

log4j - openning a new file

Thread view: 
ER - 01 Jul 2007 16:54 GMT
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.
timjowers - 02 Jul 2007 22:30 GMT
> 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
Arne Vajhøj - 12 Aug 2007 03:23 GMT
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.