Browse Source

改成枚举

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

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

@ -17,20 +17,66 @@ public class DesignerLogger {
/** /**
* 记录LoggingEvent对象 * 记录LoggingEvent对象
*
* @param event * @param event
*/ */
public static void log(LoggingEvent event) { public static void log(LoggingEvent event) {
if (event == null) { if (event == null) {
return; return;
} }
int intLevel = event.getLevel().toInt(); LogParser.parse(event).log(event);
ThrowableInformation information = event.getThrowableInformation(); }
if (intLevel == INFO_INT) {
FineLoggerFactory.getLogger().info(event.getRenderedMessage()); public enum LogParser {
} else if (intLevel == ERROR_INT) { DEFAULT(-1) {
FineLoggerFactory.getLogger().error(event.getRenderedMessage(), information == null ? null : information.getThrowable()); @Override
} else if (intLevel == WARN_INT) { public void log(LoggingEvent event) {
FineLoggerFactory.getLogger().warn(event.getRenderedMessage(), information == null ? null : information.getThrowable());
}
},
INFO(Level.INFO.toInt()) {
@Override
public void log(LoggingEvent event) {
FineLoggerFactory.getLogger().info(event.getRenderedMessage());
}
},
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