Java Utililty Methods slf4j Logger

List of utility methods to do slf4j Logger

Description

The list of methods to do slf4j Logger are organized into topic(s).

Method

voidlogDebug(String string)
log Debug
logger.info("debug :" + string);
voidlogEntrance(Logger logger, String methodName, String methodArguments)

Logs for entrance into every public methods with Level#DEBUG .

logger.debug(String.format(ENTRANCE_METHOD_PATTERN, methodName, methodArguments));
voidlogError(final Logger logger, final String message, final Throwable cause)
IntelliJ bubbles up all error level logging to user, and if there is a "cause", it makes it a clickable link and user can view the stacktrace.
logger.error(message);
logger.warn(message, cause);
voidlogError(Logger log, Throwable t, String message)
log Error
if (log.isDebugEnabled()) {
    log.error(message, t);
} else {
    log.error(t.getMessage());
voidlogError(String message, Throwable ex, Logger logger, String userId)
This is used for logging exceptions with additional information in the log message.
StringBuilder sb = new StringBuilder();
sb.append(getLogElement("LdapId", userId)).append(getLogElement("Exception", message))
        .append(getLogElement("Cause", ex.getMessage()));
logger.error(sb.toString(), ex);
voidlogErrors(Logger logger, List strings)
Efetua log de varios erros.
if (strings != null) {
    for (String error : strings) {
        logger.error("logErrors :: " + error);
voidLogException(Logger log, String descrption, Throwable e)
Log Exception
String msg = e.getMessage();
log.error("{}:{}", descrption, msg);
voidlogExit(Logger logger, String methodName, String returnValue, long timeSpent)

Logs for exit from every public methods with Level#DEBUG .

logger.debug(String.format(EXIT_METHOD_PATTERN, methodName, returnValue, timeSpent));
LoggerloggerForThisClass()
logger For This Class
final StackTraceElement myCaller = Thread.currentThread().getStackTrace()[2];
if (!"<clinit>".equals(myCaller.getMethodName())) {
    throw new RuntimeException("Logger must be static");
return LoggerFactory.getLogger(myCaller.getClassName());
LoggerloggerWithName(Class klass, String name)
logger With Name
return LoggerFactory.getLogger(String.format("%s.%s", klass.getName(), name));