-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Abstracted logger to fall back to native if Log4J isn't present
- Loading branch information
1 parent
c1805b9
commit 5e3315c
Showing
6 changed files
with
89 additions
and
3 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
plugins { | ||
id 'java' | ||
id "com.github.johnrengelman.shadow" version "8.1.1" apply false | ||
} | ||
|
||
subprojects { | ||
|
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
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
8 changes: 8 additions & 0 deletions
8
core/src/main/java/io/dogboy/serializationisbad/core/logger/ILogger.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 io.dogboy.serializationisbad.core.logger; | ||
|
||
public interface ILogger { | ||
void debug(String message); | ||
void info(String message); | ||
void warn(String message); | ||
void error(String message, Throwable throwable); | ||
} |
31 changes: 31 additions & 0 deletions
31
core/src/main/java/io/dogboy/serializationisbad/core/logger/Log4JLogger.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,31 @@ | ||
package io.dogboy.serializationisbad.core.logger; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
public class Log4JLogger implements ILogger { | ||
private final Logger logger; | ||
|
||
public Log4JLogger(String name) { | ||
this.logger = LogManager.getLogger(name); | ||
} | ||
@Override | ||
public void debug(String message) { | ||
logger.debug(message); | ||
} | ||
|
||
@Override | ||
public void info(String message) { | ||
logger.info(message); | ||
} | ||
|
||
@Override | ||
public void warn(String message) { | ||
logger.warn(message); | ||
} | ||
|
||
@Override | ||
public void error(String message, Throwable throwable) { | ||
logger.error(message, throwable); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
core/src/main/java/io/dogboy/serializationisbad/core/logger/NativeLogger.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,32 @@ | ||
package io.dogboy.serializationisbad.core.logger; | ||
|
||
import java.util.logging.Logger; | ||
|
||
public class NativeLogger implements ILogger { | ||
private final Logger logger; | ||
|
||
public NativeLogger(String name) { | ||
this.logger = Logger.getLogger(name); | ||
} | ||
|
||
@Override | ||
public void debug(String message) { | ||
logger.finest(message); | ||
} | ||
|
||
@Override | ||
public void info(String message) { | ||
logger.info(message); | ||
} | ||
|
||
@Override | ||
public void warn(String message) { | ||
logger.warning(message); | ||
} | ||
|
||
@Override | ||
public void error(String message, Throwable throwable) { | ||
logger.severe(message); | ||
throwable.printStackTrace(); | ||
} | ||
} |