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. CentOS 7安装Tomcat8

    一.安装环境 tomcat的安装依赖于Java JDK,需要先安装配置正确的JDK http://www.cnblogs.com/VoiceOfDreams/p/8376978.html 二.安装包准 ...

  2. 通过psping测试结果,初步判断远端服务器的状态

    1.psping的输出结果为如下正常显示时,说明远端服务器的IP及端口可用 C:\Users\he.liming>psping 139.219.66.205:4352 PsPing v2.10 ...

  3. CSS深入理解学习笔记之relative

    1.relative和absolute的相煎关系 限制作用:①限制left/top/right/bottom定位:②限制z-index层级:③限制在overflow下的嚣张气焰. relative和f ...

  4. linux 中 ping的回传值

      今天在学习鸟哥私房菜的过程中,不明白ping的回传值是怎么设置的,后来网上找的结果了,特此记录一下 1 题目大意是指,ping一个网段的机器,如果可以通,就显示UP,如果不通就显示Down,其中一 ...

  5. 在nagios中使用python脚本监控linux主机

    在被监控端192.168.5.1101.先把getload.py放到/usr/local/nagios/libexec内[root@nhserver1 ~]# vim /usr/local/nagio ...

  6. 循环while 、do…while 、for

    循环while .do-while .for 循环结构的选择? - 当对一个条件进行一次判断时,用if语句: - 当对一个条件进行多次判断时,用while语句: 1.While 循环条件成立就会执行循 ...

  7. Sql Server的艺术(五) SQL UNION与UNION JOIN运算符

    学习本节所用表: CREATE TABLE TEACHER ( ID INT IDENTITY (,) PRIMARY KEY , --主键,自增长 TNO INT NOT NULL, --教工号 T ...

  8. jQuery中的DOM操作------复制及包裹节点

    1.复制节点: 如果单击<li>元素后需要再复制一个<li>元素,可以用clone()方法来完成: $(this).clone().appendTo("ul" ...

  9. javase学习小结二

    三角函数方法 Math.sin(radians):Math.sin(Math.PI/6)=0.5 Math.cos(radians):Math.cos(Math.PI/3)=0.5 Math.tan( ...

  10. C#将图片背景从透明变成白色

    var img = System.Drawing.Image.FromStream(ms); int width = img.Width; int height = img.Height; var x ...