使用控制台和滚动文件附加程序的非常简单的log4j2属性配置文件

苏巴吉特·帕尔(Subhajit Pal)

我想要一个带有控制台的log4j2属性文件配置和一个使用log4j2的滚动文件附加程序,可以将其用于其他应用程序。日志配置应在生产环境中轮换日志。

维卡斯(Vikas Sachdeva)

我认为没有用于记录或log4j2配置的行业标准每个人都根据应用程序的需要更改配置。

以下是一个示例log4j2配置文件,该文件具有ConsoleAppenderRollingFileAppender-

status = warn
name= properties_configuration

# Give directory path where log files should get stored
property.basePath = ./log/

# ConsoleAppender will print logs on console
appender.console.type = Console
appender.console.name = consoleLogger
appender.console.target = SYSTEM_OUT
appender.console.layout.type = PatternLayout

# Specify the pattern of the logs
appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss.SSS} %level [%t] [%c] [%M] [%l] - %msg%n


# RollingFileAppender will print logs in file which can be rotated based on time or size
appender.rolling.type = RollingFile
appender.rolling.name = fileLogger
appender.rolling.fileName= ${basePath}app.log
appender.rolling.filePattern= ${basePath}app_%d{yyyyMMdd}.log.gz
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = %d{yyyy-MM-dd HH:mm:ss.SSS} %level [%t] [%c] [%M] [%l] - %msg%n
appender.rolling.policies.type = Policies

# Rotate log file each day and keep 30 days worth
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
appender.rolling.policies.time.interval = 1
appender.rolling.policies.time.modulate = true
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.delete.type = Delete
appender.rolling.strategy.delete.basePath = ${basePath}
appender.rolling.strategy.delete.maxDepth = 1
appender.rolling.strategy.delete.ifLastModified.type = IfLastModified
# Delete files older than 30 days
appender.rolling.strategy.delete.ifLastModified.age = 30d

# Mention package name here in place of example. Classes in this package or subpackages will use ConsoleAppender and RollingFileAppender for logging         
logger.example.name = example
logger.example.level = debug
logger.example.additivity = false
logger.example.appenderRef.rolling.ref = fileLogger
logger.example.appenderRef.console.ref = consoleLogger

# Configure root logger for logging error logs in classes which are in package other than above specified package
rootLogger.level = error
rootLogger.additivity = false
rootLogger.appenderRef.rolling.ref = fileLogger
rootLogger.appenderRef.console.ref = consoleLogger

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用控制台和文件附加器的非常简单的log4j2 XML配置文件

Log4j2:如何在控制台日志中查找是否已找到日志配置文件

找不到log4j2配置文件。使用默认配置:仅将错误记录到控制台

log4j2 配置记录到文件但不记录到控制台

Log4j2记录到文件和控制台

属性文件格式的安全TCP套接字附加程序的log4j2配置

Log4j2的控制台附加程序的NullpointerException

Log4j2:记录影响控制台级别的文件级别

Log4J2 - 只写入日志文件而不是控制台

找不到log4j2配置文件

log4j2找不到配置文件

找不到log4j2配置文件

使用Spring的与配置文件相关的log4j2配置

使用单个log4j2 xml文件配置log4j2和log4j

使用可执行JAR时指定Log4j2配置文件

Log4j2无法使用json配置文件

没有使用 log4j2 和 slf4j 的控制台输出

Log4j2:日志未发送到控制台,因为日志文件工作正常

带有滚动文件附加程序的Log4j2 AsyncLogger不显示文件行号

无法为log4j控制台附加程序配置时区

在本地运行时如何登录到控制台,在使用log4j2在服务器上运行时如何登录到滚动日志文件?

控制台log4j2 kafka:找不到记录器的附加程序(kafka.utils.Log4jControllerRegistration $)

虚拟控制台的配置文件

在 log4j2 中访问 spring 配置文件以获取 spring boot 应用程序

使用 WSL2 配置文件运行时如何查看控制台应用程序的输出?

Spring配置文件,不同的Log4j2配置

log4j 2向控制台附加程序添加多种颜色

log4j xml配置,将一些Logger写入文件和控制台

如何使用非默认的工匠配置文件URL配置工匠配置文件客户端和工匠配置文件管理控制台?