Example usage for org.apache.commons.logging.impl Log4JLogger Log4JLogger

List of usage examples for org.apache.commons.logging.impl Log4JLogger Log4JLogger

Introduction

In this page you can find the example usage for org.apache.commons.logging.impl Log4JLogger Log4JLogger.

Prototype

public Log4JLogger(Logger logger) 

Source Link

Document

For use with a log4j factory.

Usage

From source file:com.github.veithen.ulog.Log4jLogFactory.java

protected Log newInstance(String name) {
    return new Log4JLogger(name);
}

From source file:com.linuxbox.util.ThreadAwareLogger.java

public ThreadAwareLogger(String name) {
    actualLog = new Log4JLogger(name);
}

From source file:cz.fi.muni.xkremser.editor.server.guice.LogProvider.java

@Override
public Log get() {
    return new Log4JLogger("MeditorLogger");
}

From source file:interactivespaces.launcher.bootstrap.Log4jLoggingProvider.java

/**
 * Configure the provider.//from  w  w w.j ava2  s  .  c om
 *
 * @param baseInstallDir
 *          base installation directory for IS
 */
public void configure(File baseInstallDir) {
    File loggingPropertiesFile = new File(baseInstallDir, LOGGING_PROPERTIES_FILE);

    Properties loggingProperties = new Properties();

    FileInputStream fileInputStream = null;

    try {
        fileInputStream = new FileInputStream(loggingPropertiesFile);
        loggingProperties.load(fileInputStream);

        loggingProperties.put("log4j.appender.interactivespaces.File",
                new File(baseInstallDir, "logs/interactivespaces.log").getAbsolutePath());
        PropertyConfigurator.configure(loggingProperties);
        baseInteractiveSpacesLogger = Logger.getLogger(LOGGER_BASE_NAME);

        baseContainerLog = new Log4JLogger(baseInteractiveSpacesLogger);
    } catch (FileNotFoundException e) {
        throw new RuntimeException(String.format("Unable to find container configuration %s",
                loggingPropertiesFile.getAbsolutePath()));
    } catch (IOException e) {
        throw new RuntimeException(String.format("Error while reading container configuration %s",
                loggingPropertiesFile.getAbsolutePath()), e);
    }
}

From source file:interactivespaces.launcher.bootstrap.Log4jLoggingProvider.java

@Override
public Log getLog(String logName, String level) {
    Level l = LOG_4J_LEVELS.get(level.toLowerCase());
    boolean unknownLevel = false;
    if (l == null) {
        unknownLevel = true;//  ww w  .j  a v  a  2 s .  co  m
        l = Level.ERROR;
    }

    Logger logger = Logger.getLogger("interactivespaces." + logName);
    logger.setLevel(l);

    if (unknownLevel) {
        logger.error(String.format("Unknown log level %s, set to ERROR", level));
    }

    return new Log4JLogger(logger);
}

From source file:io.smartspaces.launcher.bootstrap.Log4jLoggingProvider.java

/**
 * Configure the provider.//  w w  w  . ja v  a2  s  . com
 *
 * @param baseInstallDir
 *          base installation directory for IS
 * @param configDir
 *          the configuration directory for IS
 */
public void configure(File baseInstallDir, File configDir) {
    File loggingPropertiesFile = findLoggingConfiguration(baseInstallDir, configDir);

    loggingProperties = new Properties();

    try (FileInputStream fileInputStream = new FileInputStream(loggingPropertiesFile)) {
        loggingProperties.load(fileInputStream);

        loggingProperties.put(LOG4J_PROPERTY_FILEPATH_SMARTSPACES_LOGGER,
                new File(baseInstallDir, FILEPATH_CONTAINER_SMARTSPACES_LOG).getAbsolutePath());
        PropertyConfigurator.configure(loggingProperties);
        basesmartspacesLogger = Logger.getLogger(LOGGER_BASE_NAME);

        baseContainerLog = new Log4JLogger(basesmartspacesLogger);
    } catch (FileNotFoundException e) {
        throw new RuntimeException(String.format("Unable to find container configuration %s",
                loggingPropertiesFile.getAbsolutePath()));
    } catch (IOException e) {
        throw new RuntimeException(String.format("Error while reading container configuration %s",
                loggingPropertiesFile.getAbsolutePath()), e);
    }
}

