Log4j - Looking for a good 'Getting started

2019-02-10 05:43发布

I downloaded Log4j version 1.2.16 today. I want to enable logging in a simple java console application. I'm looking for a 'quick start' tutorial or blog that allows me to perform file logging with some good code samples.

2条回答
仙女界的扛把子
2楼-- · 2019-02-10 06:25

Please see whether this "How to integrate log4j with Java project" helps you. It takes you through 5 quick steps.

  • Set up the project with log4j
  • Create log4j.properties file
  • Write a class to record log messages
  • Compile and run program
  • Check the log messages

Even though the question is older, as you have asked for a tutorial or a blog post on how to get started quickly, I thought of sharing this.

查看更多
Anthone
3楼-- · 2019-02-10 06:28

The short introduction to log4j is a perfectly fine starting point for log4j.

If you're ready to spend some money, you can buy the log4j manual.

By the way, if you're new to logging in Java, I'd suggest the slf4j + logback combo. In my opinion, this is the best logging solution available. Slf4j is a logging "facade" and it needs an implementation underneath. Log4j and logback can be used as implementations.

Since logback is log4j's successor and made by the same author, I'd suggest using it instead. Not only that, logback's manual is available online and it's free.

Since log4j's development has more or less stalled, I'd suggest you upgrade to slf4j + logback.

查看更多
登录 后发表回答