Whats your favorite log library?

agolangf · · 1066 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I came from Java and fell in love with log4j.</p> <p>i.e the class names and levels in the log entries etc</p> <p>Now I&#39;m looking for a nice go library, any suggestions?</p> <p>If you are going to say standard logger please include examples of how you use it please</p> <p>Edit: So it looks like logrus has the biggest following here,</p> <p>followed closely by log15</p> <hr/>**评论:**<br/><br/>tjholowaychuk: <pre><p><a href="https://github.com/Sirupsen/logrus">https://github.com/Sirupsen/logrus</a> is pretty nice, I&#39;d certainly recommend sticking with structured logging personally. I dislike the &#34;hooks&#34;, just because I think it&#39;s much more elegant write to stdio and ship the logs outside of the application, but whatever works :)</p></pre>diegobernardes: <pre><p>using logrus too, very good.</p></pre>ihsw: <pre><p>Another advocacy for logrus, it is excellent.</p></pre>nerr: <pre><p>logrus is great. The internal logging library at my workplace wraps it and removes all of the &#34;-f&#34; and &#34;-ln&#34; family of methods, so your only option is to add values to your logs as fields. We also made some small changes to reduce the verbosity of the logging calls:</p> <pre><code>log.Ctx(ctx).Err(err).KVs(log.F{ &#34;foo.id&#34;: 10, &#34;foo.name&#34;: &#34;bar&#34;, }).Error(&#34;error occurred while doing X&#34;) </code></pre> <p>The above adds information from a context and an error in predefined fields that we use throughout our codebase. Our logs are aggregated using rsyslog into ElasticSearch and Kibana.</p></pre>gmccue: <pre><p>+1 for logrus. I&#39;m a big fan. Hooks abound as well, so you can hook-in loads of services.</p></pre>naturalselection: <pre><p>glog</p></pre>nohoudini: <pre><p>glog too</p></pre>nilium: <pre><p>glog as well. Otherwise I just use the standard log package and point it at syslog.</p></pre>iyee: <pre><p>glog doesn&#39;t support rotating files by time, pity.</p></pre>tehbilly: <pre><p>I wish it let you set an io.Writer as the output, then you could just use lumberjack or whatever you&#39;d like.</p></pre>inconshreveable: <pre><p>I&#39;m biased, of course, but I&#39;m partial to <a href="https://github.com/inconshreveable/log15">https://github.com/inconshreveable/log15</a> and a number of other like it as well</p></pre>stuffsnout: <pre><p>by far my favorite library for logging</p></pre>inconshreveable: <pre><p>thank you! i&#39;d like to get back to improving it soon =)</p> <p>huge props go to cs-guy who was instrumental in making it even better</p></pre>shazow: <pre><p>I&#39;m a fan of <a href="https://github.com/alexcesaro/log" rel="nofollow">github.com/alexcesaro/log</a>.</p> <p>It&#39;s really simple and does exactly what I need. I&#39;ve used it for several projects with no disappointments and the author is very responsive. </p> <p>I wouldn&#39;t say it&#39;s strictly <em>better</em> than any other logging library; to me, I like that it doesn&#39;t do a lot more than what I need it to do.</p></pre>cs-guy: <pre><p>As one of the authors I am biased to <a href="https://godoc.org/github.com/go-kit/kit/log">github.com/go-kit/kit/log</a>. I have also made significant contributions to log15 (mentioned below) and recommend it as well. The Go kit log package was strongly influenced by log15. Go kit log takes a less is more philosophy.</p></pre>GoTheFuckToBed: <pre><p>pipe</p></pre>MrGossett: <pre><p>A coworker of mine wrote <a href="https://github.com/phemmer/sawmill" rel="nofollow">https://github.com/phemmer/sawmill</a>. I couldn&#39;t imagine using anything else. It providers handlers to integrate with Splunk, Sentry, syslog, and standard streams (STDOUT/STDERR), as well as Capture (to slice) and Channel handlers that are nice for testing. It also has a pluggable handler system that makes it extensible. It spins off a goroutine for each write, so it&#39;s super quick and doesn&#39;t get in the way if the log handler is slow.</p></pre>quiI: <pre><p>stdout</p></pre>tcrypt: <pre><p>At work we use (and built) <a href="https://github.com/gocraft/health" rel="nofollow">gocraft/health</a> which provides tagged logging and metrics. Out of the box it can optionally send data to statsd, Bugsnag, or be polled via a JSON API. This makes it super easy to have constant metrics about your running code and alerts when there are issues.</p> <p>We use a <a href="https://github.com/gocraft/web#middleware" rel="nofollow">middleware</a> so every web request or background job is counted, timed, and sent to statsd/Librato so we get automatic charts. It also has a tool, healthtop, which is a <a href="https://camo.githubusercontent.com/0984d0789a901aab0edd5257fa06bc19666363f8/68747470733a2f2f676f63726166742e6769746875622e696f2f6865616c74682f696d616765732f6865616c7468746f702e706e67" rel="nofollow">New Relic type breakdown of your instrumented code.</a></p> <p>It also compliments our other project, <a href="https://github.com/gocraft/dbr" rel="nofollow">dbr</a>, which will automatically log and time executed queries to a given health stream which makes tracking down inefficient queries quick and painless.</p></pre>apgwoz: <pre><p>We typically use logrus, but also attach some custom hooks to report to Rollbar. In addition we utilize go-metrics for publishing metrics to Librato. Other folks in the company utilize l2met, which just pulls metrics data out of the logs -- this is a service run by Librato.</p> <p>Recently, I&#39;ve been thinking about how to make this all better, and started a new lib to hopefully simplify this workflow. The basic idea is that you log key-value pairs (though anything else is supported as well) only, and attach filters to the logger, which can do things like print to standard out, or report to rollbar, or stop the filter chain and post l2met style metrics directly to Librato (instead of doing the l2met thing).</p> <p>I think the same thing could probably be done in logrus, but there are other little things that bug me about that library, so YOLO: <a href="https://github.com/apg/ln" rel="nofollow">https://github.com/apg/ln</a>. Keep in mind that I&#39;ve put like 2 hours into this so far and have a long way to go, and may just abandon it if it doesn&#39;t seem like it&#39;s any better than what we have...</p></pre>Have_No_Name: <pre><p>If you are moving from log4j, would you find log4go easy? <a href="https://github.com/alecthomas/log4go/" rel="nofollow">https://github.com/alecthomas/log4go/</a></p></pre>henrikbjorn: <pre><p>We use Logrus. But we &#34;hide&#34; the usage of Logrus behind interfaces so we dont have to rely directly on logrus and have pointers in our method signatures.</p></pre>Yojihito: <pre><blockquote> <p>standard logger</p> </blockquote> <p>This piece of shit is useless and should get deleted asap.</p> <p>Used it, tried to change date format to ISO 8601 norm, the standard date norm, LOL NOPE HARDCODED.</p> <p>Delete, next.</p></pre>GoGoGadgetGopher: <pre><p>:o</p> <p>u mad bro?</p></pre>Yojihito: <pre><p>Yes. A logging mechanism with hardcoded date format is shit. If that date format isn&#39;t even ISO compatible is a piece of useless shit.</p></pre>

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

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