Search in sources :

Example 16 with ConsoleAppender

use of org.apache.log4j.ConsoleAppender in project ignite by apache.

the class GridTestLog4jLogger method createConsoleAppender.

/**
     * Creates console appender with some reasonable default logging settings.
     *
     * @param maxLevel Max logging level.
     * @return New console appender.
     */
private Appender createConsoleAppender(Level maxLevel) {
    String fmt = "[%d{ABSOLUTE}][%-5p][%t][%c{1}] %m%n";
    // Configure output that should go to System.out
    Appender app = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_OUT);
    LevelRangeFilter lvlFilter = new LevelRangeFilter();
    lvlFilter.setLevelMin(Level.TRACE);
    lvlFilter.setLevelMax(maxLevel);
    app.addFilter(lvlFilter);
    return app;
}
Also used : Appender(org.apache.log4j.Appender) ConsoleAppender(org.apache.log4j.ConsoleAppender) FileAppender(org.apache.log4j.FileAppender) ConsoleAppender(org.apache.log4j.ConsoleAppender) PatternLayout(org.apache.log4j.PatternLayout) LevelRangeFilter(org.apache.log4j.varia.LevelRangeFilter)

Example 17 with ConsoleAppender

use of org.apache.log4j.ConsoleAppender in project ignite by apache.

the class GridTestLog4jLogger method addConsoleAppenderIfNeeded.

/**
     * Adds console appender when needed with some default logging settings.
     *
     * @param logLevel Optional log level.
     * @param implInitC Optional log implementation init closure.
     */
private void addConsoleAppenderIfNeeded(@Nullable Level logLevel, @Nullable IgniteClosure<Boolean, Logger> implInitC) {
    if (inited) {
        if (implInitC != null)
            // Do not init.
            impl = implInitC.apply(false);
        return;
    }
    synchronized (mux) {
        if (inited) {
            if (implInitC != null)
                // Do not init.
                impl = implInitC.apply(false);
            return;
        }
        if (implInitC != null)
            // Init logger impl.
            impl = implInitC.apply(true);
        boolean quiet = Boolean.valueOf(System.getProperty(IGNITE_QUIET, "true"));
        boolean consoleAppenderFound = false;
        Category rootCategory = null;
        ConsoleAppender errAppender = null;
        for (Category l = impl; l != null; ) {
            if (!consoleAppenderFound) {
                for (Enumeration appenders = l.getAllAppenders(); appenders.hasMoreElements(); ) {
                    Appender appender = (Appender) appenders.nextElement();
                    if (appender instanceof ConsoleAppender) {
                        if ("CONSOLE_ERR".equals(appender.getName())) {
                            // Treat CONSOLE_ERR appender as a system one and don't count it.
                            errAppender = (ConsoleAppender) appender;
                            continue;
                        }
                        consoleAppenderFound = true;
                        break;
                    }
                }
            }
            if (l.getParent() == null) {
                rootCategory = l;
                break;
            } else
                l = l.getParent();
        }
        if (consoleAppenderFound && quiet)
            // User configured console appender, but log is quiet.
            quiet = false;
        if (!consoleAppenderFound && !quiet && Boolean.valueOf(System.getProperty(IGNITE_CONSOLE_APPENDER, "true"))) {
            // Console appender not found => we've looked through all categories up to root.
            assert rootCategory != null;
            // to configuration and did not set IGNITE_CONSOLE_APPENDER to false.
            if (errAppender != null) {
                rootCategory.addAppender(createConsoleAppender(Level.INFO));
                if (errAppender.getThreshold() == Level.ERROR)
                    errAppender.setThreshold(Level.WARN);
            } else
                // No error console appender => create console appender with no level limit.
                rootCategory.addAppender(createConsoleAppender(Level.OFF));
            if (logLevel != null)
                impl.setLevel(logLevel);
        }
        quiet0 = quiet;
        inited = true;
    }
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) Appender(org.apache.log4j.Appender) ConsoleAppender(org.apache.log4j.ConsoleAppender) FileAppender(org.apache.log4j.FileAppender) Category(org.apache.log4j.Category) Enumeration(java.util.Enumeration)

