mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
feat: support OmsStdOutLogger
This commit is contained in:
parent
cded964bcd
commit
7feb25cf8a
@ -33,6 +33,7 @@ public class LogConfig {
|
||||
public enum LogType {
|
||||
ONLINE(1),
|
||||
LOCAL(2),
|
||||
STDOUT(3),
|
||||
|
||||
NULL(999);
|
||||
private final Integer v;
|
||||
|
@ -7,6 +7,7 @@ import tech.powerjob.worker.common.WorkerRuntime;
|
||||
import tech.powerjob.worker.log.impl.OmsLocalLogger;
|
||||
import tech.powerjob.worker.log.impl.OmsNullLogger;
|
||||
import tech.powerjob.worker.log.impl.OmsServerLogger;
|
||||
import tech.powerjob.worker.log.impl.OmsStdOutLogger;
|
||||
|
||||
/**
|
||||
* OmsLoggerFactory
|
||||
@ -31,6 +32,8 @@ public class OmsLoggerFactory {
|
||||
switch (LogConfig.LogType.of(cfg.getType())) {
|
||||
case LOCAL:
|
||||
return new OmsLocalLogger(cfg);
|
||||
case STDOUT:
|
||||
return new OmsStdOutLogger(cfg);
|
||||
case NULL:
|
||||
return new OmsNullLogger();
|
||||
default:
|
||||
|
@ -1,5 +1,8 @@
|
||||
package tech.powerjob.worker.log.impl;
|
||||
|
||||
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.model.LogConfig;
|
||||
import tech.powerjob.worker.log.OmsLogger;
|
||||
@ -65,4 +68,21 @@ public abstract class AbstractOmsLogger implements OmsLogger {
|
||||
}
|
||||
error0(messagePattern, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成日志内容
|
||||
* @param messagePattern 日志格式
|
||||
* @param arg 填充参数
|
||||
* @return 生成完毕的日志内容
|
||||
*/
|
||||
protected static String genLogContent(String messagePattern, Object... arg) {
|
||||
// 借用 Slf4J 直接生成日志信息
|
||||
FormattingTuple formattingTuple = MessageFormatter.arrayFormat(messagePattern, arg);
|
||||
if (formattingTuple.getThrowable() != null) {
|
||||
String stackTrace = ExceptionUtils.getStackTrace(formattingTuple.getThrowable());
|
||||
return formattingTuple.getMessage() + System.lineSeparator() + stackTrace;
|
||||
}else {
|
||||
return formattingTuple.getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import org.slf4j.LoggerFactory;
|
||||
import tech.powerjob.common.model.LogConfig;
|
||||
|
||||
/**
|
||||
* More user feedback when the task volume server timeout serious. After pressure testing, we found that there is no bottleneck in the server processing scheduling tasks, and it is assumed that the large amount of logs is causing a serious bottleneck. Therefore, we need to provide local logging API for large MR tasks.
|
||||
* Many user feedback when the task volume server timeout serious. After pressure testing, we found that there is no bottleneck in the server processing scheduling tasks, and it is assumed that the large amount of logs is causing a serious bottleneck. Therefore, we need to provide local logging API for large MR tasks.
|
||||
*
|
||||
* @author tjq
|
||||
* @since 2021/2/4
|
||||
|
@ -3,9 +3,6 @@ package tech.powerjob.worker.log.impl;
|
||||
import tech.powerjob.common.enums.LogLevel;
|
||||
import tech.powerjob.common.model.LogConfig;
|
||||
import tech.powerjob.worker.background.OmsLogHandler;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
import org.slf4j.helpers.FormattingTuple;
|
||||
import org.slf4j.helpers.MessageFormatter;
|
||||
|
||||
|
||||
/**
|
||||
@ -47,23 +44,6 @@ public class OmsServerLogger extends AbstractOmsLogger {
|
||||
process(LogLevel.ERROR, messagePattern, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成日志内容
|
||||
* @param messagePattern 日志格式
|
||||
* @param arg 填充参数
|
||||
* @return 生成完毕的日志内容
|
||||
*/
|
||||
private static String genLogContent(String messagePattern, Object... arg) {
|
||||
// 借用 Slf4J 直接生成日志信息
|
||||
FormattingTuple formattingTuple = MessageFormatter.arrayFormat(messagePattern, arg);
|
||||
if (formattingTuple.getThrowable() != null) {
|
||||
String stackTrace = ExceptionUtils.getStackTrace(formattingTuple.getThrowable());
|
||||
return formattingTuple.getMessage() + System.lineSeparator() + stackTrace;
|
||||
}else {
|
||||
return formattingTuple.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
private void process(LogLevel level, String messagePattern, Object... args) {
|
||||
String logContent = genLogContent(messagePattern, args);
|
||||
omsLogHandler.submitLog(instanceId, level, logContent);
|
||||
|
@ -0,0 +1,41 @@
|
||||
package tech.powerjob.worker.log.impl;
|
||||
|
||||
import tech.powerjob.common.enums.LogLevel;
|
||||
import tech.powerjob.common.model.LogConfig;
|
||||
|
||||
/**
|
||||
* use java.lang.System#out or java.lang.System#err to print log info
|
||||
*
|
||||
* @author tjq
|
||||
* @since 2022/10/3
|
||||
*/
|
||||
public class OmsStdOutLogger extends AbstractOmsLogger {
|
||||
|
||||
public OmsStdOutLogger(LogConfig logConfig) {
|
||||
super(logConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
void debug0(String messagePattern, Object... args) {
|
||||
System.out.println(buildStdOut(LogLevel.DEBUG, messagePattern, args));
|
||||
}
|
||||
|
||||
@Override
|
||||
void info0(String messagePattern, Object... args) {
|
||||
System.out.println(buildStdOut(LogLevel.INFO, messagePattern, args));
|
||||
}
|
||||
|
||||
@Override
|
||||
void warn0(String messagePattern, Object... args) {
|
||||
System.out.println(buildStdOut(LogLevel.WARN, messagePattern, args));
|
||||
}
|
||||
|
||||
@Override
|
||||
void error0(String messagePattern, Object... args) {
|
||||
System.err.println(buildStdOut(LogLevel.ERROR, messagePattern, args));
|
||||
}
|
||||
|
||||
private static String buildStdOut(LogLevel logLevel, String messagePattern, Object... args) {
|
||||
return logLevel.name().concat("-").concat(genLogContent(messagePattern, args));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user