All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nervousync.utils.LoggerUtils Maven / Gradle / Ivy

There is a newer version: 1.2.1
Show newest version
package org.nervousync.utils;

import org.apache.logging.log4j.core.config.builder.api.*;
import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.appender.ConsoleAppender;
import org.apache.logging.log4j.core.config.Configuration;
import org.nervousync.commons.Globals;
import org.nervousync.exceptions.AbstractException;
import org.slf4j.LoggerFactory;

import java.util.*;

/**
 * 

Logger Utilities

* * Current utilities implements features: *
    Using programming to initialize Log4j
*
    Using programming to initialize Log4j and configure target package with custom level
*
    Support output internationalize logger information
*
*

日志工具集

* * 此工具集实现以下功能: *
    使用编程方式初始化Log4j
*
    使用编程方式初始化Log4j并设置目标包名为不同的日志等级
*
    支持国际化的日志输出
*
* * @author Steven Wee [email protected] * @version $Revision: 1.2.0 $ $Date: Sep 15, 2018 16:54:27 $ */ public final class LoggerUtils { /** *

Private constructor for LoggerUtils

*

日志工具集的私有构造方法

*/ private LoggerUtils() { } /** *

Configure root logger using given level

*

使用给定的日志等级设置根日志

* * @param rootLevel Log level * 日志等级 */ public static void initLoggerConfigure(final Level rootLevel) { initLoggerConfigure(rootLevel, new PackageLogger[0]); } /** *

Configure root logger using given level and configure given package name to custom level

*

使用给定的日志等级设置根日志,同时设置给定的包名为对应的日志等级

* * @param rootLevel Log level * 日志等级 * @param packageLoggers Package logger configure array * 包日志设置数组 */ public static void initLoggerConfigure(final Level rootLevel, final PackageLogger... packageLoggers) { initLoggerConfigure(Globals.DEFAULT_VALUE_STRING, rootLevel, packageLoggers); } /** *

Configure root logger using given level, save logger to target file path and configure given package name to custom level

*

使用给定的日志等级设置根日志,将日志文件写入到指定的目录,同时设置给定的包名为对应的日志等级

* * @param basePath Log file base path * 文件日志的保存目录 * @param rootLevel Log level * 日志等级 * @param packageLoggers Package logger configure array * 包日志设置数组 */ public static void initLoggerConfigure(final String basePath, final Level rootLevel, final PackageLogger... packageLoggers) { Optional.ofNullable(generateConfiguration(generateConfig(basePath, rootLevel, packageLoggers))) .ifPresent(configuration -> { LoggerContext loggerContext = (LoggerContext) LogManager.getContext(Boolean.FALSE); loggerContext.setConfiguration(configuration); loggerContext.updateLoggers(); }); } /** *

Generate PackageLogger instance using given package name and log level

*

使用给定的包名和日志等级生成PackageLogger实例对象

* * @param packageName Package name * 包名 * @param loggerLevel Log level * 日志等级 * * @return Generated PackageLogger instance * 生成的PackageLogger实例对象 */ public static PackageLogger newLogger(final String packageName, final Level loggerLevel) { return new PackageLogger(packageName, loggerLevel); } /** *

Retrieve i18n logger instance

*

获取国际化支持的日志实例对象

* * @param clazz Logger identify class * 日志识别类 * * @return Generated logger instance * 生成的日志实例对象 */ public static Logger getLogger(final Class clazz) { return new Logger(clazz); } /** *

Package logger define

*

包日志定义

* * @author Steven Wee [email protected] * @version $Revision: 1.0.0 $ $Date: Sep 15, 2018 17:28:14 $ */ public static final class PackageLogger { /** * Package name * 包名 */ private final String packageName; /** * Log level * 日志等级 */ private final Level loggerLevel; /** *

Private constructor for PackageLogger

*

包日志定义的私有构造方法

* * @param packageName Package name * 包名 * @param loggerLevel Log level * 日志等级 */ private PackageLogger(final String packageName, final Level loggerLevel) { this.packageName = packageName; this.loggerLevel = loggerLevel; } /** *

Getter method for package name

*

包名的Getter方法

* * @return Package name * 包名 */ public String getPackageName() { return packageName; } /** *

Getter method for log level

*

日志等级的Getter方法

* * @return Log level * 日志等级 */ public Level getLoggerLevel() { return loggerLevel; } } /** *

Logger define for support i18n

*

有国际化支持的日志定义

* * @author Steven Wee [email protected] * @version $Revision: 1.0.0 $ $Date: Jul 21, 2023 12:59:48 $ */ public static final class Logger { /** * Logger instance * 日志实例 */ private final org.slf4j.Logger logger; private final MultilingualUtils.Agent multiAgent; /** *

Constructor for MultilingualLogger

*

有国际化支持的日志的构造方法

* * @param clazz Logger identify class * 日志识别类 */ Logger(final Class clazz) { this.logger = LoggerFactory.getLogger(clazz); this.multiAgent = MultilingualUtils.newAgent(clazz); } /** *

Logger level is trace enabled

*

日志级别开启Trace

*/ public boolean isTraceEnabled() { return this.logger.isTraceEnabled(); } /** *

Output trace message

*

输出Trace信息

* * @param messageKey Message identify key * 信息识别键值 */ public void trace(final String messageKey) { this.trace(messageKey, new Object[0]); } /** *

Output trace message

*

输出Trace信息

* * @param messageKey Message identify key * 信息识别键值 * @param collections given parameters of information formatter * 用于资源信息格式化的参数 */ public void trace(final String messageKey, final Object... collections) { this.trace(messageKey, null, collections); } /** *

Output trace message

*

输出Trace信息

* * @param messageKey Message identify key * 信息识别键值 * @param throwable Throwable exception instance * 抛出的异常实例对象 */ public void trace(final String messageKey, Throwable throwable) { this.trace(messageKey, throwable, new Object[0]); } /** *

Output trace message

*

输出Trace信息

* * @param messageKey Message identify key * 信息识别键值 * @param throwable Throwable exception instance * 抛出的异常实例对象 * @param collections given parameters of information formatter * 用于资源信息格式化的参数 */ public void trace(final String messageKey, Throwable throwable, final Object... collections) { this.logger.trace(this.multiAgent.findMessage(messageKey, collections)); if (throwable != null) { String message = Globals.DEFAULT_VALUE_STRING; if (throwable instanceof AbstractException) { message = this.multiAgent.findMessage("Code_Error", "0x" + Long.toHexString(((AbstractException) throwable).getErrorCode())); } this.logger.trace(message, throwable); } } /** *

Logger level is debug enabled

*

日志级别开启Debug

*/ public boolean isDebugEnabled() { return this.logger.isDebugEnabled(); } /** *

Output debug message

*

输出Debug信息

* * @param messageKey Message identify key * 信息识别键值 */ public void debug(final String messageKey) { this.debug(messageKey, new Object[0]); } /** *

Output debug message

*

输出Debug信息

* * @param messageKey Message identify key * 信息识别键值 * @param collections given parameters of information formatter * 用于资源信息格式化的参数 */ public void debug(final String messageKey, final Object... collections) { this.debug(messageKey, null, collections); } /** *

Output debug message

*

输出Debug信息

* * @param messageKey Message identify key * 信息识别键值 * @param throwable Throwable exception instance * 抛出的异常实例对象 */ public void debug(final String messageKey, Throwable throwable) { this.debug(messageKey, throwable, new Object[0]); } /** *

Output debug message

*

输出Debug信息

* * @param messageKey Message identify key * 信息识别键值 * @param throwable Throwable exception instance * 抛出的异常实例对象 * @param collections given parameters of information formatter * 用于资源信息格式化的参数 */ public void debug(final String messageKey, Throwable throwable, final Object... collections) { this.logger.debug(this.multiAgent.findMessage(messageKey, collections)); if (throwable != null) { String message = Globals.DEFAULT_VALUE_STRING; if (throwable instanceof AbstractException) { message = this.multiAgent.findMessage("Code_Error", "0x" + Long.toHexString(((AbstractException) throwable).getErrorCode())); } this.logger.debug(message, throwable); } } /** *

Logger level is info enabled

*

日志级别开启Info

*/ public boolean isInfoEnabled() { return this.logger.isInfoEnabled(); } /** *

Output info message

*

输出Info信息

* * @param messageKey Message identify key * 信息识别键值 */ public void info(final String messageKey) { this.info(messageKey, new Object[0]); } /** *

Output info message

*

输出Info信息

* * @param messageKey Message identify key * 信息识别键值 * @param collections given parameters of information formatter * 用于资源信息格式化的参数 */ public void info(final String messageKey, final Object... collections) { this.info(messageKey, null, collections); } /** *

Output info message

*

输出Info信息

* * @param messageKey Message identify key * 信息识别键值 * @param throwable Throwable exception instance * 抛出的异常实例对象 */ public void info(final String messageKey, Throwable throwable) { this.info(messageKey, throwable, new Object[0]); } /** *

Output info message

*

输出Info信息

* * @param messageKey Message identify key * 信息识别键值 * @param throwable Throwable exception instance * 抛出的异常实例对象 * @param collections given parameters of information formatter * 用于资源信息格式化的参数 */ public void info(final String messageKey, Throwable throwable, final Object... collections) { this.logger.info(this.multiAgent.findMessage(messageKey, collections)); if (throwable != null) { String message = Globals.DEFAULT_VALUE_STRING; if (throwable instanceof AbstractException) { message = this.multiAgent.findMessage("Code_Error", "0x" + Long.toHexString(((AbstractException) throwable).getErrorCode())); } this.logger.info(message, throwable); } } /** *

Logger level is warn enabled

*

日志级别开启Warn

*/ public boolean isWarnEnabled() { return this.logger.isWarnEnabled(); } /** *

Output trace message

*

输出Warn信息

* * @param messageKey Message identify key * 信息识别键值 */ public void warn(final String messageKey) { this.warn(messageKey, new Object[0]); } /** *

Output warn message

*

输出Warn信息

* * @param messageKey Message identify key * 信息识别键值 * @param collections given parameters of information formatter * 用于资源信息格式化的参数 */ public void warn(final String messageKey, final Object... collections) { this.warn(messageKey, null, collections); } /** *

Output warn message

*

输出Warn信息

* * @param messageKey Message identify key * 信息识别键值 * @param throwable Throwable exception instance * 抛出的异常实例对象 */ public void warn(final String messageKey, Throwable throwable) { this.warn(messageKey, throwable, new Object[0]); } /** *

Output warn message

*

输出Warn信息

* * @param messageKey Message identify key * 信息识别键值 * @param throwable Throwable exception instance * 抛出的异常实例对象 * @param collections given parameters of information formatter * 用于资源信息格式化的参数 */ public void warn(final String messageKey, Throwable throwable, final Object... collections) { this.logger.warn(this.multiAgent.findMessage(messageKey, collections)); if (throwable != null) { String message = Globals.DEFAULT_VALUE_STRING; if (throwable instanceof AbstractException) { message = this.multiAgent.findMessage("Code_Error", "0x" + Long.toHexString(((AbstractException) throwable).getErrorCode())); } this.logger.warn(message, throwable); } } /** *

Logger level is error enabled

*

日志级别开启Error

*/ public boolean isErrorEnabled() { return this.logger.isErrorEnabled(); } /** *

Output trace message

*

输出Error信息

* * @param messageKey Message identify key * 信息识别键值 */ public void error(final String messageKey) { this.error(messageKey, new Object[0]); } /** *

Output error message

*

输出Error信息

* * @param messageKey Message identify key * 信息识别键值 * @param collections given parameters of information formatter * 用于资源信息格式化的参数 */ public void error(final String messageKey, final Object... collections) { this.error(messageKey, null, collections); } /** *

Output error message

*

输出Error信息

* * @param messageKey Message identify key * 信息识别键值 * @param throwable Throwable exception instance * 抛出的异常实例对象 */ public void error(final String messageKey, Throwable throwable) { this.error(messageKey, throwable, new Object[0]); } /** *

Output error message

*

输出Error信息

* * @param messageKey Message identify key * 信息识别键值 * @param throwable Throwable exception instance * 抛出的异常实例对象 * @param collections given parameters of information formatter * 用于资源信息格式化的参数 */ public void error(final String messageKey, Throwable throwable, final Object... collections) { this.logger.error(this.multiAgent.findMessage(messageKey, collections)); if (throwable != null) { String message = Globals.DEFAULT_VALUE_STRING; if (throwable instanceof AbstractException) { message = this.multiAgent.findMessage("Code_Error", "0x" + Long.toHexString(((AbstractException) throwable).getErrorCode())); } this.logger.error(message, throwable); } } } /** *

Generate Configuration instance by given LogConfig instance

*

使用给定的日志配置定义生成Configuration实例对象

* * @param logConfig LogConfig instance * 日志配置定义实例对象 * * @return Generated Configuration instance * 生成的Configuration实例对象 */ private static Configuration generateConfiguration(final LogConfig logConfig) { if (logConfig == null || logConfig.getAppenderConfigures() == null) { return null; } final ConfigurationBuilder configurationBuilder = ConfigurationBuilderFactory.newConfigurationBuilder(); configurationBuilder.setStatusLevel(Level.ERROR); Optional layoutComponentBuilder = Optional.ofNullable(layoutBuilder(logConfig.getPatternLayoutConfigure())); logConfig.getAppenderConfigures() .stream() .filter(appenderConfigure -> StringUtils.notBlank(appenderConfigure.getAppenderName()) && StringUtils.notBlank(appenderConfigure.getAppenderPlugin())) .forEach(appenderConfigure -> { AppenderComponentBuilder appenderComponentBuilder = configurationBuilder.newAppender(appenderConfigure.getAppenderName(), appenderConfigure.getAppenderPlugin()); Optional.ofNullable(appenderConfigure.getAppenderAttributes()) .ifPresent(appenderAttributes -> appenderAttributes.forEach(appenderComponentBuilder::addAttribute)); Optional.ofNullable(appenderConfigure.getAppenderComponents()) .ifPresent(appenderComponents -> appenderComponents.forEach(componentConfigure -> initComponentConfig(appenderComponentBuilder, componentConfigure))); if (appenderConfigure.getPatternLayoutConfigure() == null) { layoutComponentBuilder.ifPresent(appenderComponentBuilder::add); } else { Optional.ofNullable(layoutBuilder(appenderConfigure.getPatternLayoutConfigure())) .ifPresent(appenderComponentBuilder::add); } configurationBuilder.add(appenderComponentBuilder); }); Optional.ofNullable(logConfig.getLoggerConfigures()) .ifPresent(loggerConfigures -> loggerConfigures.stream() .filter(loggerConfigure -> StringUtils.notBlank(loggerConfigure.getPackageName()) && loggerConfigure.getAppenderNames() != null && !loggerConfigure.getAppenderNames().isEmpty()) .forEach(loggerConfigure -> { LoggerComponentBuilder loggerComponentBuilder = configurationBuilder.newLogger(loggerConfigure.getPackageName(), loggerConfigure.getLoggerLevel()); loggerComponentBuilder.addAttribute("additivity", Boolean.FALSE); loggerConfigure.getAppenderNames().forEach(appenderName -> loggerComponentBuilder.add(configurationBuilder.newAppenderRef(appenderName))); configurationBuilder.add(loggerComponentBuilder); })); LoggerConfigure rootLoggerConfigure = logConfig.getRootLoggerConfigure(); if (rootLoggerConfigure.getAppenderNames() != null && !rootLoggerConfigure.getAppenderNames().isEmpty()) { RootLoggerComponentBuilder rootLoggerComponentBuilder = configurationBuilder.newRootLogger(rootLoggerConfigure.getLoggerLevel()); rootLoggerConfigure.getAppenderNames() .forEach(appenderName -> rootLoggerComponentBuilder.add(configurationBuilder.newAppenderRef(appenderName))); configurationBuilder.add(rootLoggerComponentBuilder); } return configurationBuilder.build(); } /** *

Generate LogConfig instance by given parameters

*

使用给定的参数信息生成日志配置定义实例对象

* * @param basePath Log file base path * 文件日志的保存目录 * @param rootLevel Log level * 日志等级 * @param packageLoggers Package logger configure array * 包日志设置数组 * * @return Generated LogConfig instance * 生成的日志配置定义实例对象 */ private static LogConfig generateConfig(final String basePath, final Level rootLevel, final PackageLogger... packageLoggers) { PatternLayoutConfigure patternLayoutConfigure = new PatternLayoutConfigure(); Map layoutAttributes = new HashMap<>(); layoutAttributes.put("pattern", "%d{yyyy-MM-dd HH:mm:ss} %p [%t] [%c:%L]: %m%n"); patternLayoutConfigure.setAttributesMap(layoutAttributes); List appenderConfigures = new ArrayList<>(); AppenderConfigure appenderConfigure = new AppenderConfigure("Console", "Console"); Map consoleAppenderAttributes = new HashMap<>(); consoleAppenderAttributes.put("target", ConsoleAppender.Target.SYSTEM_OUT); appenderConfigure.setAppenderAttributes(consoleAppenderAttributes); appenderConfigures.add(appenderConfigure); LoggerConfigure rootLoggerConfigure = new LoggerConfigure(newLogger(Globals.DEFAULT_VALUE_STRING, rootLevel)); List appenderNames; if (StringUtils.notBlank(basePath)) { FileUtils.makeDir(basePath); AppenderConfigure fileAppenderConfigure = new AppenderConfigure("File", "File"); Map fileAppenderAttributes = new HashMap<>(); fileAppenderAttributes.put("fileName", basePath + Globals.DEFAULT_LOG_FILE_PATH); fileAppenderConfigure.setAppenderAttributes(fileAppenderAttributes); appenderConfigures.add(fileAppenderConfigure); appenderNames = List.of("Console", "File"); } else { appenderNames = List.of("Console"); } rootLoggerConfigure.setAppenderNames(appenderNames); LogConfig logConfig = new LogConfig(patternLayoutConfigure); logConfig.setAppenderConfigures(appenderConfigures); logConfig.setRootLoggerConfigure(rootLoggerConfigure); if (packageLoggers != null) { List loggerConfigures = new ArrayList<>(); Arrays.stream(packageLoggers) .filter(packageLogger -> StringUtils.notBlank(packageLogger.getPackageName())) .forEach(packageLogger -> { LoggerConfigure loggerConfigure = new LoggerConfigure(packageLogger); loggerConfigure.setAppenderNames(appenderNames); loggerConfigures.add(loggerConfigure); }); logConfig.setLoggerConfigures(loggerConfigures); } return logConfig; } /** *

Initialize component configure

*

初始化组件配置

* * @param parentBuilder Parent builder instance * 上级构建器实例对象 * @param componentConfigure Component configure * 组件配置定义 */ private static void initComponentConfig(final ComponentBuilder parentBuilder, final ComponentConfigure componentConfigure) { if (parentBuilder == null || componentConfigure == null || StringUtils.isEmpty(componentConfigure.getComponentPlugin())) { return; } final ComponentBuilder componentBuilder = ConfigurationBuilderFactory.newConfigurationBuilder() .newComponent(componentConfigure.getComponentPlugin()); if (componentConfigure.getComponentAttributes() != null) { componentConfigure.getComponentAttributes().forEach(componentBuilder::addAttribute); } if (componentConfigure.getChildComponents() != null) { componentConfigure.getChildComponents() .forEach(childComponentConfig -> initComponentConfig(componentBuilder, childComponentConfig)); } parentBuilder.addComponent(componentBuilder); } /** *

Generate LayoutComponentBuilder by given pattern layout configure

*

根据给定的输出格式配置信息生成输出格式组件构建器

* * @param patternLayoutConfigure Pattern layout configure * 日志输出格式配置定义 */ private static LayoutComponentBuilder layoutBuilder(final PatternLayoutConfigure patternLayoutConfigure) { if (patternLayoutConfigure == null) { return null; } LayoutComponentBuilder layoutComponentBuilder = ConfigurationBuilderFactory.newConfigurationBuilder().newLayout("PatternLayout"); if (patternLayoutConfigure.getAttributesMap() != null) { patternLayoutConfigure.getAttributesMap().forEach(layoutComponentBuilder::addAttribute); } if (patternLayoutConfigure.getLoggerComponents() != null) { patternLayoutConfigure.getLoggerComponents() .forEach(componentConfigure -> initComponentConfig(layoutComponentBuilder, componentConfigure)); } return layoutComponentBuilder; } /** *

Log configure define

*

日志配置定义

* * @author Steven Wee [email protected] * @version $Revision: 1.0.0 $ $Date: Sep 15, 2018 17:30:18 $ */ private static final class LogConfig { /** * Log print pattern layout configure * 日志输出的格式设置 */ private final PatternLayoutConfigure patternLayoutConfigure; /** * Logger appender configure * 日志输出目标设置 */ private List appenderConfigures; /** * Custom logger configure * 自定义日志设置 */ private List loggerConfigures; /** * Root logger configure * 根日志设置 */ private LoggerConfigure rootLoggerConfigure; /** *

Private constructor for LogConfig

*

日志配置定义的私有构造方法

* * @param patternLayoutConfigure Log print pattern layout configure * 日志输出的格式设置 */ private LogConfig(PatternLayoutConfigure patternLayoutConfigure) { this.patternLayoutConfigure = patternLayoutConfigure; } /** *

Getter method for Log print pattern layout configure

*

日志输出的格式设置的Getter方法

* * @return Log print pattern layout configure * 日志输出的格式设置 */ public PatternLayoutConfigure getPatternLayoutConfigure() { return patternLayoutConfigure; } /** *

Getter method for Logger appender configure

*

日志输出目标设置的Getter方法

* * @return Logger appender configure * 日志输出目标设置 */ public List getAppenderConfigures() { return appenderConfigures; } /** *

Setter method for Logger appender configure

*

日志输出目标设置的Setter方法

* * @param appenderConfigures Logger appender configure * 日志输出目标设置 */ public void setAppenderConfigures(List appenderConfigures) { this.appenderConfigures = appenderConfigures; } /** *

Getter method for Custom logger configure

*

自定义日志设置的Getter方法

* * @return Custom logger configure * 自定义日志设置 */ public List getLoggerConfigures() { return loggerConfigures; } /** *

Setter method for Custom logger configure

*

自定义日志设置的Setter方法

* * @param loggerConfigures Custom logger configure * 自定义日志设置 */ public void setLoggerConfigures(List loggerConfigures) { this.loggerConfigures = loggerConfigures; } /** *

Getter method for Root logger configure

*

根日志设置的Getter方法

* * @return Root logger configure * 根日志设置 */ public LoggerConfigure getRootLoggerConfigure() { return rootLoggerConfigure; } /** *

Setter method for Root logger configure

*

根日志设置的Setter方法

* * @param rootLoggerConfigure Root logger configure * 根日志设置 */ public void setRootLoggerConfigure(LoggerConfigure rootLoggerConfigure) { this.rootLoggerConfigure = rootLoggerConfigure; } } /** *

Pattern layout configure define

*

日志输出格式配置定义

* * @author Steven Wee [email protected] * @version $Revision: 1.0.0 $ $Date: Sep 15, 2018 17:31:06 $ */ private static final class PatternLayoutConfigure { /** * Attribute configure map * 参数设置映射 */ private Map attributesMap; /** * Logger component list * 日志组件列表 */ private List loggerComponents; /** *

Private constructor for PatternLayoutConfigure

*

日志输出格式配置定义的私有构造方法

*/ private PatternLayoutConfigure() { } /** *

Getter method for Attribute configure map

*

参数设置映射的Getter方法

* * @return Attribute configure map * 参数设置映射 */ public Map getAttributesMap() { return attributesMap; } /** *

Setter method for Attribute configure map

*

参数设置映射的Setter方法

* * @param attributesMap Attribute configure map * 参数设置映射 */ public void setAttributesMap(Map attributesMap) { this.attributesMap = attributesMap; } /** *

Getter method for Logger component list

*

日志组件列表的Getter方法

* * @return Logger component list * 日志组件列表 */ public List getLoggerComponents() { return loggerComponents; } /** *

Setter method for Logger component list

*

日志组件列表的Setter方法

* * @param loggerComponents Logger component list * 日志组件列表 */ public void setLoggerComponents(List loggerComponents) { this.loggerComponents = loggerComponents; } } /** *

Appender configure define

*

日志输出目标配置定义

* * @author Steven Wee [email protected] * @version $Revision: 1.0.0 $ $Date: Sep 15, 2018 17:37:22 $ */ private static final class AppenderConfigure { /** * Appender name * 日志输出目标名称 */ private final String appenderName; /** * Appender plugin name * 日志输出目标插件名 */ private final String appenderPlugin; /** * Appender attributes map * 日志输出目标属性映射 */ private Map appenderAttributes; /** * Appender component list * 日志输出目标组件列表 */ private List appenderComponents; /** * Appender pattern layout configure * 日志输出目标格式定义 */ private PatternLayoutConfigure patternLayoutConfigure; /** *

Private constructor for AppenderConfigure

*

日志输出目标配置定义的私有构造方法

* * @param appenderName Appender name * 日志输出目标名称 * @param appenderPlugin Appender plugin name * 日志输出目标插件名 */ private AppenderConfigure(final String appenderName, final String appenderPlugin) { this.appenderName = appenderName; this.appenderPlugin = appenderPlugin; } /** *

Getter method for appender name

*

日志输出目标名称的Getter方法

* * @return Appender name * 日志输出目标名称 */ public String getAppenderName() { return appenderName; } /** *

Getter method for appender plugin name

*

日志输出目标插件名称的Getter方法

* * @return Appender plugin name * 日志输出目标插件名称 */ public String getAppenderPlugin() { return appenderPlugin; } /** *

Getter method for appender attributes map

*

日志输出目标属性映射的Getter方法

* * @return Appender attributes map * 日志输出目标属性映射 */ public Map getAppenderAttributes() { return appenderAttributes; } /** *

Setter method for appender attributes map

*

日志输出目标属性映射的Setter方法

* * @param appenderAttributes Appender attributes map * 日志输出目标属性映射 */ public void setAppenderAttributes(Map appenderAttributes) { this.appenderAttributes = appenderAttributes; } /** *

Getter method for appender component list

*

日志输出目标组件列表的Getter方法

* * @return Appender component list * 日志输出目标组件列表 */ public List getAppenderComponents() { return appenderComponents; } /** *

Setter method for appender component list

*

日志输出目标组件列表的Setter方法

* * @param appenderComponents the appender components * Appender component list * 日志输出目标组件列表 */ public void setAppenderComponents(List appenderComponents) { this.appenderComponents = appenderComponents; } /** *

Getter method for appender pattern layout configure

*

日志输出目标格式定义的Getter方法

* * @return Appender pattern layout configure * 日志输出目标格式定义 */ public PatternLayoutConfigure getPatternLayoutConfigure() { return patternLayoutConfigure; } /** *

Setter method for appender pattern layout configure

*

日志输出目标格式定义的Setter方法

* * @param patternLayoutConfigure Appender pattern layout configure * 日志输出目标格式定义 */ public void setPatternLayoutConfigure(PatternLayoutConfigure patternLayoutConfigure) { this.patternLayoutConfigure = patternLayoutConfigure; } } /** *

Logger configure define

*

日志配置定义

* * @author Steven Wee [email protected] * @version $Revision: 1.0.0 $ $Date: Sep 15, 2018 17:43:57 $ */ private static final class LoggerConfigure { /** * Package name * 包名 */ private final String packageName; /** * Log level * 日志等级 */ private final Level loggerLevel; /** * Log appender name list * 日志输出目标名称列表 */ private List appenderNames; /** *

Private constructor for LoggerConfigure

*

日志配置定义的私有构造方法

* * @param packageLogger Package logger define * 包日志定义 */ private LoggerConfigure(final PackageLogger packageLogger) { this.packageName = packageLogger.getPackageName(); this.loggerLevel = packageLogger.getLoggerLevel(); } /** *

Getter method for package name

*

包名的Getter方法

* * @return Package name * 包名 */ public String getPackageName() { return packageName; } /** *

Getter method for log level

*

日志等级的Getter方法

* * @return Log level * 日志等级 */ public Level getLoggerLevel() { return loggerLevel; } /** *

Getter method for log appender name list

*

日志输出目标名称列表的Getter方法

* * @return Log appender name list * 日志输出目标名称列表 */ public List getAppenderNames() { return appenderNames; } /** *

Setter method for log appender name list

*

日志输出目标名称列表的Setter方法

* * @param appenderNames Log appender name list * 日志输出目标名称列表 */ public void setAppenderNames(List appenderNames) { this.appenderNames = appenderNames; } } /** *

Component configure define

*

组件配置定义

* * @author Steven Wee [email protected] * @version $Revision: 1.0.0 $ $Date: Sep 15, 2018 17:55:19 $ */ private static final class ComponentConfigure { /** * Component plugin name * 组件插件名称 */ private final String componentPlugin; /** * Component attributes map * 组件属性映射 */ private Map componentAttributes; /** * Child component configure list * 子组件配置信息列表 */ private List childComponents; /** *

Private constructor for ComponentConfigure

*

组件配置定义的私有构造方法

* * @param componentPlugin Component plugin name * 组件插件名称 */ private ComponentConfigure(final String componentPlugin) { this.componentPlugin = componentPlugin; this.componentAttributes = new HashMap<>(); this.childComponents = new ArrayList<>(); } /** *

Getter method for component plugin name

*

组件插件名称的Getter方法

* * @return Component plugin name * 组件插件名称 */ public String getComponentPlugin() { return componentPlugin; } /** *

Getter method for component attributes map

*

组件属性映射的Getter方法

* * @return Component attributes map * 组件属性映射 */ public Map getComponentAttributes() { return componentAttributes; } /** *

Setter method for component attributes map

*

组件属性映射的Setter方法

* * @param componentAttributes Component attributes map * 组件属性映射 */ public void setComponentAttributes(Map componentAttributes) { this.componentAttributes = componentAttributes; } /** *

Getter method for child component configure list

*

子组件配置信息列表的Getter方法

* * @return Child component configure list * 子组件配置信息列表 */ public List getChildComponents() { return childComponents; } /** *

Setter method for child component configure list

*

子组件配置信息列表的Setter方法

* * @param childComponents Child component configure list * 子组件配置信息列表 */ public void setChildComponents(List childComponents) { this.childComponents = childComponents; } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy