开发者

How to use SLF4J to log to two different files based on type of msg..?

开发者 https://www.devze.com 2023-03-27 04:58 出处:网络
i am running a client server program in spring. i am trying to implement SLF4J + Logback for logging. Now the thing is my client (which in real life would be a device/sensor) will send me data in str

i am running a client server program in spring. i am trying to implement SLF4J + Logback for logging.

Now the thing is my client (which in real life would be a device/sensor) will send me data in string format which contains various fields seperated by comma) exact pattern is like this : deviceID,DeviceName,DeviceLocation,TimeStamp,someValue

now what i want is to filter the message in Logback using deviceID and then write the whole string to file which has name like device.log suppose for example 1,indyaa开发者_开发技巧h,Scranton,2011-8-10 12:00:00,34 should be logged in to file device1.log dynamically. so how can i use evaluateFilter in logback/janino.

Thanks in advance.


Logback provides all the features you need out of the box. You need to learn about SiftingAppender and probably MDC.

SiftingAppender wraps several homogeneous appenders and picks single one per each logging message based on user-defined criteria (called distriminator). The documentation is pretty good, and it has some nice examples.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号