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 ...
随机推荐
- banner无缝轮播【小封装】
转载:http://www.qdfuns.com/notes/23446/d1691a1edf5685396813cc85ae6ab10f.html 一直在重复的写banner,写了了好几个,然后每次 ...
- CentOS7.x机器安装Azure CLI2.0
安装Azure CLI 2.0的前提是:机器中必须有 Python 2.7.x 或 Python 3.x.如果机器中没有其中任何一个Python的版本,请及时安装 1.准备一台CentOS 7.3的机 ...
- linux_用户和组
linux用户分为3类: 超级用户:root, UID为0, GID为0 普通用户: 500 -65535, 由root创建 虚拟用户: 1-499 - 系统里傀儡,不能使用,固定存在,满足linux ...
- shell参数传递
应用实例: #!/bin/bash #运行:bash para_tran.bash text1.txt text2.txt #"set $1"设置存储传入的第一参数 #" ...
- Struts2是什么?
Struts2是什么: Struts2是整合了struts1和webwork的技术优点的使用广泛的MVC框架: Struts2的特点: 1.基于MVC框架,结构清晰,便于开发人员掌控开发流程: 2.使 ...
- JavaScript:事件对象Event和冒泡
本文最初发表于博客园,并在GitHub上持续更新前端的系列文章.欢迎在GitHub上关注我,一起入门和进阶前端. 以下是正文. 绑定事件的两种方式 我们在上一篇文章中已经讲过事件的概念.这里讲一下注册 ...
- 主备(keepalived+nginx)
实验环境 系统: centos 6.9 mini 机器名 ip 虚拟ip kn1 192.168.126.10 kn2 ...
- 命令行登陆mysql提示'mysql' 不是内部或外部命令
问题:命令行登陆mysql提示'mysql' 不是内部或外部命令.如图1所示. 图1 原因:没有将mysql的bin文件夹配置到环境变量里区,因为命令行登陆mysql需要调用bin下的mysql.ex ...
- 19_Python元组总结
元组 1 元组:不可变的容器,一旦初始化就不能更改,有索引:可以查,不能增,改,删除单个元素:可遍历,不能排序 2 当元组元素,只有一个的时候,需要在元素后加",",否则回当()运 ...
- Spring学习一
1.POJO和JavaBean的区别 POJO 和JavaBean是我们常见的两个关键字,一般容易混淆,POJO全称是Plain Ordinary Java Object / Pure Old Jav ...