apache common logging也是一个比较有名的log包。其实它只是简单封装了一些现有的log框架。
1. 只是一个框架
2. 如果有 commons-logging.properties 配置文件, 可以用它来配置使用哪个框架,以及各个框架的优先级
3. 如果没有上述文件,会搜索系统中现在的日志框架,优先是log4j, 然后是 jdk 的logger
4. 如果连jdk logger都没有,可以使用自带的 simplelog, 将所有的Log实例的日志输出到 System.out中
java -D
org.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog ...
如果使用jdk的logger,可以建logging.properties文件,在里面进行配置,例子如下:
# handlers
handlers=java.util.logging.FileHandler, java.util.logging.ConsoleHandler
# general level
# 7个级别,从高到低分别为:SEVERE,WARNING,INFO,CONFIG,FINE,FINER,FINEST 还可以为ALL和OFF
.level=INFO,比设置低的将不输出
# file handler
java.util.logging.FileHandler.pattern = %h/java%u.log
java.util.logging.FileHandler.limit = 50000
java.util.logging.FileHandler.count = 1
java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter
java.util.logging.FileHandler.append = true
# console handler
java.util.logging.ConsoleHandler.level = FINEST
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
test.de.jayefem.log4e.logkits.JDK1_4_Logging.level = FINEST
可以参考 jre/lib 下的同名文件。
代码里:
static Log log = LogFactory.getLog(this.class); //作为类的静态成员
log.info("...");
log.debug("");
一般来说,要用debug,应将level设为 fine 以下。
附:
- java.util.logging.FileHandler.level specifies the default level for the
Handler (defaults to Level.ALL).
- java.util.logging.FileHandler.filter specifies the name of a Filter
class to use (defaults to no Filter).
- java.util.logging.FileHandler.formatter specifies the name of a
Formatter class to use (defaults to
java.util.logging.XMLFormatter)
- java.util.logging.FileHandler.encoding the name of the character set
encoding to use (defaults to the default platform encoding).
- java.util.logging.FileHandler.limit specifies an approximate maximum amount
to write (in bytes) to any one file. If this is zero, then there is no limit.
(Defaults to no limit).
- java.util.logging.FileHandler.count specifies how many output files to cycle
through (defaults to 1).
- java.util.logging.FileHandler.pattern specifies a pattern for generating the
output file name. See below for details. (Defaults to "%h/java%u.log").
- java.util.logging.FileHandler.append specifies whether the FileHandler
should append onto any existing files (defaults to false).
A pattern consists of a string that includes the following special components
that will be replaced at runtime:
- "/" the local pathname separator
- "%t" the system temporary directory
- "%h" the value of the "user.home" system property
- "%g" the generation number to distinguish rotated logs
- "%u" a unique number to resolve conflicts
- "%%" translates to a single percent sign "%"
分享到:
相关推荐
C# Logger 是按照 Apache 的 log4j 项目设计的。它是一个日志工具,可以用来将事件如调试、信息、警告和错误信息写到 Windows 事件日志中。
Orhan Obut 大神分享的一开源项目Logger输出日志,非常好用,该开源库能够把: 线程的信息 类的信息 方法的信息 格式打印json、xml等 点击链接跳转到源码打印处 此外还可根据自己需求进行定制化,并且还可日志输出...
Apache Log4j_1.2.17 完整依赖包,在jdk1.8.201中测试通过。使用教程https://www.tutorialspoint.com/springmvc/springmvc_log4j.htm
The type org.apache.tools.ant.Task cannot be resolved. It is indirectly referenced from required .class files错误....., 解决办法:在工程中加入此jar包
NULL 博文链接:https://wait7758521.iteye.com/blog/1933964
日志类jar包 所属apache分类下 log4j-1.2.17!!!
编年史记录器支持大多数标准记录API,包括: SLF4J 退回Apache log4j 1.2 Apache log4j 2 Java Util记录Apache通用日志记录Chronicle Logger能够将您的所有日志聚合到中央存储。 它具有内置的弹性,因此您将永远...
在 Java 中发送 GET 和 POST 请求是非常常见的操作,今天我们将通过使用 Apache HttpClient 库来实现这些操作。 什么是 Apache HttpClient 库? Apache HttpClient 库是 Apache 软件基金会提供的一个开源库,用于...
log4j.rootLogger = INFO,A1 log4j.addivity.org.apache=true log4j.logger.com.ibatis = ERROR log4j.logger.com.ibatis.common.jdbc.SimpleDataSource = ERROR #log4j.logger....
用于OPC的ogamma Visual Logger是用于以下目的的集成工具: 使用其他包装应用程序从OPC UA服务器以及经典OPC DA服务器收集数据; 存储在时间序列数据库中的数据: TimescaleDB (为存储时间序列数据而优化的...
实际使用:static Logger logger = Logger.getLogger (ServerWithLog4j.class.getName ()) ; 2、 读取配置文件: 获得了Logger的实例之后,接下来将配置Log4j使用环境: 语法表示: BasicConfigurator...
注意:您可能想查看 ,它将它实现为一个 Apache 模块。 注意:请参阅以获得更先进的示例。 它使用 inotify 来监视文件,而不是潜在地在 Logging 中阻塞 Web 服务器。 概括 旨在从 Apache CustomLog 管道配置运行的 ...
org.apache.tools.ant.DefaultLogger org.apache.tools.ant.Diagnostics$1 org.apache.tools.ant.ExitException org.apache.tools.ant.PathTokenizer org.apache.tools.ant.ProjectHelper org.apache.tools.ant...
ansible-logger在MySQL数据库中(使用ansible回调)将结果和ansible运行的事实存档。 它带有易于使用且响应Swift的Web界面。 它可以作为“嵌入式”日志记录解决方案-您无需以任何方式修改现有的剧本就可以使用它! ...
1.log4j:WARNNoappenderscouldbefoundforlogger(org.apache.hadoop.util.Shell). 2.log4j:WARNPleaseinitializethelog4jsystemproperly. 3.log4j:WARNSeehttp://logging.apache.org/log4j/1.2/faq....
可是现在的开源项目都使用的是 log4j,log4j 已经成了事实上的标准,但由于又有一部分开发者在使用 sun logger,因此 apache 才推出 commons-logging,使得我们不必关注我们正在使用何种日志工具。
用于Log4j,apache Logger打印堆栈信息 由于网上没这一部分信息,自己就把它写出来了 其实也就短短几句代码 在捕捉异常的时候使用该类即可
Logger ( os . Stderr )) 如果要轮换日志等,则需要替换目标,因此应保留ApacheLog结构: l := & ApacheLog {} l . LogFormat = logformat . CombinedLog . Clone () l . LogFormat . SetOutput ( dst ) e . Use ( ...
Mougrim记录器端口Yii 2扩展此扩展提供了在Yii 2 Framework中使用 (来自 Logger)的功能。 该扩展提供了所有期望分析的日志。好处具有下一个优点: 灵活的配置; 类似于Apache log4php的界面(具有调试日志级别);...