This repository has been archived by the owner on Jun 7, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
4638d03
commit 372d3b6
Showing
18 changed files
with
585 additions
and
129 deletions.
There are no files selected for viewing
124 changes: 0 additions & 124 deletions
124
bootstrap/src/main/java/org/wildfly/swarm/bootstrap/BootstrapLogger.java
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
bootstrap/src/main/java/org/wildfly/swarm/bootstrap/logging/BackingLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
bootstrap/src/main/java/org/wildfly/swarm/bootstrap/logging/BackingLoggerManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.wildfly.swarm.bootstrap.logging; | ||
|
||
/** | ||
* @author Bob McWhirter | ||
*/ | ||
public interface BackingLoggerManager { | ||
BackingLogger getBackingLogger(String name); | ||
} |
117 changes: 117 additions & 0 deletions
117
bootstrap/src/main/java/org/wildfly/swarm/bootstrap/logging/BootstrapLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() + "]"; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
bootstrap/src/main/java/org/wildfly/swarm/bootstrap/logging/InitialBackingLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ); | ||
} | ||
} |
Oops, something went wrong.