Logging per category like log4j

xuanbao · · 456 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hi there, I have been searching a lot, but I haven&#39;t found any logging library that allows me to set different logging levels for different packages. I mean. For example, I want to set my program level to debug, as I develop it, but perhaps, I would also want to a library/package that I use, that of course would use the same logging library, set temporary to debug, to see what happens. Other libraries/packages using the same logging library, should log anything, as I didn&#39;t enable them. This is just like Java&#39;s log4j or Python&#39;s logging work. Of course, the logging library should have multiple types of outputs/appenders, be configurable programatically/from a file, and be thread safe. There are so much logging libraries for golang, but none of them do this...</p> <hr/>**评论:**<br/><br/>recurrency: <pre><p>I like <code>go-kit/log</code>. </p> <p>The <code>Logger</code>-interface is just alternating key values: <code>log.Log(keyvals ... interface{})</code>. </p> <p>With the <code>log.With(logger, keyvals ... interface{})</code> function you can pass in your logger and prepend it with a relevant kv such as level, timestamp, component etc</p></pre>dvln: <pre><p>I wrote a package a while back you might want to check out, github.com/dvln/out is the name. It has leveled logging, can manage a couple of writers (screen and log file for instance with independent output level controls, thread safe, and one can flip on log levels based on file name or even routine within a file... although I tend to use those via env control when I want to do that). Regardless, you can modify further as needed...</p></pre>rauyran: <pre><p>juju&#39;s logging package has module level control</p> <p><a href="https://github.com/juju/loggo" rel="nofollow">https://github.com/juju/loggo</a></p></pre>dazzford: <pre><p>If you have a need for those things, then build them or add PRs for those features.</p> <p>I’m not aware of any lib that has them.</p> <p>Go is not JAVA and it shouldn’t be.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

456 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传