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 / May 2005

Tip: Looking for answers? Try searching our database.

java.util.logging Help

Thread view: 
cppaddict - 08 May 2005 08:47 GMT
I've read a couple of online tutorials about the java.util.logging
API, and have gone over the examples here:

http://java.sun.com/j2se/1.4.2/docs/guide/util/logging/overview.html#2.0

I am still unclear on some basic points, and would love to see a few
more detailed examples -- ideally, a sample app made up of a handful
of collaborating classes.  However, I cannot find anything like this
on google.  Can anyone point me in the right direction?

I only need to use very simple logging.  I want to be able to control
output using levels, output to console or file or both (depending on
my config).  I still don't understand why each class needs its own
logger, and I don't know how to control output using config files (or
how to set the location of a config file).

Thanks for any help,
cpp
Betty - 08 May 2005 20:04 GMT
> I've read a couple of online tutorials about the java.util.logging
> API, and have gone over the examples here:
[quoted text clipped - 14 lines]
> Thanks for any help,
> cpp

static Logger logger = Logger.getLogger("global"); // standard java logging
capability
static Handler fh = null; // file handler
static Handler ch = null; // console handler

try
{
 fh = new FileHandler("LOGFILE-NewDraw%g.log", 50000, 10, false); //
default level = ALL
 ch = new ConsoleHandler(); // default level = INFO
}
catch (SecurityException e1)
{
 System.err.println("Security Exception"); // should not happen
 e1.printStackTrace();
 System.exit(1);
}
catch (IOException e1)
{
 System.err.println("IO Exception");
 e1.printStackTrace();
 System.exit(1);
}
// default handler for console is SimpleFormatter()
fh.setFormatter(new SimpleFormatter()); // default handler for file is XML
fh.setLevel(Level.ALL); // change level here if you want to change it
ch.setLevel(Level.ALL);
logger.addHandler(fh);
logger.addHandler(ch);
logger.setLevel(Level.ALL); // null
// default is one parent handler and that is console at level INFO, so kill
it
// since we want to have control over all handlers
logger.setUseParentHandlers(false);

// a couple of test messages, both go into log file
System.out.println("testing level \"fine\""); // should not see (ch level is
INFO)
System.out.println("testing level \"warning\""); // should see this msg


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.