com.fastchar.slf4j.FastLog4j2Config Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fastchar-slf4j Show documentation
Show all versions of fastchar-slf4j Show documentation
FastChar-SLF4J is a FastChar plugin.
package com.fastchar.slf4j;
import com.fastchar.core.FastChar;
import com.fastchar.interfaces.IFastConfig;
import com.fastchar.slf4j.log4j2.provider.Log4jProvider;
import com.fastchar.slf4j.log4j2.provider.Log4jSplitInfo;
import com.fastchar.slf4j.log4j2.provider.Log4jLevelEnum;
import java.util.ArrayList;
import java.util.List;
/**
* @author 沈建(Janesen)
* @date 2021/12/25 14:58
*/
public class FastLog4j2Config implements IFastConfig {
public FastLog4j2Config() {
FastChar.getOverrides().add(Log4jProvider.class);
FastChar.getObservable().addObserver(Log4jProvider.class);
if (FastChar.getConstant().isDebug()) {
FastChar.getLog().info("已启用SLF4j日志插件!");
}
}
private boolean enable;
private String logDirectory = "${sys:catalina.home}/logs";
private Log4jLevelEnum rootLevel = Log4jLevelEnum.Error;
private final List logSplits = new ArrayList<>();
public String getLogDirectory() {
return logDirectory;
}
public FastLog4j2Config setLogDirectory(String logDirectory) {
this.logDirectory = logDirectory;
return this;
}
public Log4jLevelEnum getRootLevel() {
return rootLevel;
}
public FastLog4j2Config setRootLevel(Log4jLevelEnum rootLevel) {
this.rootLevel = rootLevel;
return this;
}
public List getLogSplits() {
return logSplits;
}
public boolean isEnable() {
return enable;
}
public FastLog4j2Config setEnable(boolean enable) {
this.enable = enable;
return this;
}
/**
* 添加日志分割配置
*
* @param logFileName 日志文件名
* @param logPattern 需要分割的名匹配
* @return 当前对象
*/
public FastLog4j2Config addLogFile(String logFileName, String logPattern) {
return addLogFile(logFileName, logPattern, "debug");
}
/**
* 添加日志分割配置
*
* @param logFileName 日志文件名
* @param logPattern 需要分割的名匹配
* @param logLevel 日志输出级别 all、debug、info、warn
* @return 当前对象
*/
public FastLog4j2Config addLogFile(String logFileName, String logPattern, String logLevel) {
return addLogFile(logFileName, logPattern, logLevel, 20);
}
/**
* 添加日志分割配置
*
* @param logFileName 日志文件名
* @param logPattern 需要分割的名匹配
* @param logMaxFileSize 日志文件最大多少M
* @return 当前对象
*/
public FastLog4j2Config addLogFile(String logFileName, String logPattern, int logMaxFileSize) {
return addLogFile(logFileName, logPattern, "debug", logMaxFileSize);
}
/**
* 添加日志分割配置
*
* @param logFileName 日志文件名
* @param logPattern 需要分割的名匹配
* @param logLevel 日志输出级别 all、debug、info、warn
* @param logMaxFileSize 日志文件最大多少M
* @return 当前对象
*/
public FastLog4j2Config addLogFile(String logFileName, String logPattern, String logLevel, int logMaxFileSize) {
logSplits.add(new Log4jSplitInfo()
.setFileName(logFileName)
.setLevel(logLevel)
.setLogPattern(logPattern)
.setLogFileMaxSize(logMaxFileSize));
return this;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy