Code example for LogRecord

Methods: getLevelgetLoggerNamegetMessagegetParametersgetThrown

0
     * juli handler that Redirect to log4j 
     */ 
    public static class JuliToLog4jHandler extends Handler {
 
        public void publish(LogRecord record) {
            org.apache.log4j.Logger log4j = getTargetLogger(record.getLoggerName());
            Priority priority = toLog4j(record.getLevel());
            log4j.log(priority, toLog4jMessage(record), record.getThrown());
        } 
 
        static org.apache.log4j.Logger getTargetLogger(String loggerName) {
            return org.apache.log4j.Logger.getLogger(loggerName);
        } 
 
        public static org.apache.log4j.Logger getTargetLogger(Class<?> clazz) {
            return getTargetLogger(clazz.getName());
        } 
 
        private String toLog4jMessage(LogRecord record) {
            String message = record.getMessage();
            // Format message 
            try { 
                Object parameters[] = record.getParameters();
                if (parameters != null && parameters.length != 0) {
                    // Check for the first few parameters ? 
                    if (message.indexOf("{0}") >= 0
                            || message.indexOf("{1}") >= 0
                            || message.indexOf("{2}") >= 0