avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Approved List" <approved_li...@opticnerve.tv>
Subject LogKit - 'Default' Formatting (Solved!)
Date Fri, 03 May 2002 00:10:51 GMT
Thanks Peter! That did the trick.

I am sure that I am not the only person who has had a similar question, as
the JavaDocs do not really give enough insight into how to really implement
Patterns using Targets and LogTarget.

So, for the benefit of everyone, the following is the complete code used to
"re-configure" the default format of a LogKit message. (Note: This code
sends to System.out only.)

/**-- BEGIN CODE -- **/

/** Constants to be used for the new logger **/
final static String theCategory = "yourCategory";
final static String EOL  = System.getProperty( "line.separator", "\n" );

/** Create the actual logger **/
final static Logger logger = Hierarchy.getDefaultHierarchy().getLoggerFor(
theCategory );

/** Create your 'custom' pattern **/
final PatternFormatter formatter =
	new PatternFormatter( "%{priority}:%{time}:%{category}:%{message}" + EOL );

/** Setup endpoint for log messages **/
final StreamTarget target = new StreamTarget( System.out, formatter );

/** Associate target with logger **/
logger.setLogTargets( new LogTarget[]{target} );
logger.debug( "The Message" );

/**-- END CODE -- **/

I would love it if someone else would check this to make sure that it is in
fact correct. It is working correctly for me, but one never knows.

It might also be great if we could have a similar example for writing out to
a file, as well as examples using the various other formatters. Any takers?

Finally, is there are repository for LogKit examples anywhere? How about a
FAQ dedicated to LogKit?

Regards,

Tal Golan

-----Original Message-----
From: Peter Donald [mailto:peter@apache.org]
Sent: Thursday, May 02, 2002 3:47 PM
To: Avalon Developers List
Subject: Re: LogKit - Formatting


On Fri, 3 May 2002 05:02, Approved List wrote:
> I have created a simple test using the following code from the LogKit
> whitepaper...
>
> Logger logger =
Hierarchy.getDefaultHierarchy().getLoggerFor("myCategory");
> logger.setPriority( Priority.DEBUG );
> logger.debug( "This is a debug message" );

Try the following


//Setup formatter
final PatternFormatter formatter =
 new PatternFormatter( "%{priority}:%{time}:%{category}:%{message}\n" );

//setup endpoint for log messages
final StreamTarget target =
   new StreamTarget( System.out, formatter );

//associate target with logger
logger.setLogTargets( new LogTarget[]{target} );
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.351 / Virus Database: 197 - Release Date: 4/19/2002


--
To unsubscribe, e-mail:   <mailto:avalon-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-dev-help@jakarta.apache.org>


Mime
View raw message