Skip to content

Commit

Permalink
for 'logback.statusListenerClass' system property add STDOUT as a sho…
Browse files Browse the repository at this point in the history
…rthand for ch.qos.logback.core.status.OnConsoleStatusListener

Signed-off-by: Ceki Gulcu <ceki@qos.ch>
  • Loading branch information
ceki committed Jul 11, 2023
1 parent 1caf36d commit b331f63
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class ContextInitializer {
* @deprecated Please use ClassicConstants.CONFIG_FILE_PROPERTY instead
*/
final public static String CONFIG_FILE_PROPERTY = ClassicConstants.CONFIG_FILE_PROPERTY;
private static final String JORAN_CONFIGURATION_DURATION_MSG = "JoranConfiguration duration ";
private static final String CONFIGURATION_AS_A_SERVICE_DURATION_MSG = "Configuration as a service duration ";

final LoggerContext loggerContext;

Expand Down Expand Up @@ -76,7 +78,7 @@ public void autoConfig(ClassLoader classLoader) throws JoranException {
c.setContext(loggerContext);
Configurator.ExecutionStatus status = c.configure(loggerContext);
if (status == Configurator.ExecutionStatus.DO_NOT_INVOKE_NEXT_IF_ANY) {
printDuration(startConfigurationAsAService, "Configuration as a service duration ", true);
printDuration(startConfigurationAsAService, CONFIGURATION_AS_A_SERVICE_DURATION_MSG, true);
return;
}
} catch (Exception e) {
Expand All @@ -85,16 +87,16 @@ public void autoConfig(ClassLoader classLoader) throws JoranException {
}
}

printDuration(startConfigurationAsAService, "Configuration as a service duration ", false);
printDuration(startConfigurationAsAService, CONFIGURATION_AS_A_SERVICE_DURATION_MSG, false);

long startJoranConfiguration = System.currentTimeMillis();
Configurator.ExecutionStatus es = attemptConfigurationUsingJoranUsingReflexion(classLoader);

if (es == Configurator.ExecutionStatus.DO_NOT_INVOKE_NEXT_IF_ANY) {
printDuration(startJoranConfiguration, "JoranConfiguration duration", true);
printDuration(startJoranConfiguration, JORAN_CONFIGURATION_DURATION_MSG, true);
return;
}
printDuration(startJoranConfiguration, "JoranConfiguration duration", false);
printDuration(startJoranConfiguration, JORAN_CONFIGURATION_DURATION_MSG, false);

// at this stage invoke basicConfigurator
fallbackOnToBasicConfigurator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class CoreConstants {
final public static String STATUS_LISTENER_CLASS_KEY = "logback.statusListenerClass";
final public static String SYSOUT = "SYSOUT";

final public static String STDOUT = "STDOUT";

/**
* Number of idle threads to retain in a context's executor service.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
import ch.qos.logback.core.spi.ContextAware;
import ch.qos.logback.core.spi.LifeCycle;
import ch.qos.logback.core.status.OnConsoleStatusListener;
import ch.qos.logback.core.status.OnErrorConsoleStatusListener;
import ch.qos.logback.core.status.StatusListener;

import static ch.qos.logback.core.CoreConstants.STDOUT;
import static ch.qos.logback.core.CoreConstants.SYSOUT;

public class StatusListenerConfigHelper {

public static void installIfAsked(Context context) {
Expand All @@ -31,7 +35,7 @@ public static void installIfAsked(Context context) {

private static void addStatusListener(Context context, String listenerClassName) {
StatusListener listener = null;
if (CoreConstants.SYSOUT.equalsIgnoreCase(listenerClassName)) {
if (SYSOUT.equalsIgnoreCase(listenerClassName) || STDOUT.equalsIgnoreCase(listenerClassName)) {
listener = new OnConsoleStatusListener();
} else {
listener = createListenerPerClassName(context, listenerClassName);
Expand Down

0 comments on commit b331f63

Please sign in to comment.