Java slf4j Logger loggerForThisClass()

Here you can find the source of loggerForThisClass()

Description

logger For This Class

License

Apache License

Declaration

public static Logger loggerForThisClass() 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Main {
    public static Logger loggerForThisClass() {
        // We use the third stack element; second is this method, first is .getStackTrace()
        final StackTraceElement myCaller = Thread.currentThread().getStackTrace()[2];
        if (!"<clinit>".equals(myCaller.getMethodName())) {
            throw new RuntimeException("Logger must be static");
        }//from  www . j  a v a  2 s.c  o  m
        return LoggerFactory.getLogger(myCaller.getClassName());
    }
}

Related

  1. logError(Logger log, Throwable t, String message)
  2. logError(String message, Throwable ex, Logger logger, String userId)
  3. logErrors(Logger logger, List strings)
  4. LogException(Logger log, String descrption, Throwable e)
  5. logExit(Logger logger, String methodName, String returnValue, long timeSpent)
  6. loggerWithName(Class klass, String name)
  7. logInfo(Logger log)
  8. logInfo(Logger log, Throwable t)
  9. logInfo(Logger logger, String s)