<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'm running a Go application on CentOS 7 using Systemd, and I noticed that all "fmt.Println()'s" are being logged to Journald. Is this a good place to keep logs, or have you had better experiences with other methods? I'm also aware that writing to stdout is bad practice, but I'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's structured and 12-factor app compliant. The nice thing is everything is configurable by environment variables including 256 colors</p></pre>