3) Use MDC.
private static final Logger log = Logger.getLogger( "job" );
Integer jobId = new Ingteger(1);
MDC.put( "jobid", jobId );
log.error( "Job failed!", exception );
MDC.remove( "jobid" );
This would be my recommended approach from experience. One day
you'll find there's some other crucial bit of info you need to track
(say, userId), and then you're forced to modify every place you
create the custom object to take that new parameter, or start
creating optional constructors (eww).
Instead, at the point the current Thread knows what the user is
(usually somewhere at the start of the operation) it can set and
forget it and no other code needs to know. Remember this is a
logging function (you're trying to instrument your logs with more
detail) and you could potentially be 'polluting' all of your code
with the concept of JobId where it has no relevance (that is, it just
so happens some bit of code is running in the context of a particular
JobId).
cheers,
Paul
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]