Skip to content
This repository has been archived by the owner on Jun 7, 2021. It is now read-only.

Commit

Permalink
Rework logging.
Browse files Browse the repository at this point in the history
Initially, logging for BootstrapLoggers is configured via properties:

  -Dswarm.log.CATEGORY.NAME=LEVEL

Once JBoss-Logging is installed, those same properties are transferred and merged
with the logging.properties and subsequently through to the logging subsystem configuration
to allow DMR-management of bootstrap loggers.

Additionally, while the bootstrap loggers are initially backed by a simple (needs improvement)
console logger, once JBoss-Logging is installed, they are re-attached to a JBL Logger.
  • Loading branch information
bobmcwhirter committed Dec 28, 2015
1 parent 4638d03 commit 372d3b6
Show file tree
Hide file tree
Showing 18 changed files with 585 additions and 129 deletions.

This file was deleted.

@@ -0,0 +1,21 @@
package org.wildfly.swarm.bootstrap.logging;

/**
* @author Bob McWhirter
*/
public interface BackingLogger {

Object getLevel();

boolean isDebugEnabled();
boolean isTraceEnabled();

void trace(Object message);
void debug(Object message);
void info(Object message);

void warn(Object message);
void error(Object message);
void error(Object message, Throwable t);

}
@@ -0,0 +1,8 @@
package org.wildfly.swarm.bootstrap.logging;

/**
* @author Bob McWhirter
*/
public interface BackingLoggerManager {
BackingLogger getBackingLogger(String name);
}
@@ -0,0 +1,117 @@
package org.wildfly.swarm.bootstrap.logging;

import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.logging.Level;

/**
* @author Bob McWhirter
*/
public class BootstrapLogger {

public enum Level {
NONE(java.util.logging.Level.OFF),
ERROR(java.util.logging.Level.SEVERE),
WARN(java.util.logging.Level.WARNING),
INFO(java.util.logging.Level.INFO),
DEBUG(java.util.logging.Level.FINER),
TRACE(java.util.logging.Level.FINEST ),
ALL(java.util.logging.Level.ALL);

private final java.util.logging.Level jul;

Level(java.util.logging.Level jul) {
this.jul = jul;
}

public java.util.logging.Level toJUL() {
return this.jul;
}
}

private static Map<String,BootstrapLogger> LOGGERS = new HashMap<>();
private static BackingLoggerManager MANAGER = InitialLoggerManager.INSTANCE;
private static Object LOCK = new Object();

private final String name;
private BackingLogger backingLogger;

private BootstrapLogger(String name) {
this.name = name;
}

public static BootstrapLogger logger(String name) {
synchronized ( LOGGERS ) {
BootstrapLogger logger = LOGGERS.get(name);
if ( logger == null ) {
logger = new BootstrapLogger( name );
LOGGERS.put( name, logger );
}
return logger;
}
}

public static void setBackingLoggerManager(BackingLoggerManager manager) {
synchronized ( LOCK ) {
MANAGER = manager;
LOGGERS.values().forEach( BootstrapLogger::resetBackingLogger );
}
}

private BackingLogger getBackingLogger() {
if ( this.backingLogger == null ) {
synchronized ( LOCK ) {
this.backingLogger = MANAGER.getBackingLogger(this.name);
}
}
return this.backingLogger;
}

void resetBackingLogger() {
this.backingLogger = null;
}

public void trace(Object message) {
getBackingLogger().trace(message);
}

public void debug(Object message) {
getBackingLogger().debug(message);
}

public void info(Object message) {
getBackingLogger().info(message);
}

public void warn(Object message) {
getBackingLogger().warn(message);
}

public void error(Object message) {
getBackingLogger().error(message);
}

public void error(Object message, Throwable t) {
getBackingLogger().error(message, t);
}

public Object getLevel() {
return getBackingLogger().getLevel();
}

public boolean isDebugEnabled() {
return getBackingLogger().isDebugEnabled();
}

public boolean isTraceEnabled() {
return getBackingLogger().isTraceEnabled();
}

public String toString() {
return "[" + this.name + ": " + this.getLevel() + "]";
}
}
@@ -0,0 +1,64 @@
package org.wildfly.swarm.bootstrap.logging;

/**
* @author Bob McWhirter
*/
public class InitialBackingLogger implements BackingLogger {

private final String category;
private final BootstrapLogger.Level level;


public InitialBackingLogger(String category, BootstrapLogger.Level level) {
this.category = category;
this.level = level;
}

public String getCategory() {
return this.category;
}

public BootstrapLogger.Level getLevel() {
return this.level;
}

@Override
public boolean isDebugEnabled() {
return this.level.ordinal() >= BootstrapLogger.Level.DEBUG.ordinal();
}

@Override
public boolean isTraceEnabled() {
return this.level.ordinal() >= BootstrapLogger.Level.TRACE.ordinal();
}

@Override
public void trace(Object message) {
InitialLoggerManager.INSTANCE.log( this, BootstrapLogger.Level.TRACE, message );
}

@Override
public void debug(Object message) {
InitialLoggerManager.INSTANCE.log( this, BootstrapLogger.Level.DEBUG, message );
}

@Override
public void info(Object message) {
InitialLoggerManager.INSTANCE.log( this, BootstrapLogger.Level.INFO, message );
}

@Override
public void warn(Object message) {
InitialLoggerManager.INSTANCE.log( this, BootstrapLogger.Level.WARN, message );
}

@Override
public void error(Object message) {
InitialLoggerManager.INSTANCE.log( this, BootstrapLogger.Level.ERROR, message );
}

@Override
public void error(Object message, Throwable t) {
InitialLoggerManager.INSTANCE.log( this, BootstrapLogger.Level.ERROR, message, t );
}
}

0 comments on commit 372d3b6

Please sign in to comment.