Example 18 with ConsoleAppender

use of org.apache.log4j.ConsoleAppender in project lucene-solr by apache.

the class StartupLoggingUtils method muteConsole.

/**
   * Disables all log4j ConsoleAppender's by modifying log4j configuration dynamically.
   * Must only be used during early startup
   * @return true if ok or else false if something happened, e.g. log4j classes were not in classpath
   */
@SuppressForbidden(reason = "Legitimate log4j access")
static boolean muteConsole() {
    try {
        if (!isLog4jActive()) {
            logNotSupported("Could not mute logging to console.");
            return false;
        }
        org.apache.log4j.Logger rootLogger = LogManager.getRootLogger();
        Enumeration appenders = rootLogger.getAllAppenders();
        while (appenders.hasMoreElements()) {
            Appender appender = (Appender) appenders.nextElement();
            if (appender instanceof ConsoleAppender) {
                log.info("Property solr.log.muteconsole given. Muting ConsoleAppender named " + appender.getName());
                rootLogger.removeAppender(appender);
            }
        }
        return true;
    } catch (Exception e) {
        logNotSupported("Could not mute logging to console.");
        return false;
    }
}
Also used : Appender(org.apache.log4j.Appender) ConsoleAppender(org.apache.log4j.ConsoleAppender) ConsoleAppender(org.apache.log4j.ConsoleAppender) Enumeration(java.util.Enumeration) SuppressForbidden(org.apache.solr.common.util.SuppressForbidden)

Example 19 with ConsoleAppender

use of org.apache.log4j.ConsoleAppender in project intellij-community by JetBrains.

the class StartupUtil method prepareAndStart.

static void prepareAndStart(String[] args, AppStarter appStarter) {
    boolean newConfigFolder = false;
    if (!Main.isHeadless()) {
        AppUIUtil.updateFrameClass();
        newConfigFolder = !new File(PathManager.getConfigPath()).exists();
    }
    if (!checkJdkVersion()) {
        System.exit(Main.JDK_CHECK_FAILED);
    }
    // avoiding "log4j:WARN No appenders could be found"
    System.setProperty("log4j.defaultInitOverride", "true");
    try {
        org.apache.log4j.Logger root = org.apache.log4j.Logger.getRootLogger();
        if (!root.getAllAppenders().hasMoreElements()) {
            root.setLevel(Level.WARN);
            root.addAppender(new ConsoleAppender(new PatternLayout(PatternLayout.DEFAULT_CONVERSION_PATTERN)));
        }
    } catch (Throwable e) {
        //noinspection CallToPrintStackTrace
        e.printStackTrace();
    }
    // note: uses config folder!
    if (!checkSystemFolders()) {
        System.exit(Main.DIR_CHECK_FAILED);
    }
    ActivationResult result = lockSystemFolders(args);
    if (result == ActivationResult.ACTIVATED) {
        System.exit(0);
    } else if (result != ActivationResult.STARTED) {
        System.exit(Main.INSTANCE_CHECK_FAILED);
    }
    if (newConfigFolder) {
        appStarter.beforeImportConfigs();
        ConfigImportHelper.importConfigsTo(PathManager.getConfigPath());
    }
    Logger.setFactory(LoggerFactory.class);
    Logger log = Logger.getInstance(Main.class);
    startLogging(log);
    loadSystemLibraries(log);
    fixProcessEnvironment(log);
    if (!Main.isHeadless()) {
        AppUIUtil.updateWindowIcon(JOptionPane.getRootFrame());
        AppUIUtil.registerBundledFonts();
        AppUIUtil.showPrivacyPolicy();
    }
    appStarter.start(newConfigFolder);
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) PatternLayout(org.apache.log4j.PatternLayout) Logger(com.intellij.openapi.diagnostic.Logger) File(java.io.File)

Example 20 with ConsoleAppender

use of org.apache.log4j.ConsoleAppender in project ChatGameFontificator by GlitchCog.

