Java slf4j Logger logError(String message, Throwable ex, Logger logger, String userId)

Here you can find the source of logError(String message, Throwable ex, Logger logger, String userId)

Description

This is used for logging exceptions with additional information in the log message.

License

Apache License

Declaration

public static void logError(String message, Throwable ex, Logger logger, String userId) 

Method Source Code


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

import org.slf4j.Logger;

public class Main {
    /**//from w w w. j  a  va 2s  . co  m
     * This is used for logging exceptions with additional information in the log message. This method is called for non
     * identifiable exceptions (which will not be surfaced to the user).
     */
    public static void logError(String message, Throwable ex, Logger logger, String userId) {
        StringBuilder sb = new StringBuilder();
        sb.append(getLogElement("LdapId", userId)).append(getLogElement("Exception", message))
                .append(getLogElement("Cause", ex.getMessage()));

        logger.error(sb.toString(), ex);
    }

    private static String getLogElement(String label, Object value) {
        if (value != null) {
            return "[" + label + ": " + value + "] ";
        }
        return "";
    }
}

Related

  1. logDebug(Logger logger, String mensagem, Object... params)
  2. logDebug(String string)
  3. logEntrance(Logger logger, String methodName, String methodArguments)
  4. logError(final Logger logger, final String message, final Throwable cause)
  5. logError(Logger log, Throwable t, String message)
  6. logErrors(Logger logger, List strings)
  7. LogException(Logger log, String descrption, Throwable e)
  8. logExit(Logger logger, String methodName, String returnValue, long timeSpent)
  9. loggerForThisClass()