当前位置: 代码迷 >> 综合 >> Logger.getLogger(LogTestAction.class)为什么一定要加载一个类
  详细解决方案

Logger.getLogger(LogTestAction.class)为什么一定要加载一个类

热度:50   发布时间:2024-01-05 03:33:49.0

不是一定要加载一个类,但是加载一个类也是有好处的。如果类有了包声明后,在log4j的配置文件中,可以声明属于某个包下的类用什么方式来显示日志,或只显示某个包下的类的日志。

 

这个方法的源码是:

 

  /*** Retrieve a logger named according to the value of the* <code>name</code> parameter. If the named logger already exists,* then the existing instance will be returned. Otherwise, a new* instance is created.  ** <p>By default, loggers do not have a set level but inherit it* from their neareast ancestor with a set level. This is one of the* central features of log4j.** @param name The name of the logger to retrieve.  */staticpublicLogger getLogger(String name) {return LogManager.getLogger(name);}/*** Shorthand for <code>getLogger(clazz.getName())</code>.** @param clazz The name of <code>clazz</code> will be used as the* name of the logger to retrieve.  See {@link #getLogger(String)}* for more detailed information.*/staticpublicLogger getLogger(Class<?> clazz) {return LogManager.getLogger(clazz.getName());}

  

 

  相关解决方案