Java Logger和System.out.println之间有什么区别 [英] What is the difference between Java Logger and System.out.println

查看:237
本文介绍了Java Logger和System.out.println之间有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了关于记录器类的api(这里)我正在查看 Logger.info 方法。当我看到它的边界显示为字符串 public void info(String msg)时,我很困惑,它与 System.out.println相同()。我想知道这两者之间有什么不同,为什么我们使用Logger代替 System.out.println ,当他们打印出相同的东西时。

I looked up the api about the logger class(here) and I was looking at the Logger.info method. I was confused when I saw its perimeter as a message displayed as a string public void info(String msg) which is same as System.out.println(). I am wondering what is the different between these two, and why do we use Logger instead of System.out.println when they can print out the same thing.

在Logger中。

Logger.info(你好)

输出:

[INFO ] 2015-08-07 11:18:46.140 [main] ClassName Hello

System.out.println

`System.out.println(你好)

`System.out.println("Hello")

输出:
你好

推荐答案

通常,因为可以将 Logger 配置为写入文件(和控制台)。它也可以在更高(或更低)的粒度上配置消息传递。例如,您可以配置(在运行时) warn 的级别。在这种情况下,该looger不会显示 debug info 消息。它可以包括诸如正在写的类,行号以及(消息的)日期和时间等信息。

Usually, because a Logger can be configured to write to a file (and the console). It might also be configured at higher (or lower) granularity as to messaging. For example, you might configure (at runtime) for level of warn. In which case, that looger would not display debug or info messages. It can include information such as the class that is writing, a line number, and a date and time (of the message).

这篇关于Java Logger和System.out.println之间有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