File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Open Source Projects and the fly likes Logging new, unsupported fields Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Reply Bookmark "Logging new, unsupported fields" Watch "Logging new, unsupported fields" New topic
Author

Logging new, unsupported fields

L Duperval
Ranch Hand

Joined: May 14, 2003
Posts: 63
Hi,

We want to use log4j to log even information for our application. We need to log information that isn't part of the log4j spec (for example, number of bytes transferred, userid for this event, etc.). Is there a documented way to do this or do I have to create my own logger?

My goal was to make an appender that received different types of objects as a parameter and the logger would know how that data would be logged to the database according to its type.

For example,

MyObject o1;
logger.info(o1);

OtherObject o2;
logger.info(o2);

would use the same table to log information. But in the cas of o1, it could (conceivably) log the userid, the hostname and some detailed information.

In the case of o2, it could log JRE version, Domain name, other info to the same table. That would probably be on top of some of the data that log4j logs.

has anyone ever done something like this?

Thanks,

L


Live Free, Live Happy
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 13842

If it's system-wide information you wanted to add (JRE version, host name etc.) then it's not the appender you need to play with. Here's the code I wrote for including host name in the logs; first a PatternParser that makes '%h' mean host name:then a PatternLayout that uses that:and finally a snippet from the log4j.properties file:
 
 
subject: Logging new, unsupported fields
 
Threads others viewed
Researching a logging model, advice welcome.
db4o
How to encapsulate Logger info
Log4J configuration problem
Memory Allocation for Strings
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com