Logging in Go

blov · · 2192 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>My question is two-fold: what are some best practices for logging errors/messages in Go, and to where do you typically log these messages?</p> <p>I&#39;m running a Go application on CentOS 7 using Systemd, and I noticed that all &#34;fmt.Println()&#39;s&#34; are being logged to Journald. Is this a good place to keep logs, or have you had better experiences with other methods? I&#39;m also aware that writing to stdout is bad practice, but I&#39;m not sure what else to do.</p> <hr/>**评论:**<br/><br/>vascocosta: <pre><p>Have you tried the <a href="http://golang.org/pkg/log/" rel="nofollow">log</a> and <a href="http://golang.org/pkg/log/syslog/" rel="nofollow">syslog</a> packages?</p></pre>pib: <pre><p>I like <a href="https://github.com/Sirupsen/logrus" rel="nofollow">logrus</a> for logging, it adds log levels (error, warning, info, debug, etc.) and also has formatters for outputting logs in various formats (LogStash JSON for example) and hooks for sending some log entries elsewhere (line RayGun for caught panics for example).</p> <p>Just writing your logs to stderr is not a bad practice, then you can leave it up to your init script to pipe the log to wherever it needs to go.</p></pre>mgutz: <pre><p>Also look at <a href="https://github.com/mgutz/logxi" rel="nofollow">logxi</a>, it&#39;s structured and 12-factor app compliant. The nice thing is everything is configurable by environment variables including 256 colors</p></pre>

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

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