From source file:io.smartspaces.launcher.bootstrap.Log4jLoggingProvider.java

@Override
public Log getLog(String logName, String level, String filename) {
    synchronized (logDataMap) {
        Level l = LOG_4J_LEVELS.get(level.toLowerCase());
        boolean unknownLevel = false;
        if (l == null) {
            unknownLevel = true;//from w  w  w .  j  ava  2  s. c  o m
            l = Level.ERROR;
        }

        Logger logger = Logger.getLogger("smartspaces." + logName);
        logger.setLevel(l);

        Log4JLogger log = new Log4JLogger(logger);
        LogData logData = new LogData();
        logDataMap.put(log, logData);

        if (filename != null) {
            // Create pattern layout
            PatternLayout layout = new PatternLayout();
            layout.setConversionPattern(loggingProperties.getProperty(LOG4J_PROPERTY_CONVERSTION_PATTERN));
            try {
                RollingFileAppender fileAppender = new RollingFileAppender(layout, filename);
                logger.addAppender(fileAppender);
                logData.setFileAppender(fileAppender);
            } catch (java.io.IOException e) {
                throw new RuntimeException(
                        String.format("Error while creating a RollingFileAppender for %s", filename), e);
            }
        }

        if (unknownLevel) {
            logger.error(String.format("Unknown log level %s, set to ERROR", level));
        }

        return log;
    }
}

From source file:com.orion.bot.Orion.java

/**
 * Object constructor//w ww. j a  v  a 2  s .c o  m
 * 
 * @author Daniele Pantaleone
 * @param  path The Orion configuration file path
 **/
