0

I have a command line application and my client needa the debugging information in the command line. I would like to add the debugging information using System.out.println, as in

System.out.println("message");

Is this good programming practice? Otherwise, what would be a better option?

4

1 回答 1

4

Instead of System.out.println(), use a logging framework.

There are several logging frameworks that are used for Java projects. Log4J is probably the most well-known and popular one. My first choice would be SLF4J, which is actually not a logging framework itself, but a layer which you use to which you can plug-in different logging frameworks (such as Log4J or Logback).

There's also a standard logging framework in the standard Java API, in the package java.util.logging, but in my experience it isn't very popular.

Advantages of using a logging framework instead of System.out.println() calls are that you can easily configure the logging to write to a file or some other storage instead of to the console, and that you can use different logging levels for debugging, warnings, and errors, and you can choose what level of log output you want to get.

于 2013-05-30T12:08:00.827 回答