Search in sources :

Example 1 with FileHandler

use of org.jboss.logmanager.handlers.FileHandler in project wildfly-core by wildfly.

the class JulStandaloneTestCase method configureLogManager.

@Before
public void configureLogManager() throws Exception {
    final PatternFormatter formatter = new PatternFormatter("[jul] %d{HH:mm:ss,SSS} %-5p [%c] %s%e%n");
    final Path logFile = Environment.LOG_DIR.resolve("test-standalone-jul.log");
    // We will use a JBoss File handler here for convenience
    final FileHandler handler = new FileHandler(formatter, logFile.toFile(), false);
    handler.setAutoFlush(true);
    currentHandler = handler;
    Logger.getLogger("").addHandler(handler);
}
Also used : Path(java.nio.file.Path) PatternFormatter(org.jboss.logmanager.formatters.PatternFormatter) FileHandler(org.jboss.logmanager.handlers.FileHandler) Before(org.junit.Before)

Example 2 with FileHandler

use of org.jboss.logmanager.handlers.FileHandler in project wildfly-core by wildfly.

the class JulHostControllerTestCase method configureLogManager.

@Before
public void configureLogManager() throws Exception {
    final PatternFormatter formatter = new PatternFormatter("[jul] %d{HH:mm:ss,SSS} %-5p [%c] %s%e%n");
    final Path logFile = Environment.LOG_DIR.resolve("test-hc-jul.log");
    // We will use a JBoss File handler here for convenience
    final FileHandler handler = new FileHandler(formatter, logFile.toFile(), false);
    handler.setAutoFlush(true);
    currentHandler = handler;
    Logger.getLogger("").addHandler(handler);
}
Also used : Path(java.nio.file.Path) PatternFormatter(org.jboss.logmanager.formatters.PatternFormatter) FileHandler(org.jboss.logmanager.handlers.FileHandler) Before(org.junit.Before)

Example 3 with FileHandler

use of org.jboss.logmanager.handlers.FileHandler in project quarkus by quarkusio.

the class LoggingSetupRecorder method createNamedHandlers.

private static Map<String, Handler> createNamedHandlers(LogConfig config, ConsoleRuntimeConfig consoleRuntimeConfig, List<RuntimeValue<Optional<Formatter>>> possibleFormatters, ErrorManager errorManager, LogCleanupFilter cleanupFilter, LaunchMode launchMode) {
    Map<String, Handler> namedHandlers = new HashMap<>();
    for (Entry<String, ConsoleConfig> consoleConfigEntry : config.consoleHandlers.entrySet()) {
        ConsoleConfig namedConsoleConfig = consoleConfigEntry.getValue();
        if (!namedConsoleConfig.enable) {
            continue;
        }
        final Handler consoleHandler = configureConsoleHandler(namedConsoleConfig, consoleRuntimeConfig, errorManager, cleanupFilter, possibleFormatters, null, launchMode);
        addToNamedHandlers(namedHandlers, consoleHandler, consoleConfigEntry.getKey());
    }
    for (Entry<String, FileConfig> fileConfigEntry : config.fileHandlers.entrySet()) {
        FileConfig namedFileConfig = fileConfigEntry.getValue();
        if (!namedFileConfig.enable) {
            continue;
        }
        final Handler fileHandler = configureFileHandler(namedFileConfig, errorManager, cleanupFilter);
        addToNamedHandlers(namedHandlers, fileHandler, fileConfigEntry.getKey());
    }
    for (Entry<String, SyslogConfig> sysLogConfigEntry : config.syslogHandlers.entrySet()) {
        SyslogConfig namedSyslogConfig = sysLogConfigEntry.getValue();
        if (!namedSyslogConfig.enable) {
            continue;
        }
        final Handler syslogHandler = configureSyslogHandler(namedSyslogConfig, errorManager, cleanupFilter);
        if (syslogHandler != null) {
            addToNamedHandlers(namedHandlers, syslogHandler, sysLogConfigEntry.getKey());
        }
    }
    return namedHandlers;
}
Also used : HashMap(java.util.HashMap) SyslogHandler(org.jboss.logmanager.handlers.SyslogHandler) FileHandler(org.jboss.logmanager.handlers.FileHandler) PeriodicSizeRotatingFileHandler(org.jboss.logmanager.handlers.PeriodicSizeRotatingFileHandler) ConsoleHandler(org.jboss.logmanager.handlers.ConsoleHandler) SizeRotatingFileHandler(org.jboss.logmanager.handlers.SizeRotatingFileHandler) Handler(java.util.logging.Handler) AsyncHandler(org.jboss.logmanager.handlers.AsyncHandler)

Example 4 with FileHandler

use of org.jboss.logmanager.handlers.FileHandler in project quarkus-test-framework by quarkus-qe.

the class Log method configure.