the class FontificatorMain method main.

/**
     * The main method for the program
     * 
     * @param args
     *            unused
     * @throws Exception
     */
public static void main(String[] args) {
    // Configure the logger
    BasicConfigurator.configure(new ConsoleAppender(LOG_PATTERN_LAYOUT));
    Logger.getRootLogger().setLevel(Level.INFO);
    try {
        UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    } catch (Exception e) {
        logger.error(e.toString(), e);
    }
    LogBox logBox = new LogBox();
    // These properties contain all the configuration for the program
    FontificatorProperties fProps = new FontificatorProperties();
    // The ChatWindow is the main window and shows the visualization of the chat
    ChatWindow chatWindow = new ChatWindow();
    // The ControlWindow is the dependent window that has all the options for modifying the properties of the chat
    final ControlWindow controlWindow = new ControlWindow(chatWindow, fProps, logBox);
    // Attempt to load the last opened data, or fall back to defaults if nothing has been loaded or if there are any
    // errors loading
    controlWindow.loadLastData(chatWindow);
    try {
        // Feed the properties into the chat to give it hooks into the properties' configuration models; Feed the
        // ControlWindow into the ChatWindow to give the chat hooks back into the controls; Sets the loaded member
        // Boolean in the chat to indicate it has everything it needs to begin rendering the visualization
        chatWindow.initChat(fProps, controlWindow);
    } catch (Exception e) {
        logger.error(e.toString(), e);
        ChatWindow.popup.handleProblem(e.toString(), e);
        System.exit(1);
    }
    // Build the GUI of the control window
    controlWindow.build(logBox);
    // Load after init takes care of the (mostly chat window based) configurations that require the window be already set up
    controlWindow.loadAfterInit();
    // Give the chat panel the message dialog so it can read censorship rules and call for the manual censorship
    // list to be redrawn when a message is posted
    chatWindow.getChatPanel().setMessageCensor(controlWindow.getMessageDialog().getCensorPanel());
    // Give the debug tab to the chat panel, since it doesn't have a shared reference to a config object for the settings
    chatWindow.getChatPanel().setDebugSettings(controlWindow.getDebugPanel());
    // Finally, display the chat and control windows now that everything has been constructed and connected
    chatWindow.setVisible(true);
    try {
        // Do it ugly but thread safe
        SwingUtilities.invokeAndWait(new Runnable() {

            @Override
            public void run() {
                controlWindow.setVisible(true);
            }
        });
    } catch (Exception e) {
        logger.error("Unable to display control window on initialization", e);
    }
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) ChatWindow(com.glitchcog.fontificator.gui.chat.ChatWindow) FontificatorProperties(com.glitchcog.fontificator.config.FontificatorProperties) ControlWindow(com.glitchcog.fontificator.gui.controls.ControlWindow) LogBox(com.glitchcog.fontificator.gui.controls.panel.LogBox)

Aggregations

ConsoleAppender (org.apache.log4j.ConsoleAppender)32 PatternLayout (org.apache.log4j.PatternLayout)23 ParseException (org.apache.commons.cli.ParseException)9 FileAppender (org.apache.log4j.FileAppender)9 Logger (org.apache.log4j.Logger)9 IOException (java.io.IOException)8 CommandLineParser (org.apache.commons.cli.CommandLineParser)8 Appender (org.apache.log4j.Appender)8 FileInputStream (java.io.FileInputStream)7 CommandLine (org.apache.commons.cli.CommandLine)7 GnuParser (org.apache.commons.cli.GnuParser)7 Options (org.apache.commons.cli.Options)7 Properties (java.util.Properties)6 Option (org.apache.commons.cli.Option)6 Enumeration (java.util.Enumeration)4 LevelRangeFilter (org.apache.log4j.varia.LevelRangeFilter)4 IgniteLogger (org.apache.ignite.IgniteLogger)3 GridTestLog4jLogger (org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger)3 RollingFileAppender (org.apache.log4j.RollingFileAppender)3 ConfigLoader (com.linkedin.databus.core.util.ConfigLoader)2