-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d2b07d
commit ddf73fe
Showing
16 changed files
with
1,659 additions
and
15 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
85 changes: 85 additions & 0 deletions
85
cffu-core/src/main/java/io/foldright/cffu/logger/ConfigReportException.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,85 @@ | ||
package io.foldright.cffu.logger; | ||
|
||
import edu.umd.cs.findbugs.annotations.Nullable; | ||
import io.foldright.cffu.logger.jdk.JdkLoggerAdapter; | ||
import io.foldright.cffu.logger.log4j.Log4jLoggerAdapter; | ||
import io.foldright.cffu.logger.log4j2.Log4j2LoggerAdapter; | ||
import io.foldright.cffu.logger.slf4j.Slf4jLoggerAdapter; | ||
|
||
|
||
public class ConfigReportException { | ||
|
||
private static Logger logger; | ||
|
||
/** | ||
* cffu.uncaught.exception.report=none | oneline | short(default) | full | ||
* corresponding system print|error|warn|info | ||
* @param msg | ||
* @param ex | ||
* @param <T> | ||
* @return | ||
*/ | ||
@Nullable | ||
@SuppressWarnings("SameReturnValue") | ||
public static <T> T reportException(String msg, Throwable ex) { | ||
|
||
String loggerLevel = System.getProperty("cffu.uncaught.exception.report.log.level", "none"); | ||
switch (loggerLevel){ | ||
case "warn": | ||
logger.warn(msg, ex); | ||
break; | ||
case "info": | ||
logger.info(msg, ex); | ||
break; | ||
case "error": | ||
logger.error(msg, ex); | ||
break; | ||
case "none": | ||
default: | ||
//no handle | ||
break; | ||
} | ||
return null; | ||
} | ||
|
||
static { | ||
String appLogger = System.getProperty("cffu.uncaught.exception.report.log.type", "none"); | ||
LoggerAdapter loggerAdapter; | ||
switch (appLogger){ | ||
case "log4j": | ||
loggerAdapter = new Log4jLoggerAdapter(); | ||
break; | ||
case "log4j2": | ||
loggerAdapter = new Log4j2LoggerAdapter(); | ||
break; | ||
case "slf4j": | ||
loggerAdapter = new Slf4jLoggerAdapter(); | ||
break; | ||
case "none": | ||
default: | ||
loggerAdapter = new JdkLoggerAdapter(); | ||
break; | ||
} | ||
logger = loggerAdapter.getLogger(ConfigReportException.class.getName()); | ||
|
||
String loggerLevel = System.getProperty("cffu.uncaught.exception.report.log.level", "none"); | ||
switch (loggerLevel){ | ||
case "warn": | ||
loggerAdapter.setLevel(Level.WARN); | ||
break; | ||
case "info": | ||
loggerAdapter.setLevel(Level.INFO); | ||
break; | ||
case "error": | ||
loggerAdapter.setLevel(Level.ERROR); | ||
break; | ||
case "none": | ||
default: | ||
loggerAdapter.setLevel(Level.OFF); | ||
//no handle | ||
break; | ||
} | ||
|
||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
cffu-core/src/main/java/io/foldright/cffu/logger/Level.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,43 @@ | ||
|
||
package io.foldright.cffu.logger; | ||
|
||
/** | ||
* Level | ||
*/ | ||
public enum Level { | ||
|
||
/** | ||
* ALL | ||
*/ | ||
ALL, | ||
|
||
/** | ||
* TRACE | ||
*/ | ||
TRACE, | ||
|
||
/** | ||
* DEBUG | ||
*/ | ||
DEBUG, | ||
|
||
/** | ||
* INFO | ||
*/ | ||
INFO, | ||
|
||
/** | ||
* WARN | ||
*/ | ||
WARN, | ||
|
||
/** | ||
* ERROR | ||
*/ | ||
ERROR, | ||
|
||
/** | ||
* OFF | ||
*/ | ||
OFF | ||
} |
Oops, something went wrong.