Search in sources :

Example 36 with PatternLayout

use of org.apache.log4j.PatternLayout in project mpeg-audio-streams by addradio.

the class Log4J method configureLog4J.

/**
 * configureLog4J.
 * @param level {@link Level}
 */
public static final void configureLog4J(final Level level) {
    final Logger rootLogger = Logger.getRootLogger();
    if (!rootLogger.getAllAppenders().hasMoreElements()) {
        rootLogger.addAppender(new ConsoleAppender(new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN)));
    }
    rootLogger.setLevel(level);
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) PatternLayout(org.apache.log4j.PatternLayout) Logger(org.apache.log4j.Logger)

Example 37 with PatternLayout

use of org.apache.log4j.PatternLayout in project pwm by pwm-project.

the class PwmLogManager method initConsoleLogger.

private static void initConsoleLogger(final Configuration config, final String consoleLogLevel) {
    final Layout patternLayout = new PatternLayout(config.readAppProperty(AppProperty.LOGGING_PATTERN));
    // configure console logging
    if (consoleLogLevel != null && consoleLogLevel.length() > 0 && !"Off".equals(consoleLogLevel)) {
        final ConsoleAppender consoleAppender = new ConsoleAppender(patternLayout);
        final Level level = Level.toLevel(consoleLogLevel);
        consoleAppender.setThreshold(level);
        for (final Package logPackage : LOGGING_PACKAGES) {
            if (logPackage != null) {
                final Logger logger = Logger.getLogger(logPackage.getName());
                logger.setLevel(Level.TRACE);
                logger.addAppender(consoleAppender);
            }
        }
        LOGGER.debug("successfully initialized default console log4j config at log level " + level.toString());
    } else {
        LOGGER.debug("skipping stdout log4j initialization due to blank setting for log level");
    }
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) Layout(org.apache.log4j.Layout) PatternLayout(org.apache.log4j.PatternLayout) PatternLayout(org.apache.log4j.PatternLayout) Level(org.apache.log4j.Level) Logger(org.apache.log4j.Logger)

Example 38 with PatternLayout

use of org.apache.log4j.PatternLayout in project pwm by pwm-project.

the class PwmLogManager method initFileLogger.

private static void initFileLogger(final Configuration config, final String fileLogLevel, final File pwmApplicationPath) {
    final Layout patternLayout = new PatternLayout(config.readAppProperty(AppProperty.LOGGING_PATTERN));
    // configure file logging
    final String logDirectorySetting = config.readAppProperty(AppProperty.LOGGING_FILE_PATH);
    final File logDirectory = FileSystemUtility.figureFilepath(logDirectorySetting, pwmApplicationPath);
    if (logDirectory != null && fileLogLevel != null && fileLogLevel.length() > 0 && !"Off".equals(fileLogLevel)) {
        try {
            if (!logDirectory.exists()) {
                if (logDirectory.mkdir()) {
                    LOGGER.info("created directory " + logDirectory.getAbsoluteFile());
                } else {
                    throw new IOException("failed to create directory " + logDirectory.getAbsoluteFile());
                }
            }
            final String fileName = logDirectory.getAbsolutePath() + File.separator + PwmConstants.PWM_APP_NAME + ".log";
            final RollingFileAppender fileAppender = new RollingFileAppender(patternLayout, fileName, true);
            final Level level = Level.toLevel(fileLogLevel);
            fileAppender.setThreshold(level);
            fileAppender.setMaxBackupIndex(Integer.parseInt(config.readAppProperty(AppProperty.LOGGING_FILE_MAX_ROLLOVER)));
            fileAppender.setMaxFileSize(config.readAppProperty(AppProperty.LOGGING_FILE_MAX_SIZE));
            PwmLogger.setFileAppender(fileAppender);
            for (final Package logPackage : LOGGING_PACKAGES) {
                if (logPackage != null) {
                    // if (!logPackage.equals(PwmApplication.class.getPackage())) {
                    final Logger logger = Logger.getLogger(logPackage.getName());
                    logger.setLevel(Level.TRACE);
                    logger.addAppender(fileAppender);
                // }
                }
            }
            LOGGER.debug("successfully initialized default file log4j config at log level " + level.toString());
        } catch (IOException e) {
            LOGGER.debug("error initializing RollingFileAppender: " + e.getMessage());
        }
    }
}
Also used : Layout(org.apache.log4j.Layout) PatternLayout(org.apache.log4j.PatternLayout) RollingFileAppender(org.apache.log4j.RollingFileAppender) PatternLayout(org.apache.log4j.PatternLayout) Level(org.apache.log4j.Level) IOException(java.io.IOException) Logger(org.apache.log4j.Logger) File(java.io.File)

Example 39 with PatternLayout

use of org.apache.log4j.PatternLayout in project onebusaway-application-modules by camsys.

the class BundleBuildingServiceImpl method configureLogging.

/**
 * setup a logger just for the bundle building activity.
 */
private void configureLogging(OutputStream os) {
    if (_debug)
        return;
    Layout layout = new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN);
    WriterAppender wa = new WriterAppender(layout, os);
    wa.setName("bundlebuilder.out");
    // introducing log4j dependency here
    org.apache.log4j.Logger logger = org.apache.log4j.Logger.getRootLogger();
    logger.addAppender(wa);
    _log.info("configuring logging");
}
Also used : Layout(org.apache.log4j.Layout) PatternLayout(org.apache.log4j.PatternLayout) PatternLayout(org.apache.log4j.PatternLayout) WriterAppender(org.apache.log4j.WriterAppender)

Example 40 with PatternLayout

use of org.apache.log4j.PatternLayout in project BiglyBT by BiglySoftware.

the class UI method initRootLogger.

/**
 * Creates a new instance of Main
 */
/*public UI() {
	}*/
public static void initRootLogger() {
    if (Logger.getRootLogger().getAppender("ConsoleAppender") == null) {
        Appender app;
        app = new ConsoleAppender(new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN));
        app.setName("ConsoleAppender");
        // 'log off' by default
        app.addFilter(new DenyAllFilter());
        Logger.getRootLogger().addAppender(app);
    }
}
Also used : Appender(org.apache.log4j.Appender) ConsoleAppender(org.apache.log4j.ConsoleAppender) ConsoleAppender(org.apache.log4j.ConsoleAppender) DenyAllFilter(org.apache.log4j.varia.DenyAllFilter) PatternLayout(org.apache.log4j.PatternLayout)

Aggregations

PatternLayout (org.apache.log4j.PatternLayout)106 ConsoleAppender (org.apache.log4j.ConsoleAppender)49 Logger (org.apache.log4j.Logger)30 IOException (java.io.IOException)20 Appender (org.apache.log4j.Appender)20 FileAppender (org.apache.log4j.FileAppender)17 File (java.io.File)14 Layout (org.apache.log4j.Layout)14 RollingFileAppender (org.apache.log4j.RollingFileAppender)12 Test (org.junit.Test)12 WriterAppender (org.apache.log4j.WriterAppender)9 CommandLineParser (org.apache.commons.cli.CommandLineParser)7 GnuParser (org.apache.commons.cli.GnuParser)7 ParseException (org.apache.commons.cli.ParseException)7 DailyRollingFileAppender (org.apache.log4j.DailyRollingFileAppender)7 FileInputStream (java.io.FileInputStream)6 Properties (java.util.Properties)6 CommandLine (org.apache.commons.cli.CommandLine)6 Option (org.apache.commons.cli.Option)6 Options (org.apache.commons.cli.Options)6