feat: define LogType

This commit is contained in:
tjq 2022-10-03 14:53:51 +08:00
parent db7f5855e1
commit 6eb5966e96
4 changed files with 40 additions and 26 deletions

View File

@ -0,0 +1,35 @@
package tech.powerjob.common.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* description
*
* @author tjq
* @since 2022/10/3
*/
@Getter
@AllArgsConstructor
public enum LogType {
ONLINE(1),
LOCAL(2),
STDOUT(3),
NULL(999);
private final Integer v;
public static LogType of(Integer type) {
if (type == null) {
return ONLINE;
}
for (LogType logType : values()) {
if (logType.v.equals(type)) {
return logType;
}
}
return ONLINE;
}
}

View File

@ -18,7 +18,7 @@ import lombok.experimental.Accessors;
@Accessors(chain = true)
public class LogConfig {
/**
* log type {@link LogType}
* log type {@link tech.powerjob.common.enums.LogType}
*/
private Integer type;
/**
@ -28,28 +28,5 @@ public class LogConfig {
private String loggerName;
@Getter
@AllArgsConstructor
public enum LogType {
ONLINE(1),
LOCAL(2),
STDOUT(3),
NULL(999);
private final Integer v;
public static LogType of(Integer type) {
if (type == null) {
return ONLINE;
}
for (LogType logType : values()) {
if (logType.v.equals(type)) {
return logType;
}
}
return ONLINE;
}
}
}

View File

@ -1,6 +1,7 @@
package tech.powerjob.worker.log;
import org.apache.commons.lang3.StringUtils;
import tech.powerjob.common.enums.LogType;
import tech.powerjob.common.model.LogConfig;
import tech.powerjob.common.serialize.JsonUtils;
import tech.powerjob.worker.common.WorkerRuntime;
@ -29,7 +30,7 @@ public class OmsLoggerFactory {
}
}
switch (LogConfig.LogType.of(cfg.getType())) {
switch (LogType.of(cfg.getType())) {
case LOCAL:
return new OmsLocalLogger(cfg);
case STDOUT:

View File

@ -4,6 +4,7 @@ import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.helpers.FormattingTuple;
import org.slf4j.helpers.MessageFormatter;
import tech.powerjob.common.enums.LogLevel;
import tech.powerjob.common.enums.LogType;
import tech.powerjob.common.model.LogConfig;
import tech.powerjob.worker.log.OmsLogger;
@ -25,7 +26,7 @@ public abstract class AbstractOmsLogger implements OmsLogger {
logConfig.setLevel(LogLevel.INFO.getV());
}
if (logConfig.getType() == null) {
logConfig.setType(LogConfig.LogType.ONLINE.getV());
logConfig.setType(LogType.ONLINE.getV());
}
}