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

intparsePortNumber(String port, int defaultPort)
parse Port Number
int proxyPort = defaultPort;
if (port != null) {
    try {
        proxyPort = Integer.parseInt(port);
    } catch (NumberFormatException ne) {
        LOGGER.warn("Unable to parse port '" + port + "'. Using default port number " + defaultPort, ne);
return proxyPort;
voidprintInfoLog(Class cla, String message)
print Info Log
LoggerFactory.getLogger(cla).info(message);
voidprintPrettyJson(Logger logger, String json)
print Pretty Json
try {
    ObjectMapper mapper = new ObjectMapper();
    logger.info(mapper.writerWithDefaultPrettyPrinter()
            .writeValueAsString(mapper.readValue(json, Object.class)));
} catch (Exception e) {
    e.printStackTrace();
voidprintRequestLog(Map reqParam)
print Request Log
writeMessage(LOG_STRING_REQ_MSG_BEGIN);
Iterator<Entry<String, String>> it = reqParam.entrySet().iterator();
while (it.hasNext()) {
    Entry<String, String> en = it.next();
    writeMessage("[" + en.getKey() + "] = [" + en.getValue() + "]");
writeMessage(LOG_STRING_REQ_MSG_END);
voidprintResponseLog(String res)
print Response Log
writeMessage(LOG_STRING_RSP_MSG_BEGIN);
writeMessage(res);
writeMessage(LOG_STRING_RSP_MSG_END);
voidprintStackTrace(Logger logger, Throwable e)
print Stack Trace
String stackStr = "";
StackTraceElement[] stacks = e.getStackTrace();
logger.error(e.getMessage());
for (int i = 0; i < stacks.length; i++) {
    stackStr = "File " + stacks[i].getFileName() + " Class " + stacks[i].getClassName() + " Method "
            + stacks[i].getMethodName() + " Line " + stacks[i].getLineNumber();
    logger.error(stackStr);
voidprofilerTrigger2(Logger log, String msg)
profiler Trigger
log.info("profilerTrigger2(); called");
voidputMDCs(String clientId, String subjectId)
put MD Cs
MDC.put(CLIENT_ID, clientId);
MDC.put(SUBJECT_ID, subjectId);
voidrequest(String infoMessage)
request
request.info(infoMessage);
voidrestoreContext(Map mdcContextMap)
restore Context
if (mdcContextMap == null || mdcContextMap.isEmpty()) {
    MDC.clear();
} else {
    MDC.setContextMap(mdcContextMap);