• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Logging new, unsupported fields

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
reply
    Bookmark Topic Watch Topic
  • New Topic