SystemLogger4J consists of a single class which contains a small of APIs, works as wrappers over the standard Log4J APIs. This is Eclipse project with Apache Maven compatiblity, so no need to add dependencies explicitly if the Maven is configured properly.
package org.shared.commons.logging; import org.apache.log4j.Logger; import org.apache.log4j.spi.LoggerFactory; /** * This class works as a wrapper over the standard Log4J. */ public class SystemLogger { private static final String LOG_PREFIX = "| " + Thread.currentThread().getName() + " | "; private static SystemLogger systemLoggerInstance; private static Logger logger; private LoggerFactory loggerFactory; private SystemLogger() { // This class can not be instantiated externally } private SystemLogger(final LoggerFactory loggerFactoryInstance) { loggerFactory = loggerFactoryInstance; } /** * Sets logger for a specific 'clazz' * * @param clazz */ public static void setLogger(final Class clazz) { if (systemLoggerInstance == null) { systemLoggerInstance = new SystemLogger(); } logger = Logger.getLogger(clazz); } /** * Sets the logger factory, which remains available application wide once it * is set. * * @param loggerFactoryInstance */ public static void setLoggerFactory(final LoggerFactory loggerFactoryInstance) { if (systemLoggerInstance == null) { systemLoggerInstance = new SystemLogger(loggerFactoryInstance); } } public static void trace(final String message) { if (logger.isTraceEnabled()) { logger.trace(LOG_PREFIX + message); } } public static void info(final String message) { logger.info(LOG_PREFIX + message); } public static void debug(final String message) { if (logger.isDebugEnabled()) { logger.debug(LOG_PREFIX + message); } } public static void warn(final String message) { logger.warn(LOG_PREFIX + message); } public static void error(final String message) { logger.error(LOG_PREFIX + message); } public static void fatal(final String message) { logger.fatal(LOG_PREFIX + message); } public LoggerFactory getLoggerFactory() { return loggerFactory; } }