0

By the below post i can able to configure log4j to log in N different file.

Creating multiple log files of different content with log4j

log4j: Log output of a specific class to a specific appender

But i question is FOO.java should able to log in 2 different files. Normal debug/infos in general logger and some statistics in different logger.

I use slf4j and log4j.. I can able to change the logging framework if needed.

Community
  • 1
  • 1
neo007
  • 27
  • 7
  • Can you please explain what you mean by "some statistics"? Is there some reason you can't configure your "statistics" via configuration in log4j **or** slf4j? – Elliott Frisch Oct 29 '15 at 03:51
  • The application connect to different server once in a minute and prints tons of logs which pollutes the normal .log. Since those polluting log is also needed for debugging purpose i need that in a different file. – neo007 Oct 29 '15 at 03:59

1 Answers1

1

Normally, loggers are named after the class, but you don't have to do that. You can name the logger something totally different, or use the class name with some prefix or suffix, e.g. for class org.example.Foo:

org.example.Foo          <-- Standard logger name
org.example.Foo.stats
stats.org.example.Foo
Foo.stats
stats.Foo
stats.Bar

Using a prefix will allow you to redirect statistics from all sources (classes) to a separate file, in one config entry.

You decide what is appropriate for you.

Andreas
  • 154,647
  • 11
  • 152
  • 247
  • To expand on this, you can use `Logger.getLogger(String)` to get one `Logger` for "statistics" and a second `Logger` for "debug". – Elliott Frisch Oct 29 '15 at 04:06