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:

example.go

nxlog4go Log Levels and Pattern Layout的更多相关文章

  1. [Javascript] Log Levels and Semantic Methods

    Go beyond console.log by learning about log levels, filtering log output and structuring your output ...

  2. Jmeter-Maven-Plugin高级应用:Log Levels

    Log Levels Pages 12 Home Adding additional libraries to the classpath Advanced Configuration Basic C ...

  3. Log4j2进阶使用(Pattern Layout详细设置)

    1.进阶说明 通过配置Layout打印格式化的日志, Log4j2支持很多的Layouts: CSV GELF HTML JSON Pattern Serialized Syslog XML YAML ...

  4. FPC Trace Pattern Layout Design Notices (軟板線路設計注意事項)

    整理了一些軟板(FPCB/Flex Cable)製造廠關於線路設計的要求 (Design Guide)以避免應用上的品質問題. 1.Relationship between Through Hole, ...

  5. nxlog4go 按天或按文件大小分割日志

    Building a new rotate file writer: rfw := l4g.NewRotateFileWriter("_rfw.log").SetMaxSize(1 ...

  6. 在idea中如何添加log日志

    1.首先下载log4的jar包,官方路径为:http://www.apache.org/dyn/closer.cgi/logging/log4j/1.2.17/log4j-1.2.17.zip 2.下 ...

  7. log实例

    配置详解见2014.10月篇 log4j的pom.xml <dependency> <groupId>log4j</groupId> <artifactId& ...

  8. LogBack log出力路径

    转自:http://blog.csdn.net/z69183787/article/details/30284391 请看下面这段配置,这是无法工作的: <?xml version=" ...

  9. Logback Pattern

    Logback日志配置示例 <appender name="SYSLOG" class="ch.qos.logback.classic.net.SyslogAppe ...

随机推荐

  1. Python-Blog1-搭建开发环境

    注:本系列是根据廖雪峰python实战过程,详情可见(https://www.liaoxuefeng.com/) 环境准备 Python 版本:Python 3.X,查看python版本python ...

  2. php等比例压缩图片

    <?php function resizeImage($im,$maxwidth,$maxheight,$name,$filetype) { $pic_width = imagesx($im); ...

  3. 解决页面引用百度地图API设置点的logo不显示问题

    在写css时需要引用一个百度的api地图,却发现设置点的logo图片不能显示,后查阅百度测试发现是图片路径的问题: 在引用的下载的html页面找到 var icon = new BMap.Icon 将 ...

  4. 怎么查看mysql的安装目录

    如果忘记了MySQL的安装目录,怎么快速找到呢?方法或许很多,作者觉得这种最方便了 环境:windows+mysql+navicat 方法:进入mysql命令行输入:show variables li ...

  5. web技术发展历程--读《大型网站技术架构_核心原理与案例分析》

    1 早期的web服务 2 CGI程序的出现.发展.凋零到MVC的兴起 CGI:通用网关接口技术. 随着CGI技术的出现,web服务端可以通过不同的用户请求产生动态页面内容. web服务器将请求数据交给 ...

  6. 【SqlServer系列】浅谈SQL Server事务与锁(上篇)

    一  概述 在数据库方面,对于非DBA的程序员来说,事务与锁是一大难点,针对该难点,本篇文章视图采用图文的方式来与大家一起探讨. “浅谈SQL Server 事务与锁”这个专题共分两篇,上篇主讲事务及 ...

  7. 02_HTML5+CSS3详解第五、六天(实战篇之HTML5制作企业网站)

    [废话连篇 - 实战篇,没什么好说的,最后一章兼容性问题懒得看了,over] Details 一.Xmind部分 xmind教程:http://www.jianshu.com/p/7c488d5e4b ...

  8. CentOS7修改主机名(hostname)

    Linux中的hostname在大多数应用中至为重要,例如有些应用强制使用主机名称而不能使用IP地址,如果默认主机名称都为localhost.localdomain 的话那一定会出现问题,而且看起来也 ...

  9. 【转】shell学习笔记(四)——条件测试

    1 test 条件检测 当我要检测系统上面某些文件或者是相关的属性时,利用 test 这个命令来工作真是好用得不得了, 举例来说,我要检查 /home/oracle/zy是否存在时,使用: test ...

  10. php之插入排序

    <?phpfunction insertSort($arr) {  //插入排序    $len = count($arr);    for($i=1;$i<$len;$i++){     ...