简单好用的Log工具

Simple Log was written out of frustration with other "logging frameworks". Many of its features are designed to contrast with the way in which these frameworks are used. Because of this, it seemed sensible to show a comparison between Simple Log and one of these frameworks so that you can see the difference before committing to using Simple Log in your own code. I have chosen Log4J for the comparison, as this is undoubtedly the most widely used logging framework.

这个log软件很简单,只有三个class.
半个小时就可以基本学会使用。

https://simple-log.dev.java.net/

tips:

Creating a Logger

private static final SimpleLogger log = new SimpleLogger(Test.class);

Given no configuration file, Simple Log produces no output. This is a feature that allows you to easily have zero output in deployment if desired.
The default output of a Simple Log text log message is shown below.
Thu 2006/02/09 08:38:11.269| |main|Test|Plain message

Type of Output

log.entry("main()");
log.info("Plain message");
log.infoObject("object", new Object());
log.errorException(new Exception("Test Exception"));
log.exit("main()");


Above is the code used to produce the below output.

Thu 2006/02/09 08:38:11.269|>>>|main|Test|main() Thu 2006/02/09 08:38:11.269| |main|Test|Plain message Thu 2006/02/09 08:38:11.269|---|main|Test|object|java.lang.Object@bf2d5e Thu 2006/02/09 08:38:11.269|***|main|Test|java.lang.Exception: Test Exception java.lang.Exception: Test Exception at test.Test.main(Test.java:52) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90) Thu 2006/02/09 08:38:11.279|<<<|main|Test|main()

Logging to a File

To log to a file using Simple Log, simply specify the name of the file with the simplelog.logFile property.

simplelog.logFile = application.log

Log File Rolling

simplelog.logFile=application.log
simplelog.rollover=timeOfDay
simplelog.rollover.timeOfDay.time=02:00
simplelog.rollover.timeOfDay.timezone=GMT+10:00

Instance-Based Logging



public class TreeNode {
 private final SimpleLogger log;
 public TreeNode(String name) {
   log = new SimpleLogger(TreeNode.class, name);
 }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值