How to capture glog.Info to stdout instead of stderr when running with --logtostderr

2,559 views
Skip to first unread message

webus...@gmail.com

unread,
Jun 27, 2015, 8:37:31 PM6/27/15
to golan...@googlegroups.com
I have a set of go programs that get run on a compute farm. I'm using the glog library for all my logging (love it). My go scheduler captures the stdout and stderr from the porgrams and redirects them to two different files. I then have a web interface which allows you to see what the error messages were (and normal messages were) for each program scheduled. 

In my log files I have some glog.Info and glog.Error. However, when I run the program with "test --logtostderr" everything goes to stderr. I would like debug and info messages to go to stdout and error and fatal messages to go to stderr. 

Is there any way to do this using glog? If not, is there a simple local change I can make to my glog library to do this? How do other people handle this?

Thanks,

wu

Erik Brady

unread,
Jul 1, 2015, 8:45:03 PM7/1/15
to golan...@googlegroups.com
I wanted something similar but didn't find anything that quite fit my needs... so I wrote a package:

It defaults to stdout for regular messages and stderr for errors although one can set an io.Writer (or multi-writer) for any of the output levels.  It allows various other settings as covered in the docs and such (and can mirror the screen output to a log file ... or not, such as if you want to mirror more data to the log file than to the screen based on different output/log levels for either... independent control basically).

Feel free to give it a whirl and let me know if you have any questions.  I suppose a disclaimer is that I'm fairly new to Go and, while I'm using it for my own purposes it is not heavily tested (or reviewed) by others.

Cheers,
Erik
Reply all
Reply to author
Forward
0 new messages