Java logger that automatically determines caller's class name
Posted
by alex
on Stack Overflow
See other posts from Stack Overflow
or by alex
Published on 2008-09-17T07:06:47Z
Indexed on
2010/05/15
13:34 UTC
Read the original article
Hit count: 279
public static Logger getLogger() {
final Throwable t = new Throwable();
final StackTraceElement methodCaller = t.getStackTrace()[1];
final Logger logger = Logger.getLogger(methodCaller.getClassName());
logger.setLevel(ResourceManager.LOGLEVEL);
return logger;
}
This method would return a logger that knows the class it's logging for. Any ideas against it?
© Stack Overflow or respective owner