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:

example.go

原文地址:https://www.cnblogs.com/ccpaging/p/8491023.html

时间: 2024-10-13 21:22:39

nxlog4go Log Levels and Pattern Layout的相关文章

Java Logging: Log Levels

Table of Contents Filtering Messages When a message is logged via a Logger it is logged with a certain log level. The built-in log levels are: SEVERE WARNING INFO CONFIG FINE FINER FINEST The log level is represented by the class java.util.logging.Le

[Javascript] Log Levels and Semantic Methods

Go beyond console.log by learning about log levels, filtering log output and structuring your output to be meaningful and concise. The JavaScript console object offers many methods to make your life easier - start learning them here! console.log("thi

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

Log Levels Pages 12 Home Adding additional libraries to the classpath Advanced Configuration Basic Configuration Configuring the jvm that the jmeter process runs in FAQ Log Levels Modifying Properties Proxy Configuration Remote Server Configuration S

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

整理了一些軟板(FPCB/Flex Cable)製造廠關於線路設計的要求 (Design Guide)以避免應用上的品質問題. 1.Relationship between Through Hole, Land, Cover Film, and Cover Coat   Not Recommended(不建議) Recommended(建議)       通孔的焊墊必須用Cover film 覆蓋住,以避免使用時剝落.       2. Circuit Pattern Guidance    

LogBack log出力路径

转自:http://blog.csdn.net/z69183787/article/details/30284391 请看下面这段配置,这是无法工作的: <?xml version="1.0" encoding="UTF-8" ?> <configuration> <contextName>JTheque</contextName> <appender name="FILE" class=&q

logback:logback和slf4j中的:appender、logger、encoder、layout

(1)appender 1.appender标签是logback配置文件中重要的组件之一.在logback配置文件中使用appender标签进行定义.可 以包含0个或多个appender标签. 2.appender主要作用就是:①控制打印日志的地方.②打印日志的输出格式. 3.appender语法结构: 1)属性:appender标签中包含两个强制需要的属性:①name.②class ①name:为这个appender起一个唯一标识的名称.与appender-ref中的值相对应.以引用appen

Logstash中grok pattern

USERNAME [a-zA-Z0-9_-]+ USER %{USERNAME} INT (?:[+-]?(?:[0-9]+)) BASE10NUM (?<![0-9.+-])(?>[+-]?(?:(?:[0-9]+(?:\.[0-9]+)?)|(?:\.[0-9]+))) NUMBER (?:%{BASE10NUM}) BASE16NUM (?<![0-9A-Fa-f])(?:[+-]?(?:0x)?(?:[0-9A-Fa-f]+)) BASE16FLOAT \b(?<![0-9

在idea中如何添加log日志

1.首先下载log4的jar包,官方路径为:http://www.apache.org/dyn/closer.cgi/logging/log4j/1.2.17/log4j-1.2.17.zip 2.下载完成后,把jar包导入到idea中,参考文档:http://jingyan.baidu.com/article/fec7a1e5f79e2b1191b4e74f.html 3.之后参考log4使用教程,参考链接:http://www.codeceo.com/article/log4j-usage.

log实例

配置详解见2014.10月篇 log4j的pom.xml <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> log4j.properties ### direct log messages to stdout ### log4j.appender