    001    package org.maltparser.core.helper;
    002
    003    import org.apache.log4j.ConsoleAppender;
    004    import org.apache.log4j.Level;
    005    import org.apache.log4j.Logger;
    006    import org.apache.log4j.PatternLayout;
    007
    008    /**
    009    *
    010    *
    011    * @author Johan Hall
    012    */
    013    public class SystemLogger {
    014            private static SystemLogger uniqueInstance = new SystemLogger();
    015            private static Logger systemLogger;
    016            private Level systemVerbosityLevel;
    017            private ConsoleAppender consoleAppender;
    018
    019            private SystemLogger() {
    020                    systemLogger = Logger.getLogger("System");
    021                    /* System verbosity (Standard Out) */
    022                    consoleAppender = new ConsoleAppender(new PatternLayout("%m"), ConsoleAppender.SYSTEM_ERR);
    023                    consoleAppender.setEncoding("UTF-16");
    024                    systemLogger.addAppender(consoleAppender);
    025                    if (System.getProperty("Malt.verbosity") != null) {
    026                            setSystemVerbosityLevel(System.getProperty("Malt.verbosity").toUpperCase());
    027                    } else {
    028                            setSystemVerbosityLevel("INFO");
    029                    }
    030            }
    031
    032            /**
    033            * Returns a reference to the single instance.
    034            */
    035            public static SystemLogger instance() {
    036                    return uniqueInstance;
    037            }
    038
    039            /**
    040            * Returns a reference to the Logger.
    041            */
    042            public static Logger logger() {
    043                    return systemLogger;
    044            }
    045
    046            /**
    047             * Returns the system verbosity level
    048             *
    049             * @return the system verbosity level
    050             */
    051            public Level getSystemVerbosityLevel() {
    052                    return systemVerbosityLevel;
    053            }
    054
    055            /**
    056             * Sets the system verbosity level
    057             *
    058             * @param verbosity     a system verbosity level
    059             */
    060            public void setSystemVerbosityLevel(String verbosity) {
    061                    this.systemVerbosityLevel = Level.toLevel(verbosity, Level.INFO);
    062                    consoleAppender.setThreshold(systemVerbosityLevel);
    063                    systemLogger.setLevel(systemVerbosityLevel);
    064            }
    065    }