nxlog4go Log Levels and Pattern Layout
Log levels
nxlog4go provides log levels as below:
type Level int
const (
FINEST Level = iota
FINE
DEBUG
TRACE
INFO
WARNING
ERROR
CRITICAL
_SILENT_ = 100
)
// Strings
var (
levelStrings = [...]string{"FNST", "FINE", "DEBG", "TRAC", "INFO", "WARN", "EROR", "CRIT", "OFFL"}
)
DEBUG - WARNING, are more useful.
ERROR, may cause the program exited.
CRITICAL, may crash the program.
_SILENT_, used during configuration to turn in quiet mode. It is used in loglog (internal logger) and set as default.
Setting filter level
var log = l4g.New(l4g.DEBUG)
Setting the log level when build a logger.
log.SetLevel(l4g.WARNING)
Setting the output level for the logger. Any log's level which is lower then WARNING should be ignored.
SetXXX functions in nxlog4go always return a point, so it is chainable. For example:
var log = l4g.New(l4g.DEBUG).SetPrefix("example").SetPattern("[%T %D %Z] [%L] (%P:%s) %M\n")
Pattern layout
- Pattern codes
// %N - Time (15:04:05.000000)
// %T - Time (15:04:05)
// %t - Time (15:04)
// %Z - Zone (-0700)
// %z - Zone (MST)
// %D - Date (2006/01/02)
// %Y - Date (2006-01-02)
// %d - Date (01/02/06)
// %L - Level (FNST, FINE, DEBG, TRAC, WARN, EROR, CRIT)
// %l - Level
// %P - Prefix
// %S - Source
// %s - Short Source
// %n - Line number
// %M - Message
// %R - Return (\n)
// Ignores unknown formats
- Some default patterns
var (
PATTERN_DEFAULT = "[%D %T %z] [%L] (%s:%n) %M\n"
PATTERN_SHORT = "[%t %d] [%L] %M\n"
PATTERN_ABBREV = "[%L] %M\n"
PATTERN_JSON = "{\"Level\":%l,\"Created\":\"%YT%N%Z\",\"Prefix\":\"%P\",\"Source\":\"%S\",\"Line\":%n,\"Message\":\"%M\"}"
)
- Setting pattern
log.SetPattern("[%T %D %Z] [%L] (%P:%s) %M\n")
"\n" is byte 0x13. "%R" is same and always used in configuration.
Or:
log.SetPattern(PATTERN_JSON)
PATTERN_JSON encode the log to JSON format. It is 2x faster than JSON encoder.
- Output like
[22:48:35 2018/03/01 +08:00] [INFO] (example:example.go) The time is now: 22:48:35 CST 2018/03/01
[22:48:35.248443 2018/03/01 CST] [INFO] (prefix1:example.go) The time is now: 22:48:35 CST 2018/03/01
[14:48:35 2018/03/01 +08:00] [INFO] (example:example.go) Using UTC time stamp. Now: 22:48:35 CST 2018/03/01
[22:48:35 2018/03/01 +08:00] [INFO] (example:example.go) Using local time stamp. Now: 22:48:35 CST 2018/03/01
- Setting UTC time zone
log.Layout().Set("utc", true)
Example
See also:
nxlog4go Log Levels and Pattern Layout的更多相关文章
- [Javascript] Log Levels and Semantic Methods
Go beyond console.log by learning about log levels, filtering log output and structuring your output ...
- Jmeter-Maven-Plugin高级应用:Log Levels
Log Levels Pages 12 Home Adding additional libraries to the classpath Advanced Configuration Basic C ...
- Log4j2进阶使用(Pattern Layout详细设置)
1.进阶说明 通过配置Layout打印格式化的日志, Log4j2支持很多的Layouts: CSV GELF HTML JSON Pattern Serialized Syslog XML YAML ...
- FPC Trace Pattern Layout Design Notices (軟板線路設計注意事項)
整理了一些軟板(FPCB/Flex Cable)製造廠關於線路設計的要求 (Design Guide)以避免應用上的品質問題. 1.Relationship between Through Hole, ...
- nxlog4go 按天或按文件大小分割日志
Building a new rotate file writer: rfw := l4g.NewRotateFileWriter("_rfw.log").SetMaxSize(1 ...
- 在idea中如何添加log日志
1.首先下载log4的jar包,官方路径为:http://www.apache.org/dyn/closer.cgi/logging/log4j/1.2.17/log4j-1.2.17.zip 2.下 ...
- log实例
配置详解见2014.10月篇 log4j的pom.xml <dependency> <groupId>log4j</groupId> <artifactId& ...
- LogBack log出力路径
转自:http://blog.csdn.net/z69183787/article/details/30284391 请看下面这段配置,这是无法工作的: <?xml version=" ...
- Logback Pattern
Logback日志配置示例 <appender name="SYSLOG" class="ch.qos.logback.classic.net.SyslogAppe ...
随机推荐
- Maven1-HelloWorld简单入门
编写POM(Project Object Model) Maven项目的核心是pom.xml,它定义了项目的基本信息,用于描述项目如何构建,声明项目依赖 创建文件夹,名称为hello-world 创建 ...
- 搞个小项目吧,做一个ppt播放器
先来两个参考链接,接下来再进行实战 http://www.geek-workshop.com/forum.php?mod=viewthread&tid=1137 http://www.geek ...
- java面向对象的三大特性——继承
ul,ol { margin: 0; list-style: none; padding: 0 } a { text-decoration: none; color: inherit } * { ma ...
- JS中数组的常用方法
首先,在开始前我们先了解一下什么是数组. 1.什么是数组? 数组就是一组数据的集合,其表现形式就是内存中的一段连续的内存地址,数组名称其实就是连续内存地址的首地址.说白了它就是将一堆数据按照一定的顺序 ...
- 计算器(Ext)
<html> <head> <title>计算器</title> <meta charset="UTF-8"> < ...
- MySql按日期进行统计
1 数据库字段pk_time(Varchar) 当天的数据 SELECT * FROM 表 WHERE date(fk_time) = curdate(); 当月的数据 SELECT *FROM 表 ...
- 04_Javascript初步第二天(下)
错误对象 try{ aa();//这是一个未被定义的方法 }catch(e){ alert(e.name+":"+e.message);//输出:ReferenceError:aa ...
- 第一章 C++基本认识
1.使用visual studio时让程序暂停,在return前加上这个: char response; std::cin >> response; 2.c++程序开发流程 3.变量名的命 ...
- 通过重写 class 的 ToString() 来简化获取 enum 的 DescriptionAttribute 值
通过重写 class 的 ToString() 来简化获取 enum 的 DescriptionAttribute 值 目录 一.常见的 enum 类型 二.演变:class 版本的 enum 类型 ...
- 从jvm源码看synchronzied
synchronized的使用 synchronized关键字是Java中解决并发问题的一种常用方法,也是最简单的一种方法,其作用有三个:(1)互斥性:确保线程互斥的访问同步代码(2)可见性:保证共享 ...