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 ...
随机推荐
- ETL工具--kettle篇(17.10.09更新)
ETL是EXTRACT(抽取).TRANSFORM(转换).LOAD(加载)的简称,实现数据从多个异构数据源加载到数据库或其他目标地址,是数据仓库建设和维护中的重要一环也是工作量较大的一块.当前知道的 ...
- 使用“消息服务框架”(MSF)实现分布式事务的三阶段提交协议(电商创建订单的示例)
1,示例解决方案介绍 在上一篇 <消息服务框架(MSF)应用实例之分布式事务三阶段提交协议的实现>中,我们分析了分布式事务的三阶段提交协议的原理,现在我们来看看如何使用消息服务框架(MSF ...
- jdk源码->多线程->Thread
线程的创建 java提供了三种创建线程的方法: 通过继承 Thread 类本身: 通过实现 Runnable 接口: 通过 Callable 和 Future 创建线程. 继承Thread类 步骤: ...
- CentOS之7与6的区别
前言 centos7与6之间最大的差别就是初始化技术的不同,7采用的初始化技术是Systemd,并行的运行方式,除了这一点之外,服务启动.开机启动文件.网络命令方面等等,都说6有所不同.让我们先来了解 ...
- 第三方模块paramiko的使用
"Paramiko" is a combination of the Esperanto words for "paranoid" and "frie ...
- 什么是<!DOCTYPE html>
什么是<!DOCTYPE html>? 在HTML文档初,往往会有这么一句话<!DOCTYPE html>,那么它的意义是什么呢?它是html5标准网页声明,全称为Docume ...
- ansible playbook实践(一)-基础环境安装
1 介绍 Ansible 是一个系统自动化工具,用来做系统配管理,批量对远程主机执行操作指令. 2 实验环境 ip 角色 192.168.40.71 ansible管控端 192.168.40.72 ...
- JDBC为什么要使用PreparedStatement而不是Statement
PreparedStatement是什么? PreparedStatement是java.sql包下面的一个接口,用来执行SQL语句查询,通过调用connection.preparedStatemen ...
- bzoj 2627: JZPKIL [伯努利数 Pollard-rho]
2627: JZPKIL 题意:求 \[ \sum_{i=1}^n (n,i)^x [i,n]^y,\ [i,n] = lcm(i,n) \] \(n \le 10^{18},\ x,y\le 300 ...
- UVA概率练习[2]
UVa11021 Tribbles 你有K个麻球.一个只会存活一天.在死亡之前,一个麻球有P_i的概率生出i个麻球(i=0,1,…,n-1).m天后所有麻球都死亡的概率是多少?(包含在第m天前全部死亡 ...