public Orion(String path) {

    try {

        // Loading the main XML configuration file
        this.config = new XmlConfiguration(path);

        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////// LOGGER SETUP /////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        Logger.getRootLogger().setLevel(Level.OFF);
        Logger logger = Logger.getLogger("Orion");

        FileAppender fa = new FileAppender();

        fa.setLayout(new PatternLayout("%-20d{yyyy-MM-dd hh:mm:ss} %-6p %m%n"));
        fa.setFile(this.config.getString("logfile", "basepath") + this.config.getString("logfile", "filename"));
        fa.setAppend(this.config.getBoolean("logfile", "append"));
        fa.setName("FILE");
        fa.activateOptions();

        logger.addAppender(fa);

        if (this.config.getBoolean("logfile", "console")) {

            ConsoleAppender ca = new ConsoleAppender();
            ca.setLayout(new PatternLayout("%-20d{yyyy-MM-dd hh:mm:ss} %-6p %m%n"));
            ca.setWriter(new OutputStreamWriter(System.out));
            ca.setName("CONSOLE");
            ca.activateOptions();

            logger.addAppender(ca);

        }

        // Setting the log level for both the log appenders
        logger.setLevel(Level.toLevel(this.config.getString("logfile", "level")));

        // Creating the main Log object
        this.log = new Log4JLogger(logger);

        // We got a fully initialized logger utility now: printing some info messages
        this.log.info(
                "Starting " + BOTNAME + " " + VERSION + " [" + CODENAME + "] [ " + AUTHOR + " ] - " + WEBSITE);

        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /////////////////////////////////////////////// LOADING PREFERENCES ///////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        this.timeformat = this.config.getString("orion", "timeformat", "EEE, d MMM yyyy HH:mm:ss");
        this.timezone = DateTimeZone.forID(this.config.getString("orion", "timezone", "CET"));
        this.locale = new Locale(this.config.getString("orion", "locale", "EN"),
                this.config.getString("orion", "locale", "EN"));
        this.startuptime = new DateTime(this.timezone);

        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////// PRE INITIALIZED OBJECTS ////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        this.eventBus = new EventBus("events");
        this.schedule = new LinkedHashMap<String, Timer>();
        this.game = new Game();

        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /////////////////////////////////////////////////// STORAGE SETUP /////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        this.storage = new MySqlDataSourceManager(this.config.getString("storage", "username"),
                this.config.getString("storage", "password"), this.config.getString("storage", "connection"),
                this.log);

        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////// BUFFERS SETUP ////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        this.commandqueue = new ArrayBlockingQueue<Command>(this.config.getInt("orion", "commandqueue", 100));
        this.regcommands = new MultiKeyHashMap<String, String, RegisteredCommand>();

        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////// CONSOLE SETUP ////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        this.console = (Console) Class
                .forName("com.orion.console." + this.config.getString("orion", "game") + "Console")
                .getConstructor(String.class, int.class, String.class, Orion.class)
                .newInstance(this.config.getString("server", "rconaddress"),
                        this.config.getInt("server", "rconport"),
                        this.config.getString("server", "rconpassword"), this);

        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /////////////////////////////////////////////////// CONTROLLERS SETUP /////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        this.groups = new GroupC(this);
        this.clients = new ClientC(this);
        this.aliases = new AliasC(this);
        this.callvotes = new CallvoteC(this);
        this.ipaliases = new IpAliasC(this);
        this.penalties = new PenaltyC(this);

        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////// PARSER SETUP/////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        this.parser = (Parser) Class
                .forName("com.orion.parser." + this.config.getString("orion", "game") + "Parser")
                .getConstructor(Orion.class).newInstance(this);

        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////// LOADING PLUGINS //////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        this.plugins = new LinkedHashMap<String, Plugin>();
        Map<String, String> pluginsList = this.config.getMap("plugins");

        for (Map.Entry<String, String> entry : pluginsList.entrySet()) {

            try {

                this.log.debug("Loading plugin [ " + Character.toUpperCase(entry.getKey().charAt(0))
                        + entry.getKey().substring(1).toLowerCase() + " ]");
                Plugin plugin = Plugin.getPlugin(entry.getKey(),
                        new XmlConfiguration(entry.getValue(), this.log), this);
                this.plugins.put(entry.getKey(), plugin);

            } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException
                    | IllegalAccessException | IllegalArgumentException | InvocationTargetException
                    | ParserException e) {

                // Logging the Exception and keep processing other plugins. This will not stop Orion execution
                this.log.error("Unable to load plugin [ " + Character.toUpperCase(entry.getKey().charAt(0))
                        + entry.getKey().substring(1).toLowerCase() + " ]", e);

            }

        }

        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////// PLUGINS SETUP //////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        for (Map.Entry<String, Plugin> entry : this.plugins.entrySet()) {
            Plugin plugin = entry.getValue();
            plugin.onLoadConfig();
        }

        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////// PLUGINS STARTUP /////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        for (Map.Entry<String, Plugin> entry : this.plugins.entrySet()) {

            Plugin plugin = entry.getValue();

            // Check for the plugin to be enabled. onLoadConfig may have disabled
            // such plugin in case the plugin config file is non well formed
            if (plugin.isEnabled())
                plugin.onStartup();

        }

        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////// GAME SERVER SYNC ////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        List<List<String>> status = this.console.getStatus();

        if (status == null) {
            this.log.warn("Unable to synchronize current server status: RCON response is NULL");
            return;
        }

        for (List<String> line : status) {

            // Dumping current user to build an infostring for the onClientConnect parser method
            Map<String, String> userinfo = this.console.dumpuser(Integer.parseInt(line.get(0)));

            // Not a valid client
            if (userinfo == null)
                continue;

            String infostring = new String();

            for (Map.Entry<String, String> entry : userinfo.entrySet()) {
                // Appending <key|value> using infostring format
                infostring += "\\" + entry.getKey() + "\\" + entry.getValue();
            }

            // Generating an EVT_CLIENT_CONNECT event for the connected client
            this.parser.parseLine("0:00 ClientUserinfo: " + line.get(0) + " " + infostring);

        }

        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /////////////////////////////////////////////////////// THREADS SETUP /////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        this.reader = new Thread(new Reader(this.config.getString("server", "logfile"),
                this.config.getInt("server", "logdelay"), this));
        this.commandproc = new Thread(new CommandProcessor(this));
        this.reader.setName("READER");
        this.commandproc.setName("COMMAND");

        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////// THREADS STARTUP ////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        this.commandproc.start();
        this.reader.start();

        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////// NOTICE BOT RUNNING ///////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        this.console.say(
                BOTNAME + " " + VERSION + " [" + CODENAME + "] - " + WEBSITE + " >> " + Color.GREEN + "ONLINE");

    } catch (Exception e) {

        // Stopping Threads if they are alive
        if ((this.commandproc != null) && (this.commandproc.isAlive()))
            this.commandproc.interrupt();
        if ((this.reader != null) && (this.reader.isAlive()))
            this.reader.interrupt();

        // Logging the Exception. Orion is not going to work if an Exception is catched at startup time
        this.log.fatal("Unable to start " + BOTNAME + " " + VERSION + " [" + CODENAME + "] [ " + AUTHOR
                + " ] - " + WEBSITE, e);

    }

}

