Package com.ibm.wps.logging

Examples of com.ibm.wps.logging.Logger


     * @see org.apache.log4j.AppenderSkeleton#append(LoggingEvent)
     */
    protected void append(LoggingEvent event) {

        // Try finding a WPS logger which matches the log4j logger.
        Logger logger = null;
        final String loggerName = event.getLoggerName();

        try {
            // Try looking up a class from the log4j logger name. This may
            // fail since log4j allows you to pass logger names as strings.
            Class clazz = Class.forName(loggerName);
            // Look up a WPS logger for the log4j logger class name.
            logger = LogManager.getLogManager().getLogger(clazz);
        } catch (ClassNotFoundException e) {
            // The log4j logger name was not a valid class name.
            // This will happen if we have created a Category with a String
            // which is out of date or has a spelling mistake, or if a third
            // party uses something other than class names as logger names.
            // In this case we just use ourselves as the logger source and
            // report the logger mismatch as an info level log as well.
            logger = LogManager.getLogManager().getLogger(this.getClass());

            synchronized(reportedMissingClasses) {
                if (!reportedMissingClasses.contains(loggerName)) {
                    // Only report a given missing "class" once
                    logger.text(Logger.INFO, null, messageLocalizer.format(
                        "unable-to-find-logger",
                        new Object[]{loggerName, this.getClass().getName()}));
                    reportedMissingClasses.add(loggerName);
                }
            }
        }

        // Map the Log4J 'priority' to the WPS equivalent 'level'.
        int level;
        int priority = event.getLevel().toInt();
        switch (priority) {

            case Level.ERROR_INT:
            case Level.FATAL_INT:
                level = Logger.ERROR;
                break;

            case Level.WARN_INT:
                level = Logger.WARN;
                break;

            case Level.INFO_INT:
                level = Logger.INFO;
                break;

            case Level.DEBUG_INT:
            case Level.ALL_INT:
                level = Logger.TRACE_HIGH;
                break;

            default:
                level = Logger.TRACE_MEDIUM;
                break;
        }

        // If the logger has this log level enabled...
        if (logger.isLogging(level)) {
            // Then, generate the output message, including the required text
            // and optional throwable
            String message = null;
            Throwable throwable = null;
            final ThrowableInformation throwableInformation =
                    event.getThrowableInformation();

            if (throwableInformation != null) {
                throwable = throwableInformation.getThrowable();
            }

            if (layout != null) {
                message = layout.format(event);
            } else {
                message = event.getRenderedMessage();
            }

            if ((message != null) || (throwable != null)) {
                // Log the message via WPS
                logger.text(level, null, message, throwable);
            }
        }
    }
View Full Code Here

TOP

Related Classes of com.ibm.wps.logging.Logger

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.