Skip to content

Commit

Permalink
Redirect logs to stderr during app bootstrap (#5206) [ci fast]
Browse files Browse the repository at this point in the history

Signed-off-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
pditommaso authored Oct 8, 2024
1 parent e794e86 commit 9491810
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ class Launcher {
* @param args The program options as specified by the user on the CLI
*/
static void main(String... args) {
LoggerHelper.bootstrapLogger()
final status = new Launcher() .command(args) .run()
if( status )
System.exit(status)
Expand Down
30 changes: 30 additions & 0 deletions modules/nextflow/src/main/groovy/nextflow/util/LoggerHelper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,36 @@ class LoggerHelper {
INSTANCE.setQuiet0(quiet)
}

/**
* Setup a minimal logger that redirect log events to stderr only used during app bootstrap
*/
static void bootstrapLogger() {
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();

// Reset the logger context (this clears any existing loggers)
context.reset();

// Create a console appender that writes to stderr
final consoleAppender = new ConsoleAppender<ILoggingEvent>();
consoleAppender.setContext(context);
consoleAppender.setTarget("System.err");

// Set a simple pattern for the log output
final encoder = new PatternLayoutEncoder();
encoder.setContext(context);
encoder.setPattern("%d{HH:mm:ss.SSS} %-5level - %msg%n");
encoder.start();

// Attach the encoder to the appender
consoleAppender.setEncoder(encoder);
consoleAppender.start();

// Get the root logger and set its level to DEBUG
Logger rootLogger = context.getLogger(Logger.ROOT_LOGGER_NAME);
rootLogger.addAppender(consoleAppender)
rootLogger.setLevel(Level.DEBUG)
}

/*
* Filters the logging event based on the level assigned to a specific 'package'
*/
Expand Down

0 comments on commit 9491810

Please sign in to comment.