Search in sources :

Example 56 with Appender

use of org.apache.logging.log4j.core.Appender in project hive by apache.

the class LlapWrappedAppender method setupAppenderIfRequired.

private void setupAppenderIfRequired(LogEvent event) {
    if (appenderControl.get() == null) {
        if (node.getType().getElementName().equalsIgnoreCase("appender")) {
            for (final Node cnode : node.getChildren()) {
                final Node appNode = new Node(cnode);
                config.createConfiguration(appNode, event);
                if (appNode.getObject() instanceof Appender) {
                    final Appender app = appNode.getObject();
                    app.start();
                    if (!(app instanceof RandomAccessFileAppender)) {
                        String message = "Cannot handle appenders other than " + RandomAccessFileAppender.class.getName() + ". Found: " + app.getClass().getName();
                        LOGGER.error(message);
                        throw new IllegalStateException(message);
                    }
                    realAppender.set(app);
                    appenderControl.set(new AppenderControl(app, null, null));
                    if (LOGGER.isDebugEnabled()) {
                        RandomAccessFileAppender raf = (RandomAccessFileAppender) app;
                        LOGGER.debug("Setup new appender to write to file: " + raf.getFileName() + ", appenderName=" + raf.getName() + ", appenderManagerName=" + raf.getManager().getName());
                    }
                    break;
                }
            }
            if (appenderControl.get() == null) {
                // Fail if mis-configured.
                throw new RuntimeException(LlapWrappedAppender.class.getSimpleName() + "name=" + getName() + " unable to setup actual appender." + "Could not find child appender");
            }
        } else {
            // Fail if mis-configured.
            throw new RuntimeException(LlapWrappedAppender.class.getSimpleName() + "name=" + getName() + " unable to setup actual appender." + "Could not find child appender");
        }
    }
}
Also used : AbstractAppender(org.apache.logging.log4j.core.appender.AbstractAppender) Appender(org.apache.logging.log4j.core.Appender) RandomAccessFileAppender(org.apache.logging.log4j.core.appender.RandomAccessFileAppender) RandomAccessFileAppender(org.apache.logging.log4j.core.appender.RandomAccessFileAppender) AppenderControl(org.apache.logging.log4j.core.config.AppenderControl) PluginNode(org.apache.logging.log4j.core.config.plugins.PluginNode) Node(org.apache.logging.log4j.core.config.Node)

Example 57 with Appender

use of org.apache.logging.log4j.core.Appender in project hive by apache.

the class HadoopJobExecHelper method localJobDebugger.

public void localJobDebugger(int exitVal, String taskId) {
    StringBuilder sb = new StringBuilder();
    sb.append("\n");
    sb.append("Task failed!\n");
    sb.append("Task ID:\n  " + taskId + "\n\n");
    sb.append("Logs:\n");
    console.printError(sb.toString());
    for (Appender appender : ((Logger) LogManager.getRootLogger()).getAppenders().values()) {
        if (appender instanceof FileAppender) {
            console.printError(((FileAppender) appender).getFileName());
        } else if (appender instanceof RollingFileAppender) {
            console.printError(((RollingFileAppender) appender).getFileName());
        }
    }
}
Also used : Appender(org.apache.logging.log4j.core.Appender) FileAppender(org.apache.logging.log4j.core.appender.FileAppender) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) FileAppender(org.apache.logging.log4j.core.appender.FileAppender) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender)

Example 58 with Appender

use of org.apache.logging.log4j.core.Appender in project hive by apache.

the class LogDivertAppender method getDefaultLayout.

public Layout<? extends Serializable> getDefaultLayout() {
    // There should be a ConsoleAppender. Copy its Layout.
    Logger root = LogManager.getRootLogger();
    Layout layout = null;
    for (Appender ap : ((org.apache.logging.log4j.core.Logger) root).getAppenders().values()) {
        if (ap.getClass().equals(ConsoleAppender.class)) {
            layout = ap.getLayout();
            break;
        }
    }
    return layout;
}
Also used : Appender(org.apache.logging.log4j.core.Appender) AbstractOutputStreamAppender(org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender) ConsoleAppender(org.apache.logging.log4j.core.appender.ConsoleAppender) Layout(org.apache.logging.log4j.core.Layout) PatternLayout(org.apache.logging.log4j.core.layout.PatternLayout) PerfLogger(org.apache.hadoop.hive.ql.log.PerfLogger) Logger(org.apache.logging.log4j.Logger)

Example 59 with Appender

use of org.apache.logging.log4j.core.Appender in project hive by apache.

the class OperationManager method initOperationLogCapture.

private void initOperationLogCapture(String loggingMode) {
    // Register another Appender (with the same layout) that talks to us.
    Appender ap = LogDivertAppender.createInstance(this, OperationLog.getLoggingLevel(loggingMode));
    LoggerContext context = (LoggerContext) LogManager.getContext(false);
    Configuration configuration = context.getConfiguration();
    LoggerConfig loggerConfig = configuration.getLoggerConfig(LoggerFactory.getLogger(getClass()).getName());
    loggerConfig.addAppender(ap, null, null);
    context.updateLoggers();
    ap.start();
}
Also used : Appender(org.apache.logging.log4j.core.Appender) Configuration(org.apache.logging.log4j.core.config.Configuration) LoggerContext(org.apache.logging.log4j.core.LoggerContext) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig)

Example 60 with Appender

use of org.apache.logging.log4j.core.Appender in project elasticsearch by elastic.

the class Bootstrap method init.

/**
     * This method is invoked by {@link Elasticsearch#main(String[])} to startup elasticsearch.
     */
