Graylog log4j appender configuration in external file


(David) #1

Hi!!

I’m working in a java application and I want to configure graylog host and port in an external configuration file.

This is the graylog appender in my log4j.properties file:

log4j.appender.graylog2=org.graylog2.log.GelfAppender
log4j.appender.graylog2.graylogHost=172.21.242.209
log4j.appender.graylog2.graylogPort=12201
log4j.appender.graylog2.originHost=david-localhost
log4j.appender.graylog2.facility=gelf-java
log4j.appender.graylog2.layout=org.apache.log4j.PatternLayout
log4j.appender.graylog2.extractStacktrace=true
log4j.appender.graylog2.addExtendedInformation=true
log4j.appender.graylog2.Threshold=ERROR
log4j.appender.graylog2.additionalFields={‘aplicacion’: ‘REPRESENTA’}

I would like to configure .graylogHost and .graylogPort as a properties in an external properties file. Can I do it? and then, how can I? How can I refer from my log4j.properties file to the propeties of this external file?

I’m using gelfj 1.1.15 and log4j 1.2.15.

Thanks a lot!!


(Jochen) #2

Which GELF appender are you using?
Which version of Log4j are you using?


(David) #3

Sorry. I’m using gelfj 1.1.15 and log4j 1.2.15.
Thanks!!


(Jochen) #4

While Log4j 1.2 doesn’t support merging configuration files, you can use Java system properties in your log4j.properties file.

See https://wiki.apache.org/logging-log4j/SystemPropertiesInConfiguration and https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PropertyConfigurator.html for details.


(David) #5

Thanks for your reply. If I update log4j to the last version 2.8.2, it would be easier? I’m considering update log4j to this version…

Thanks again!!


(Jochen) #6

If you have access to the source code of the application and can make modifications to it, you can read configuration properties from any file using any logging framework.


(David) #7

Ok, thanks very much!!!

Regards.


(system) #8

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.