logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <buks...@gmail.com>
Subject SpringEnvironmentHolder never gets its Environment initiated
Date Tue, 31 Dec 2019 07:39:25 GMT
Hi, 

 

I've been trying to get the Spring environment available in log4j2 for a
couple of weeks now.

Mostly using custom lookups and using the reload mechanism. I haven't fully
got it to work when log4j2 ver 2.13.0 got released so I switched over to try
make that work for me.

What happens is that the SpringEnvironmentHolder never gets initiated with
the Spring Environment.

The condition: [

if (environment == null && LogManager.getFactory() != null &&
LogManager.getFactory().hasContext(SpringEnvironmentHolder.class.getName(),
null, false)) {

]

Is never true, even though the Spring property sources are mostly available:
[

Object obj =
LogManager.getContext(false).getObject(Log4j2CloudConfigLoggingSystem.ENVIRO
NMENT_KEY);

]

 

Any ideas what I am doing wrong here?

My log4j2.properties file looks like this:

status=warn
name=Log4j2PropertiesConfig
packages=za.co.spsi.ice.config

property.log_dateformat_pattern=-yyyy-MM-dd HH:mm:ss.SSS
property.log_level_pattern=-%5p
property.pattern=%d{${log_dateformat_pattern:-yyyy-MM-dd HH:mm:ss.SSS}}
%highlight{${log_level_pattern:-%5p}}{FATAL=red blink, ERROR=red,
WARN=yellow bold, INFO=green, DEBUG=green bold, TRACE=blue}
%style{${sys:PID}}{magenta} [%15.15t] %style{%-40.40C{1.}}{cyan} :
%m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}
property.filename=./poe-buks.log

appender.null.type=Null
appender.null.name=LogNull

appender.console.type=Console
appender.console.name=LogToConsole
appender.console.layout.type=PatternLayout
appender.console.layout.pattern=${pattern}

appender.kafka.type=kafka
appender.kafka.name=LogToKafka
appender.kafka.topic=${spring:kafka.log.topic}
appender.kafka.properties1.type=Property
appender.kafka.properties1.name=bootstrap.servers
appender.kafka.properties1.value=${spring:spring.kafka.bootstrap-servers}
appender.kafka.syncSend=${spring:kafka.log.async}
appender.kafka.layout.type=PatternLayout
appender.kafka.layout.pattern=%d{${log_dateformat_pattern:-yyyy-MM-dd
HH:mm:ss.SSS}} %highlight{${log_level_pattern:-%5p}}{FATAL=red blink,
ERROR=red, WARN=yellow bold, INFO=green, DEBUG=green bold, TRACE=blue}
%style{${sys:PID}}{magenta} [%15.15t] %style{%-40.40C{1.}}{cyan} :
%m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}

# Rotate log file
appender.rolling.type=RollingFile
appender.rolling.name=LogToRollingFile
appender.rolling.fileName=${filename}
appender.rolling.filePattern=${filename}.%d{yyyy-MM-dd}.%i.gz
appender.rolling.layout.type=PatternLayout
appender.rolling.layout.pattern=${pattern}
appender.rolling.policies.type=Policies
appender.rolling.policies.time.type=TimeBasedTriggeringPolicy
appender.rolling.policies.size.type=SizeBasedTriggeringPolicy
appender.rolling.policies.size.size=10MB
appender.rolling.strategy.type=DefaultRolloverStrategy
appender.rolling.strategy.max=10

appender.routing.type=Routing
appender.routing.name=LogToRoutingAppender
appender.routing.routes.type=Routes
appender.routing.routes.pattern=${sys:kafka.log.enabled}
appender.routing.routes.route1.type=Route
appender.routing.routes.route1.key=false
appender.routing.routes.route1.ref=LogNull
appender.routing.routes.route2.type=Route
appender.routing.routes.route2.key=true
appender.routing.routes.route2.ref=LogToKafka

logger.kafka.name=org.apache.kafka
logger.kafka.level=error
logger.kafka.additivity=false
logger.kafka.appenderRef.rolling.ref=LogToRollingFile
logger.kafka.appenderRef.routing.ref=LogToRoutingAppender

logger.spring-kafka.name=org.springframework.kafka
logger.spring-kafka.level=error
logger.spring-kafka.additivity=false
logger.spring-kafka.appenderRef.rolling.ref=LogToRollingFile
logger.spring-kafka.appenderRef.routing.ref=LogToRoutingAppender

logger.hibernate.name=org.hibernate
logger.hibernate.level=warn
logger.hibernate.additivity=false
logger.hibernate.appenderRef.rolling.ref=LogToRollingFile
logger.hibernate.appenderRef.routing.ref=LogToRoutingAppender

logger.apache.name=org.apache
logger.apache.level=warn
logger.apache.additivity=false
logger.apache.appenderRef.rolling.ref=LogToRollingFile
logger.apache.appenderRef.routing.ref=LogToRoutingAppender

#Root logger will log to
rootLogger.level=info
rootLogger.appenderRef.stdout.ref=LogToRollingFile
rootLogger.appenderRef.routing.ref=LogToRoutingAppender



 

Kind regards,

Buks

 

 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message