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 / June 2006

Tip: Looking for answers? Try searching our database.

Logger info

Thread view: 
scoffer - 20 Jun 2006 17:39 GMT
Hi all,

i need to change the Formatter for the Logger that write on the console.
My code is something like that:

       logHandler = new FileHandler("RecVenduto.log", true);
       theLogger.addHandler(logHandler);
       theLogger.setLevel(logLevel);
       Handler hdl [] = theLogger.getHandlers();
       for (int cnt=0; cnt < hdl.length; cnt++) {
         hdl[cnt].setFormatter(new MyCustomFormatter());
         hdl[cnt].setLevel(logLevel);
       }

This code change the Formatter for the FileHandler, but the console output
don't change.

Can I set different Levels for FileHandler and console output??

Thanks in advance.

Daniele B.
Software Specialist
Eduardo Yáñez Parareda - 20 Jun 2006 17:40 GMT
> Hi all,
>
[quoted text clipped - 14 lines]
>
> Can I set different Levels for FileHandler and console output??

in the logging.properties file:
java.util.logging.ConsoleHandler.level = FINEST

And to change the formatter:
java.util.logging.ConsoleHandler.formatter = es.bfc.logging.SingleLineFormatter

Why don't you use the properties file to assign handlers to the logger?
scoffer - 20 Jun 2006 17:45 GMT
>> Hi all,
>>
[quoted text clipped - 24 lines]
>
> Why don't you use the properties file to assign handlers to the logger?

I have many other properties to store so I want to store the LogLevel with
the other.

Thank's ... i'm going to test.
scoffer - 20 Jun 2006 17:56 GMT
>> Hi all,
>>
[quoted text clipped - 24 lines]
>
> Why don't you use the properties file to assign handlers to the logger?

I've tried to add another Handler to the Logger of Consolehandler so my code
now is:

       logHandler = new FileHandler("RecVenduto.log", true);
       logHandler.setFormatter(new MyCustomFormatter());
       logHandler.setLevel(Level.FINEST);
       theLogger.addHandler(logHandler);
       ConsoleHandler consoleHandler = new ConsoleHandler();
       consoleHandler.setLevel(Level.INFO);
       consoleHandler.setFormatter(new MyCustomFormatter());
       theLogger.addHandler(consoleHandler);
       theLogger.setLevel(logLevel);

And now I've two different output to my console.

Can I set this configuration programmatically and not from the properties
file??

I've to distribute this application to many sites and I don't want to change
the properties file for every client.
Henry - 20 Jun 2006 22:38 GMT
> >> Hi all,
> >>
[quoted text clipped - 45 lines]
> I've to distribute this application to many sites and I don't want to change
> the properties file for every client.

There is a pretty good article about how logging works and how to do
almost anything you can ever want with it. If you look at the API
documentation in the JDK, you should see a  major section called "Guide
to Features - Java Platform". In the subsection called Base Libraries,
you will find a link for "Logging". If you click on that link, you go
to a short page entitled Java Logging APIs. If you click the first link
on that page, "Logging Overview", you will get the document that
describes the concepts behind Logging in Java.

I think this document should answer most of your questions. You should
also be aware that you can set the properties for logging on your
system in the logging.properties file, which you should find in the lib
directory of the JRE (or the jre/lib directory of your JDK).

--
Buzz
scoffer - 21 Jun 2006 20:44 GMT
scoffer wrote:
> "Eduardo Yáñez Parareda" <eduardo.yanezNOSPAM@NOSPAMgmail.com> ha scritto
> nel messaggio news:4fqms7F1k9r5iU2@individual.net...
[quoted text clipped - 51 lines]
> change
> the properties file for every client.

There is a pretty good article about how logging works and how to do
almost anything you can ever want with it. If you look at the API
documentation in the JDK, you should see a  major section called "Guide
to Features - Java Platform". In the subsection called Base Libraries,
you will find a link for "Logging". If you click on that link, you go
to a short page entitled Java Logging APIs. If you click the first link
on that page, "Logging Overview", you will get the document that
describes the concepts behind Logging in Java.

I think this document should answer most of your questions. You should
also be aware that you can set the properties for logging on your
system in the logging.properties file, which you should find in the lib
directory of the JRE (or the jre/lib directory of your JDK).

--
Buzz

The solution is very simple ..... just create the logger with anonymous
reference like this:

 private static Logger theLogger = Logger.getLogger("");

and the console logger get the same level and formatter from the
fileHandler.

Thanks for the informations.


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.