3 回答
TA贡献1829条经验 获得超9个赞
log4go 没有很好的文档,我在原始存储库中找到了一些文档。
如果可以的话,我会使用不同的库,例如logrus,它有更好的文档、示例并且正在积极开发中。
TA贡献2011条经验 获得超2个赞
这是一个可以有两个日志的示例:
{
"console": {
"enable": true,
"level": "ERROR"
},
"files": [{
"enable": true,
"level": "DEBUG",
"filename":"./log/sys.log",
"category": "syslog",
"pattern": "[%D %T] [%L] (%S) %M",
"rotate": true,
"maxsize": "5M",
"maxlines": "10K",
"daily": true
},
{
"enable": true,
"level": "INFO",
"filename":"./log/market.log",
"category": "marketlog",
"pattern": "[%D %T] [%L] (%S) %M",
"rotate": false,
"maxsize": "10M",
"maxlines": "20K",
"daily": false
}
]
}
代码中的用法:
log4go.LOGGER("syslog").Info("...")
log4go.LOGGER("marketlog").Debug("...")
在这种情况下不会写入 marketlog 上的调试调用,因为“INFO”级别会自动将其过滤掉。
TA贡献1839条经验 获得超15个赞
简单的方法是使用 logConfig xml,例如:
<code>
<logging>
<filter enabled="true">
<tag>stdout</tag>
<type>console</type>
<!-- level is (:?FINEST|FINE|DEBUG|TRACE|INFO|WARNING|ERROR) -->
<level>INFO</level>
</filter>
<filter enabled="true">
<tag>file</tag>
<type>file</type>
<level>INFO</level>
<property name="filename"><log file Path></property>
<!--
%T - Time (15:04:05 MST)
%t - Time (15:04)
%D - Date (2006/01/02)
%d - Date (01/02/06)
%L - Level (FNST, FINE, DEBG, TRAC, WARN, EROR, CRIT)
%S - Source
%M - Message
It ignores unknown format strings (and removes them)
Recommended: "[%D %T] [%L] (%S) %M"
-->
<property name="format">[%D %T] [%L] (%S) %M</property>
<property name="rotate">true</property> <!-- true enables log rotation, otherwise append -->
<property name="maxsize">10M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 -->
<property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands -->
<property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight -->
<property name="maxbackup">10</property> <!-- Max backup for logs rotation -->
</filter>
</logging>
- 3 回答
- 0 关注
- 180 浏览
添加回答
举报