public static void configure(ScenarioContext scenario) {
    // Configure Log Manager
    try (InputStream in = QuarkusScenarioBootstrap.class.getResourceAsStream("/logging.properties")) {
        LogManager.getLogManager().readConfiguration(in);
    } catch (IOException e) {
    // ignore
    }
    String logPattern = LOG_FORMAT.get();
    Level level = Level.parse(LOG_LEVEL.get());
    // Configure logger handlers
    Logger logger = LogManager.getLogManager().getLogger("");
    logger.setLevel(level);
    // - Console
    ConsoleHandler console = new ConsoleHandler(ConsoleHandler.Target.SYSTEM_OUT, NOCOLOR ? new PatternFormatter(logPattern) : new ColorPatternFormatter(logPattern));
    console.setLevel(level);
    logger.addHandler(console);
    // - File
    try {
        FileHandler file = new FileHandler(new PatternFormatter(logPattern), scenario.getLogFile().toFile());
        file.setLevel(level);
        logger.addHandler(file);
    } catch (Exception ex) {
        Log.warn("Could not configure file handler. Caused by " + ex);
    }
}
Also used : InputStream(java.io.InputStream) ColorPatternFormatter(org.jboss.logmanager.formatters.ColorPatternFormatter) Level(java.util.logging.Level) PatternFormatter(org.jboss.logmanager.formatters.PatternFormatter) ColorPatternFormatter(org.jboss.logmanager.formatters.ColorPatternFormatter) IOException(java.io.IOException) Logger(java.util.logging.Logger) ConsoleHandler(org.jboss.logmanager.handlers.ConsoleHandler) IOException(java.io.IOException) FileHandler(org.jboss.logmanager.handlers.FileHandler)

Example 5 with FileHandler

use of org.jboss.logmanager.handlers.FileHandler in project quarkus by quarkusio.

the class LoggingSetupRecorder method configureFileHandler.

private static Handler configureFileHandler(final FileConfig config, final ErrorManager errorManager, final LogCleanupFilter cleanupFilter) {
    FileHandler handler;
    FileConfig.RotationConfig rotationConfig = config.rotation;
    if (rotationConfig.fileSuffix.isPresent()) {
        PeriodicSizeRotatingFileHandler periodicSizeRotatingFileHandler = new PeriodicSizeRotatingFileHandler();
        periodicSizeRotatingFileHandler.setSuffix(rotationConfig.fileSuffix.get());
        periodicSizeRotatingFileHandler.setRotateSize(rotationConfig.maxFileSize.asLongValue());
        periodicSizeRotatingFileHandler.setRotateOnBoot(rotationConfig.rotateOnBoot);
        periodicSizeRotatingFileHandler.setMaxBackupIndex(rotationConfig.maxBackupIndex);
        handler = periodicSizeRotatingFileHandler;
    } else {
        SizeRotatingFileHandler sizeRotatingFileHandler = new SizeRotatingFileHandler(rotationConfig.maxFileSize.asLongValue(), rotationConfig.maxBackupIndex);
        sizeRotatingFileHandler.setRotateOnBoot(rotationConfig.rotateOnBoot);
        handler = sizeRotatingFileHandler;
    }
    final PatternFormatter formatter = new PatternFormatter(config.format);
    handler.setFormatter(formatter);
    handler.setAppend(true);
    try {
        handler.setFile(config.path);
    } catch (FileNotFoundException e) {
        errorManager.error("Failed to set log file", e, ErrorManager.OPEN_FAILURE);
    }
    handler.setErrorManager(errorManager);
    handler.setLevel(config.level);
    handler.setFilter(cleanupFilter);
    if (config.async.enable) {
        return createAsyncHandler(config.async, config.level, handler);
    }
    return handler;
}
Also used : PeriodicSizeRotatingFileHandler(org.jboss.logmanager.handlers.PeriodicSizeRotatingFileHandler) FileNotFoundException(java.io.FileNotFoundException) PatternFormatter(org.jboss.logmanager.formatters.PatternFormatter) ColorPatternFormatter(org.jboss.logmanager.formatters.ColorPatternFormatter) FileHandler(org.jboss.logmanager.handlers.FileHandler) PeriodicSizeRotatingFileHandler(org.jboss.logmanager.handlers.PeriodicSizeRotatingFileHandler) SizeRotatingFileHandler(org.jboss.logmanager.handlers.SizeRotatingFileHandler) PeriodicSizeRotatingFileHandler(org.jboss.logmanager.handlers.PeriodicSizeRotatingFileHandler) SizeRotatingFileHandler(org.jboss.logmanager.handlers.SizeRotatingFileHandler)

Aggregations

FileHandler (org.jboss.logmanager.handlers.FileHandler)6 PatternFormatter (org.jboss.logmanager.formatters.PatternFormatter)4 Path (java.nio.file.Path)2 Handler (java.util.logging.Handler)2 ColorPatternFormatter (org.jboss.logmanager.formatters.ColorPatternFormatter)2 AsyncHandler (org.jboss.logmanager.handlers.AsyncHandler)2 ConsoleHandler (org.jboss.logmanager.handlers.ConsoleHandler)2 PeriodicSizeRotatingFileHandler (org.jboss.logmanager.handlers.PeriodicSizeRotatingFileHandler)2 SizeRotatingFileHandler (org.jboss.logmanager.handlers.SizeRotatingFileHandler)2 Before (org.junit.Before)2 LoggingTestsHelper.getHandler (io.quarkus.logging.LoggingTestsHelper.getHandler)1 QuarkusUnitTest (io.quarkus.test.QuarkusUnitTest)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 Level (java.util.logging.Level)1 Logger (java.util.logging.Logger)1 SyslogHandler (org.jboss.logmanager.handlers.SyslogHandler)1 Test (org.junit.jupiter.api.Test)1