static void init(final boolean foreground, final Path pidFile, final boolean quiet, final Environment initialEnv) throws BootstrapException, NodeValidationException, UserException {
    // Set the system property before anything has a chance to trigger its use
    initLoggerPrefix();
    // force the class initializer for BootstrapInfo to run before
    // the security manager is installed
    BootstrapInfo.init();
    INSTANCE = new Bootstrap();
    final SecureSettings keystore = loadSecureSettings(initialEnv);
    Environment environment = createEnvironment(foreground, pidFile, keystore, initialEnv.settings());
    try {
        LogConfigurator.configure(environment);
    } catch (IOException e) {
        throw new BootstrapException(e);
    }
    checkForCustomConfFile();
    if (environment.pidFile() != null) {
        try {
            PidFile.create(environment.pidFile(), true);
        } catch (IOException e) {
            throw new BootstrapException(e);
        }
    }
    final boolean closeStandardStreams = (foreground == false) || quiet;
    try {
        if (closeStandardStreams) {
            final Logger rootLogger = ESLoggerFactory.getRootLogger();
            final Appender maybeConsoleAppender = Loggers.findAppender(rootLogger, ConsoleAppender.class);
            if (maybeConsoleAppender != null) {
                Loggers.removeAppender(rootLogger, maybeConsoleAppender);
            }
            closeSystOut();
        }
        // fail if somebody replaced the lucene jars
        checkLucene();
        // install the default uncaught exception handler; must be done before security is
        // initialized as we do not want to grant the runtime permission
        // setDefaultUncaughtExceptionHandler
        Thread.setDefaultUncaughtExceptionHandler(new ElasticsearchUncaughtExceptionHandler(() -> Node.NODE_NAME_SETTING.get(environment.settings())));
        INSTANCE.setup(true, environment);
        /* TODO: close this once s3 repository doesn't try to read during repository construction
            try {
                // any secure settings must be read during node construction
                IOUtils.close(keystore);
            } catch (IOException e) {
                throw new BootstrapException(e);
            }*/
        INSTANCE.start();
        if (closeStandardStreams) {
            closeSysError();
        }
    } catch (NodeValidationException | RuntimeException e) {
        // disable console logging, so user does not see the exception twice (jvm will show it already)
        final Logger rootLogger = ESLoggerFactory.getRootLogger();
        final Appender maybeConsoleAppender = Loggers.findAppender(rootLogger, ConsoleAppender.class);
        if (foreground && maybeConsoleAppender != null) {
            Loggers.removeAppender(rootLogger, maybeConsoleAppender);
        }
        Logger logger = Loggers.getLogger(Bootstrap.class);
        if (INSTANCE.node != null) {
            logger = Loggers.getLogger(Bootstrap.class, Node.NODE_NAME_SETTING.get(INSTANCE.node.settings()));
        }
        // HACK, it sucks to do this, but we will run users out of disk space otherwise
        if (e instanceof CreationException) {
            // guice: log the shortened exc to the log file
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            PrintStream ps = null;
            try {
                ps = new PrintStream(os, false, "UTF-8");
            } catch (UnsupportedEncodingException uee) {
                assert false;
                e.addSuppressed(uee);
            }
            new StartupException(e).printStackTrace(ps);
            ps.flush();
            try {
                logger.error("Guice Exception: {}", os.toString("UTF-8"));
            } catch (UnsupportedEncodingException uee) {
                assert false;
                e.addSuppressed(uee);
            }
        } else if (e instanceof NodeValidationException) {
            logger.error("node validation exception\n{}", e.getMessage());
        } else {
            // full exception
            logger.error("Exception", e);
        }
        // re-enable it if appropriate, so they can see any logging during the shutdown process
        if (foreground && maybeConsoleAppender != null) {
            Loggers.addAppender(rootLogger, maybeConsoleAppender);
        }
        throw e;
    }
}
Also used : Appender(org.apache.logging.log4j.core.Appender) ConsoleAppender(org.apache.logging.log4j.core.appender.ConsoleAppender) ConsoleAppender(org.apache.logging.log4j.core.appender.ConsoleAppender) PrintStream(java.io.PrintStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CreationException(org.elasticsearch.common.inject.CreationException) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Logger(org.apache.logging.log4j.Logger) NodeValidationException(org.elasticsearch.node.NodeValidationException) SecureSettings(org.elasticsearch.common.settings.SecureSettings) Environment(org.elasticsearch.env.Environment)

Aggregations

Appender (org.apache.logging.log4j.core.Appender)105 Test (org.junit.Test)52 ConsoleAppender (org.apache.logging.log4j.core.appender.ConsoleAppender)25 Configuration (org.apache.logging.log4j.core.config.Configuration)23 LoggerContext (org.apache.logging.log4j.core.LoggerContext)18 ListAppender (org.apache.logging.log4j.test.appender.ListAppender)18 LoggerConfig (org.apache.logging.log4j.core.config.LoggerConfig)15 FileAppender (org.apache.logging.log4j.core.appender.FileAppender)14 Logger (org.apache.logging.log4j.Logger)13 BuiltConfiguration (org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration)12 AbstractAppender (org.apache.logging.log4j.core.appender.AbstractAppender)10 RollingFileAppender (org.apache.logging.log4j.core.appender.RollingFileAppender)10 AppenderControl (org.apache.logging.log4j.core.config.AppenderControl)10 Map (java.util.Map)8 Filter (org.apache.logging.log4j.core.Filter)8 URL (java.net.URL)7 IOException (java.io.IOException)6 LogEvent (org.apache.logging.log4j.core.LogEvent)6 File (java.io.File)5 Logger (org.apache.logging.log4j.core.Logger)5