What is the easiest way to get started with log4j configuration?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
In case you stumble into this and are looking for a sample file for log4j2. The way I got it to work was to create a file names log4j2.xml in the base 'resources' directory (I'm using maven so that was 'src/main/resources')
Then copy the sample configuration from the manual: http://logging.apache.org/log4j/2.x/manual/configuration.html
This will give you a nice simple console logger. I recommend you modify the pattern to how you want it to look and the 'Root level=' to something more inclusive. And of course, read the manual for more powerful settings...
In addition to some other answers, I would add a persistence appender since that's the greatest advantage of using logs over consoles and debuggers; when one can't run through the application code in real-time or the event already occurred.
!/"path"/"filename" will write to root of filesystem. "path"/"filename" will write to path relative to classpath root.
Put a file named
log4j.properties
in the root of your classpath:Nothing else is needed. Log4j will discover it and configure itself.
The absolute easiest way is to visit the log4j pages at apache and read the short introduction. They have a sample log4j.configuration ready to be copied and pasted.
It's worth reading the manual (at the risk of stating the obvious). There are a ton of configuration options, and once you learn and understand what's possible, then you can implement some very powerful logging systems.