logging - Add ${xd.job.name} and ${xd.stream.name} to Spring XD logs -
we running several streams , jobs on spring xd v1.0.0.release. corresponding stream , job modules log messages spring xd's global log files, under $xd_home/logs need tell apart log messages created each job , stream. tagging each log line value of ${xd.job.name} or ${xd.stream.name} should work us. example,
1) in config file (spring xd config, xml context file, java class... whatever), set java context(?) variable:
if(moduletype == "job") { name = ${xd.job.name}; } else if(moduletype == "stream") { name = ${xd.stream.name}; } else { name = "xd"; }
2) configure log4j properties files under $xd_home/config accordingly:
log4j.appender.file.layout.conversionpattern=%d{absolute} %5p %t %c{2} [${name}] - %m%n
3) log output spring xd running job (xd.job.name = "foojob") , stream (xd.stream.name = "barstream"):
... 13:07:41,169 debug task-scheduler-1 myjobimpl.transactionmanager [foojob] - initiating transaction commit ... 13:08:43,215 info task-scheduler-15 mystreamimpl.jsondecoder [barstream] - decoding json: {...} ... 14:08:42,569 info deploymentspathchildrencache-0 monitor.integrationmbeanexporter [xd] - summary on shutdown: messagechannelmonitor: [name=input, sends=0]
4) message logged other libraries (e.g. spring data, apache commons, whatever) should have 1 of [foojob], [barstream] or [xd], same value job or stream invoked library.
the only half-baked solution came far setting $name in log4j's mdc or ndc, don't know how set on per-stream or per-job basis (mdc , ndc work on per-thread basis).
is there way add together job or stream name corresponding log lines?
we talking internally after seeing other question.
we discussed mdc, set in bus implementations work processors , sinks. we'd need code in spring integration/spring batch create work sources , jobs well.
it overhead many wouldn't want have optional.
bottom line don't have solution (yet), sense free open new feature jira issue.
edit: responding comment below...
hmmmm... processors , sinks add together channelinterceptor
input
channel , force name in presend()
, pop in postsend()
. sources same on output
channel.
the problem postsend()
not called if exception thrown after presend()
. spring integration 4.1 (should released next week; available release candidate) adds support calling interceptor.aftersendcompletion()
called regardless of whether exception occurred or not.
note: when getting reference channel, add together interceptor, have using channelinterceptoraware
because bean might proxied.
if works, , contribute it we'd happy consider it.
logging spring-batch spring-integration spring-xd
No comments:
Post a Comment