mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
feat: define LogType
This commit is contained in:
parent
db7f5855e1
commit
6eb5966e96
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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:
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user