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);
}
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);
}
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;
}
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);
}
}
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;
}
Aggregations