On Fri, Mar 17, 2023 at 10:16 AM Stuart McLean <stuartmcl...@mac.com> wrote: > > Thanks so much for the quick answers. I did try setting the `alsologtostderr` > flag (and adding `flag.Parse()` after) but it doesn’t make a difference. I’m > trying to capture error logs anyway. I’ve tried stepping through the glog > code and it looks like messages are being written to a buffer for stderr, but > it doesn’t seem like that buffer is being flushed in time for my tests to > pick it up. I even tried adding some sleep calls to see if that made a > difference, but that didn’t help either. I don’t see any way to flush the > stderr buffer manually. It looks like we can only manually flush the file > buffer.
Sure thing. On what OS do you run your tests? The underlying writer of sinks.stderr is initialized with os.Stderr[0] and writes to it should typically be unbuffered (on Linux at least). From that perspective there's nothing really to flush here. I suspect that either the sinks.stderr reports Enabled()==false[1] which would cause the internal/logsink package to skip emitting to it, or os.Stderr is buffered on your system. In the first case double check which flags you're passing and that they're effective (and not overwritten somewhere else), and in the second case you can try to call os.Stderr.Sync() to force writing to it. If you have a reproducer i could also take a look. [0]: https://github.com/golang/glog/blob/master/glog_file.go#L156 [1]: https://github.com/golang/glog/blob/master/glog_file.go#L178 > > > On 16. Mar 2023, at 18:29, Chressie Himpel <chres...@google.com> wrote: > > > > On Thu, Mar 16, 2023 at 5:27 PM Ian Lance Taylor <i...@golang.org> wrote: > >> > >> [ + jba ] > >> > >> On Thu, Mar 16, 2023 at 8:56 AM 'Stuart McLean' via golang-nuts > >> <golang-nuts@googlegroups.com> wrote: > >>> > >>> Hi there, > >>> > >>> With glog v1.0.0 I used to be able to easily capture stderr logs for in > >>> integration tests. With the upgraded version this no longer works. I > >>> tried various suggestions that I found online and even this library: > >>> https://github.com/zenizh/go-capturer but nothing seems to work. > > > > By default glog only prints ERROR level and above to stderr. Did you > > try to pass the -alsologtostderr flag to your program (or set it via > > flag.Set("alsologtostderr", "true"))? > > > >>> > >>> Is there a way to configure glog to write to a specific file that I can > >>> read from after? > >>> > >>> Thanks for your time, > >>> Stuart McLean > >>> > >>> -- > >>> You received this message because you are subscribed to the Google Groups > >>> "golang-nuts" group. > >>> To unsubscribe from this group and stop receiving emails from it, send an > >>> email to golang-nuts+unsubscr...@googlegroups.com. > >>> To view this discussion on the web visit > >>> https://groups.google.com/d/msgid/golang-nuts/20CCAFD5-6400-4C68-BFBC-AB41F7FA7853%40mac.com. > >> > >> -- > >> You received this message because you are subscribed to the Google Groups > >> "golang-nuts" group. > >> To unsubscribe from this group and stop receiving emails from it, send an > >> email to golang-nuts+unsubscr...@googlegroups.com. > >> To view this discussion on the web visit > >> https://groups.google.com/d/msgid/golang-nuts/CAOyqgcVMFDOoqW82mwkab-4KYFPZ6H3So6xoKuudRhK%3D49niQw%40mail.gmail.com. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAPgVe6PuJG1RvY1yXiJSWA7iaxwGh6%2BVrnNC13oMSHb-qNVmnw%40mail.gmail.com.