From source file:de.innovationgate.wgpublisher.design.fs.FileSystemDesignManager.java

public FileSystemDesignManager(WGACore core, WGDatabase db, String path, Map<String, String> options)
        throws WGDesignSyncException, IOException, WGAPIException, InstantiationException,
        IllegalAccessException, InvalidCSConfigVersionException {
    _core = core;/*from   ww  w .  j  a  v  a 2 s. c o  m*/

    // Init logger
    if (db.getDbReference().startsWith(PluginConfig.PLUGIN_DBKEY_PREFIX)) {
        _log = Logger.getLogger(LOGGER_DESIGNSYNC_QUIET);
    } else {
        _log = Logger.getLogger(LOGGER_DESIGNSYNC);
    }

    _fsManager = new StandardFileSystemManager();
    _fsManager.setCacheStrategy(CacheStrategy.MANUAL);
    _fsManager.setLogger(new Log4JLogger(Logger.getLogger(LOGGER_DESIGNSYNC_QUIET)));
    _fsManager.setClassLoader(WGACore.getLibraryLoader());
    _fsManager.setCacheStrategy(getVFSCacheStrategy());
    _fsManager.init();

    _designPath = path;
    _designOptions = options;
    _designKey = options.get(OPTION_DESIGNKEY);

    _db = db;

    _directAccessDefault = db.getBooleanAttribute(WGACore.DBATTRIB_DIRECTACCESSDEFAULT, false);

    // Determine provided types
    String optionProviderTypes = (String) db.getCreationOptions().get(WGDatabase.COPTION_DESIGNPROVIDERTYPES);
    if (optionProviderTypes != null) {
        Iterator<String> providerTypes = WGUtils.deserializeCollection(optionProviderTypes, ",", true)
                .iterator();
        while (providerTypes.hasNext()) {
            String providerTypeName = providerTypes.next();
            int providerType = WGDocument.doctypeNameToNumber(providerTypeName);
            if (providerType != 0) {
                _syncedDoctypes.add(new Integer(providerType));
            }
        }
    } else {
        _syncedDoctypes.add(new Integer(WGDocument.TYPE_FILECONTAINER));
        _syncedDoctypes.add(new Integer(WGDocument.TYPE_TML));
        _syncedDoctypes.add(new Integer(WGDocument.TYPE_CSSJS));
    }

    fetchFileSystem(core);
    if (_db.isConnected()) {
        init();
    } else {
        _db.addDatabaseConnectListener(this);
    }

}

From source file:org.apache.hadoop.fs.azure.TestNativeAzureFileSystemClientLogging.java

@Test
public void testLoggingEnabled() throws Exception {

    LogCapturer logs = LogCapturer.captureLogs(new Log4JLogger(Logger.getRootLogger()));

    // Update configuration based on the Test.
    updateFileSystemConfiguration(true);

    performWASBOperations();/*from   w w  w  . ja  va 2 s  . c om*/

    assertTrue(verifyStorageClientLogs(logs.getOutput(), TEMP_DIR));
}