使用log4go,是否可以将不同类型的日志记录到不同的位置?

huangapple go评论84阅读模式
英文:

Is it possible to log to different location for different kind of logs using log4go?

问题

我注意到log4go有一个filter机制,但它是基于level的。也就是说,高于某个级别的日志会被发送到特定的filter中。我想要实现的是,例如,我们有两种类型的日志,sheepgoat,每种类型都有DEBUGINFO等所有级别的日志,sheep类型的日志发送到sheep.loggoat类型的日志发送到goat.log。使用log4go能实现吗?

英文:

I noticed log4go has the filter mechanism. But it's based on level. That is, logs above certain level goes to certain filter. What I want to achieve is, for example, we have two types of logs, sheep and goat, each with all the levels DEBUG, INFO etc, log of type sheep go to sheep.log, log of type goat goes to goat.log. Is it possible using log4go?

答案1

得分: 1

直接来说,AddFilter(name string, lvl Level, writer LogWriter) 方法中设置的 Filter 结构体 只根据日志级别进行过滤,没有考虑“类型”。

如果你想要添加“类型”过滤,你需要扩展该过滤器。

英文:

Not directly, since the Filter struct which is set by AddFilter(name string, lvl Level, writer LogWriter) only filters on the log level, without consideration of "type".

You would have to extend that filter in order to add the "type".

huangapple
  • 本文由 发表于 2015年8月6日 13:58:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/31847846.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定