Saltar al contenido

Archivo de configuración de propiedades log4j2 muy simple usando Console y Rolling File appender

Traemos la mejor solución que hemos encontrado en línea. Queremos que te resulte de mucha ayuda y si puedes comentarnos algo que nos pueda ayudar a perfeccionar nuestra información siéntete libre de hacerlo..

Solución:

Creo que no existe tal estándar de la industria para el registro o log4j2 configuración. Todos cambian la configuración según la necesidad de la aplicación.

A continuación se muestra un archivo de configuración log4j2 de muestra que tiene ConsoleAppender y RollingFileAppender

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 = %dyyyy-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= $basePathapp.log
appender.rolling.filePattern= $basePathapp_%dyyyyMMdd.log.gz
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = %dyyyy-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

Try this out:

# Declare loggers
name=LoggingConfig
appenders=a_console, a_rolling
rootLogger.level=info
rootLogger.appenderRefs=ar_console,ar_rolling
rootLogger.appenderRef.ar_console.ref=StdoutAppender
rootLogger.appenderRef.ar_rolling.ref=DailyRollingAppender

# Console logger
appender.a_console.type=Console
appender.a_console.name=StdoutAppender
appender.a_console.layout.type=PatternLayout
appender.a_console.layout.pattern=%dISO8601 [%t] %-5p (%F:%L) - %m%n

# File logger
appender.a_rolling.type=RollingFile
appender.a_rolling.name=DailyRollingAppender
appender.a_rolling.layout.pattern=%dISO8601 [%t] %-5p (%F:%L) - %m%n

appender.a_rolling.fileName=log4j2-sample.log
appender.a_rolling.filePattern=log4j2-sample-%dyyyy-MM-dd.log

appender.a_rolling.layout.type=PatternLayout
appender.a_rolling.policies.type=Policies
appender.a_rolling.policies.time.type=TimeBasedTriggeringPolicy
appender.a_rolling.policies.time.interval=1

¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)



Utiliza Nuestro Buscador

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *