英文:
Is it possible to log to different location for different kind of logs using log4go?
问题
我注意到log4go
有一个filter
机制,但它是基于level
的。也就是说,高于某个级别的日志会被发送到特定的filter
中。我想要实现的是,例如,我们有两种类型的日志,sheep
和goat
,每种类型都有DEBUG
、INFO
等所有级别的日志,sheep
类型的日志发送到sheep.log
,goat
类型的日志发送到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".
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论