java - Printing calling class name in logs using logback -


i have problem in logging class name of calling class. have logging utility class written in logback. created logger utility using singleton pattern performance reasons. when call logging statement other class print utility's class name not calling class.

private static logutil logutil =null;        public static logutil getinstance(){                 if(logutil==null){             logutil = new logutil();         }         return logutil;      } protected static final logger logger = (logger)loggerfactory.getlogger("mymodule");  public void info(string message){         if(logger.isinfoenabled()){             logger.info(message);          } } 

test class like

public class logutiltest { public static void testforlogging(){ logutil.info(“im logging message”); } } 

i’m getting output below printing logutil instead of logutiltest, need on logging calling class name

2014-04-14 16:47:21 info [main] mymodule [logutil.info:42] class name [com.commonutil.logging.logutil] - method [testforlogging] - no of person's data-100001

you can access current callstack using thread.currentthread().getstacktrace(). returns stacktraceelement array. first item represents getstacktrace(). second method calls , third method want

thread.currentthread().getstacktrace()[2].getclassname() 

returns classname of class calling method.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -