This post is a minimal howto for log4j version 1.
What a simple task ! but who never search a simple sample on the web send a little stone to me ;)
Feel free to copy paste anyway ;))
What are the dependencies
You will need to add log4j, slf4j and lombok (to use @Slf4j) :
How to use it
Simply add "@Slf4j" to your class, and then you could use "log" as logger.
How to configure appenders
To configure log4j, add a
log4j.propertiesfile to your resources. Start by defining a console appender. This appender should appear in the rootLogger definition too. You could define the following content to start:
How to configure file appender
Update your rootLoger to refer to the logfile appender, and add a logfile appender definition:
How to configure graylog (splunk-like) appender
Update your rootLoger to refer to the graylog appender, and add a gelf appender definition:
How to configure NT event appender
Pre-requisites : add
NTEventLogAppender.amd64.dllto the current directory or to the java ld library path. You could append "
-Djava.library.path=PATH" to your application if needed. Get this dll files from log4j zip distribution doc : https://wiki.apache.org/logging-log4j/NTEventLogAppender
Update your rootLoger to refer to the ntappender appender, and add a new ntappender definition:
For this last usecase you will be able to see the app logs into Windows Event Log service :