logr - a simpler logging API with less stuff

polaris · · 543 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p><a href="https://github.com/thockin/logr" rel="nofollow">https://github.com/thockin/logr</a></p> <p>Just what you need, ANOTHER logging API for go.</p> <p>After reading <a href="http://dave.cheney.net/2015/11/05/lets-talk-about-logging" rel="nofollow">http://dave.cheney.net/2015/11/05/lets-talk-about-logging</a>, I wanted to try out a simpler logging API, to see if I could actually make it work. Here&#39;s my first sketch of an API.</p> <p>An implementation in terms of glog is at <a href="https://github.com/thockin/glogr" rel="nofollow">https://github.com/thockin/glogr</a></p> <hr/>**评论:**<br/><br/>tscs37: <pre><p>I personally like my logging levels, especially for debugging.</p> <p>Of course, the warning level is basically useless; I follow the example of the go compiler, it&#39;s either an error or it&#39;s not.</p> <p>But otherwise I like to have the log levels <code>Debug</code>, <code>Info</code>, <code>Error</code> and <code>Fatal</code>. (And please don&#39;t os.Exit on Fatal, I want my cleanup pls, that&#39;s my task, not the logger&#39;s)</p> <p>It&#39;s certainly not a bad start, tho I&#39;ll probably just <code>fmt.Printf</code> in my libraries like always...</p></pre>jiminythinksjohnny: <pre><p>It&#39;s useful to reserve the <code>warning</code> level for notable events that aren&#39;t actually errors in the program, but that might relate to problems external to it—events such as bad input or failed login attempts. They&#39;re <em>forensically interesting</em>, but not individually actionable. Unlike errors, alerting on warnings isn&#39;t typically worthwhile, because no conceivable change to the program could completely avoid them. But warnings are distinct from the <code>info</code> level, which covers the unremarkable majority of events, such as successful logins. You might review warnings in bulk from time to time, and that&#39;s only practical if they aren&#39;t mixed with the noise of the <code>info</code> entries. When troubleshooting a larger system, you&#39;d look at the warnings immediately after the errors.</p> <p>Example:</p> <ul> <li><code>info</code>: Successful login for user &#34;xyz&#34;</li> <li><code>warning</code>: Login failed due to incorrect password entry for user &#34;xyz&#34;</li> <li><code>error</code>: Login failed because authentication server returned unrecognized account status for user &#34;xyz&#34;</li> <li><code>critical</code>: could not connect to authentication server</li> </ul></pre>PaluMacil: <pre><p>I use warn for documenting method executions that are successful and &#34;correct&#34; but are deprecated or risky. I have a security flaw, for instance, that I cannot remove due to a legacy requirement pressed upon me. It&#39;s better than an error / fatal, and it&#39;s &#34;bad&#34; and needs observation, so it isn&#39;t just info, and debug fits worst of all.</p></pre>tscs37: <pre><p>my approach to legacy is: &#34;don&#39;t&#34;</p> <p>Though I guess if there is no choice in that department there is no way around warnings or maintaining legacy branches.</p></pre>Barrucadu: <pre><p>Doesn&#39;t having verbosity levels just mean, in practice, you have more log levels anyway? In order for the levels to mean anything, you&#39;d need to adopt a convention about their use, which will probably just result in things like &#34;INFO level 3+ is a DEBUG message&#34;.</p> <p>Not that I think there should be only two log levels with no verbosity levels. That&#39;s crazy. But I feel like, at a minimum, there should be &#34;debug&#34;, &#34;info&#34;, and &#34;error&#34;.</p></pre>thockin: <pre><p>Being numeric means you can define it yourself, and it doesn&#39;t limit you to just one trace level. I frequently want to enable increasing levels of verbosity when tracing something hard. The loss of semantic meaning is what I find interesting</p></pre>neoasterisk: <pre><p>I could never understand the purpose of different logging levels. You either log or you do not. A well-written command produces no logging on success. &#34;No news is good news&#34;. </p> <p>I believe that the design of the standard <code>log</code> package emphasizes that idea but still allows for flexibility via <code>log.New</code> which should be sufficient for the majority of cases.</p></pre>wlll: <pre><p>As a sysadmin logs are fundamental. Logs telling you what a process was doing when it was working as expected in the lead-up to a failure can be invaluable.</p> <p>If a process is mis-behaving, enabling more verbose logging to get more diagnostic information is valuable. It can always be turned down when the process is operating normally.</p></pre>: <pre><p>[deleted]</p></pre>neoasterisk: <pre><blockquote> <p>You don&#39;t want to get a notification each time there an &#34;info&#34; level log, but you might want to get a notification each time there is a &#34;error&#34; level log in your system.</p> </blockquote> <p>This is what I meant by &#34;you either log or you do not&#34;. If something is so serious or important that it has to be logged then you log it. Otherwise it&#39;s just noise or metrics.</p> <blockquote> <p>You should log ALL requests in a web app. If you don&#39;t do that, then you&#39;re not doing your job.</p> </blockquote> <p>I agree but I personally believe that this goes a bit out of the scope of logging. This is more like statistics/metrics and although logging can help with it, I think that we better use tools more appropriate for the job like <code>expvar</code>. I read that this is considered a <a href="https://peter.bourgon.org/go-in-production/#logging-and-telemetry" rel="nofollow">best practice</a>.</p> <blockquote> <p>The standard log packages serves very little purpose. as it is half baked.</p> <p>I baffled that anyone would claim the log package is enough for serious logging.</p> </blockquote> <p>I think it all depends on how your think about software. If you only log things that truly matter, then I don&#39;t see why <code>log</code> is insufficient. Yet even if you want to do more intricate stuff you can easily create your custom loggers e.g. <code>Info = log.New(...)</code> and <code>Error = log.New(...)</code>. The standard <code>log</code> package while simple, it still allows for that flexibility.</p></pre>thockin: <pre><p>Not everything is a simple command. The main project I work on (Kubernetes) is large and complex, and it is frequently necessary to ask a user to increase logging to get sufficient info to diagnose a problem, but leaving that enabled all the time would be too noisy.</p></pre>neoasterisk: <pre><p>For special cases like Kubernetes, using a more powerful 3rd party logging package might pay off. Even better if you write your own and avoid an extra dependency. </p> <p>But for the majority of cases I truly believe that the standard <code>log</code> package is more than sufficient and flexible enough. Yet somehow I see people easily dismissing it as worthless and &#34;half-baked&#34; which is something I cannot understand.</p></pre>

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

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