0

I have the following problem.

Say I have one point of logging in my application. For example I'm receiving some request strings like:

[ABC] 123...

I want to log requests in the following way:

[ABC] 123 ... // -> abc.log
[XYZ] 567 ... // -> xyz.log
...

So log file name can be any combination of 3 [A-Z] symbols.

How can I achieve that with logback?

corvax
  • 1,095
  • 1
  • 10
  • 35
  • Maybe this could help you? http://stackoverflow.com/a/2489569 – smsnheck Oct 10 '16 at 15:26
  • @smsnheck It doesn't help at all. Because it describes logging for two concrete files. I can't define 27x27x27 appenders for each combination of A-Z symbols. – corvax Oct 10 '16 at 15:28
  • 1
    Ok, I see. What about variable replacement with ${logFileName} for the XML config and loggerContext.putProperty("logFileName", "someFileName"); in Java? – smsnheck Oct 10 '16 at 15:32
  • You really understood the problem. But trying to do that I have the following: LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); loggerContext.putProperty("logFileName", "hello"); Logger logger = LoggerFactory.getLogger("hello"); logger.info("hello"); and this file is created - logFileName_IS_UNDEFINED.log . It seems I don't know the proper way to pass variable to the context. – corvax Oct 10 '16 at 16:03
  • How does your XML config look like? – smsnheck Oct 10 '16 at 18:07
  • @smsnheck I've succeed solving my problem using - http://stackoverflow.com/questions/7824620/logback-set-log-file-name-programatically . Thank you very much! – corvax Oct 10 '16 at 18:44

0 Answers0