-
-
Notifications
You must be signed in to change notification settings - Fork 997
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ceki Gulcu <[email protected]>
- Loading branch information
Showing
11 changed files
with
180 additions
and
52 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
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
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
121 changes: 121 additions & 0 deletions
121
slf4j-api/src/main/java/org/slf4j/helpers/Reporter.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,121 @@ | ||
package org.slf4j.helpers; | ||
|
||
import java.io.PrintStream; | ||
|
||
/** | ||
* An internally used class for reporting messages generated by SLF4J itself during initialization | ||
* | ||
* @since 2.0.10 | ||
*/ | ||
public class Reporter { | ||
|
||
/** | ||
* this class is used internally by Reporter | ||
*/ | ||
private enum Level { | ||
INFO(1), WARN(2), ERROR(3); | ||
|
||
int levelInt; | ||
|
||
private Level(int levelInt) { | ||
this.levelInt = levelInt; | ||
} | ||
|
||
private int getLevelInt() { | ||
return levelInt; | ||
} | ||
} | ||
|
||
private enum TargetChoice { | ||
Stderr, Stdout; | ||
} | ||
|
||
static final String SLF4J_INFO_PREFIX = "SLF4J(I): "; | ||
static final String SLF4J_WARN_PREFIX = "SLF4J(W): "; | ||
static final String SLF4J_ERROR_PREFIX = "SLF4J(E): "; | ||
|
||
|
||
/** | ||
* Acceptable values are s "System.out", "stdout", "sysout", "System.err", "stderr" and "syserr". | ||
*/ | ||
public static final String SLF4J_REPORT_TARGET_KEY = "slf4j.reportStream"; | ||
|
||
|
||
public static final String SLF4J_VERBOSITY_KEY = "slf4j.verbosity"; | ||
static private final String[] SYSOUT_KEYS = {"System.out", "stdout", "sysout"}; | ||
|
||
static private final TargetChoice TARGET_CHOICE = initTargetChoice(); | ||
|
||
static private final Level VERBOSITY = initVerbosity(); | ||
|
||
static private TargetChoice initTargetChoice() { | ||
String reportStreamStr = System.getProperty(SLF4J_REPORT_TARGET_KEY); | ||
|
||
if(reportStreamStr == null || reportStreamStr.isEmpty()) { | ||
return TargetChoice.Stderr; | ||
} | ||
|
||
for(String s : SYSOUT_KEYS) { | ||
if(s.equalsIgnoreCase(reportStreamStr)) | ||
return TargetChoice.Stdout; | ||
} | ||
return TargetChoice.Stderr; | ||
} | ||
|
||
|
||
static private Level initVerbosity() { | ||
String verbosityStr = System.getProperty(SLF4J_VERBOSITY_KEY); | ||
|
||
if(verbosityStr == null || verbosityStr.isEmpty()) { | ||
return Level.INFO; | ||
} | ||
|
||
if(verbosityStr.equalsIgnoreCase("ERROR")) { | ||
return Level.ERROR; | ||
} | ||
|
||
|
||
if(verbosityStr.equalsIgnoreCase("WARN")) { | ||
return Level.WARN; | ||
} | ||
|
||
return Level.INFO; | ||
} | ||
|
||
static boolean isEnabledFor(Level level) { | ||
return (level.levelInt >= VERBOSITY.levelInt); | ||
} | ||
|
||
static private PrintStream getTarget() { | ||
switch(TARGET_CHOICE) { | ||
case Stdout: return System.out; | ||
case Stderr: | ||
default: return System.err; | ||
} | ||
} | ||
|
||
public static void info(String msg) { | ||
if(isEnabledFor(Level.INFO)) { | ||
getTarget().println(SLF4J_INFO_PREFIX + msg); | ||
} | ||
} | ||
|
||
static final public void warn(String msg) { | ||
if(isEnabledFor(Level.WARN)) { | ||
getTarget().println(SLF4J_WARN_PREFIX + msg); | ||
} | ||
} | ||
|
||
static final public void error(String msg, Throwable t) { | ||
// error cannot be disabled | ||
getTarget().println(SLF4J_ERROR_PREFIX + msg); | ||
getTarget().println(SLF4J_ERROR_PREFIX + "Reported exception:"); | ||
t.printStackTrace( getTarget()); | ||
} | ||
|
||
|
||
static final public void error(String msg) { | ||
// error cannot be disabled | ||
getTarget().println(SLF4J_ERROR_PREFIX + msg); | ||
} | ||
} |
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
Oops, something went wrong.