Skip to content

Commit

Permalink
Introduce the ability to use a custom logger
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Apr 27, 2020
1 parent 5bc09f2 commit 7ee6c7f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
15 changes: 12 additions & 3 deletions core/src/main/java/io/dekorate/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,36 @@ public class Session {
private final AtomicReference<SessionWriter> writer = new AtomicReference<>();
private final Map<Class<? extends SessionListener>, SessionListener> listeners = new HashMap<>();

private final Logger LOGGER = LoggerFactory.getLogger();
private final Logger LOGGER;

/**
* Creates or reuses a single instance of Session.
* @return The Session.
*/
public static Session getSession() {
return getSession(LoggerFactory.getLogger());
}

/**
* Creates or reuses a single instance of Session.
* @return The Session.
*/
public static Session getSession(Logger logger) {
if (INSTANCE != null) {
return INSTANCE;
}
synchronized (Session.class) {
if (INSTANCE == null) {
INSTANCE = new Session();
INSTANCE = new Session(logger);
INSTANCE.loadHandlers();
INSTANCE.loadGenerators();
}
}
return INSTANCE;
}

protected Session() {
protected Session(Logger logger) {
LOGGER = logger;
LOGGER.info("Initializing dekorate session.");
}

Expand Down
29 changes: 29 additions & 0 deletions core/src/main/java/io/dekorate/logger/NoopLogger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.dekorate.logger;

import io.dekorate.Logger;

/**
* Used to suppress logging completely
*/
public class NoopLogger implements Logger {

@Override
public void debug(String message) {

}

@Override
public void info(String message) {

}

@Override
public void warning(String message) {

}

@Override
public void error(String message) {

}
}

0 comments on commit 7ee6c7f

Please sign in to comment.