Browse Source

改成枚举

bugfix/10.0
zack 6 years ago
parent
commit
7a1d7a8885
  1. 58
      designer-base/src/main/java/com/fr/design/mainframe/loghandler/DesignerLogger.java

58
designer-base/src/main/java/com/fr/design/mainframe/loghandler/DesignerLogger.java

@ -17,20 +17,66 @@ public class DesignerLogger {
/**
* 记录LoggingEvent对象
*
* @param event
*/
public static void log(LoggingEvent event) {
if (event == null) {
return;
}
int intLevel = event.getLevel().toInt();
ThrowableInformation information = event.getThrowableInformation();
if (intLevel == INFO_INT) {
LogParser.parse(event).log(event);
}
public enum LogParser {
DEFAULT(-1) {
@Override
public void log(LoggingEvent event) {
}
},
INFO(Level.INFO.toInt()) {
@Override
public void log(LoggingEvent event) {
FineLoggerFactory.getLogger().info(event.getRenderedMessage());
} else if (intLevel == ERROR_INT) {
FineLoggerFactory.getLogger().error(event.getRenderedMessage(), information == null ? null : information.getThrowable());
} else if (intLevel == WARN_INT) {
}
},
WARN(Level.WARN.toInt()) {
@Override
public void log(LoggingEvent event) {
ThrowableInformation information = event.getThrowableInformation();
FineLoggerFactory.getLogger().warn(event.getRenderedMessage(), information == null ? null : information.getThrowable());
}
},
ERROR(Level.ERROR.toInt()) {
@Override
public void log(LoggingEvent event) {
ThrowableInformation information = event.getThrowableInformation();
FineLoggerFactory.getLogger().error(event.getRenderedMessage(), information == null ? null : information.getThrowable());
}
};
private int level;
LogParser(int level) {
this.level = level;
}
public int getLevel() {
return level;
}
public static LogParser parse(LoggingEvent event) {
int intLevel = event.getLevel().toInt();
for (LogParser logParser : values()) {
if (logParser.getLevel() == intLevel) {
return logParser;
}
}
return DEFAULT;
}
public void log(LoggingEvent event) {
}
}
}
Loading…
Cancel
Save