potential logger bug?

93 views
Skip to first unread message

Kyle Wolfe

unread,
Jul 30, 2015, 6:52:30 PM7/30/15
to golang-nuts
I'm currently working on recreating the issue in a condensed example, but in the meantime, I want to see if anyone has any ideas on what might be happening.

I have several private packages being used by main (github.com/codegangsta/cli):

private/project/cmd
private/packagea
private/packageb

Each package, including main uses the following (each with their own prefix):

var (
    Logger *log.Logger = log.New(os.NewFile(uintptr(syscall.Stderr), os.DevNull), "packagea: ", log.LstdFlags)
)

In main, during app.Before, I set the output for each logger with 'packagea.Logger.SetOutput(os.Stderr)'. I have it set up this way because I have a custom writer which has some filters in it, which I have since replaced with os.StdErr until I fix the issue.

All logging works great, I'll see messages in StdErr with prefixes of main, packagea, packageb, etc. Toward the end of execution of main, logging ceases to occur, and main exits with a 0. I print the logger after I know a log should have occurred and see that there are bytes in the buffer. I then switch one of the loggers outputs to os.Stdout durring app.Before that I know should be printing and it works!

Any ideas as to why the output of some of the loggers are not being flushed? I did not think any type of lock was needed against os.Stderr / os.Stdout. Again, I'm working on recreating a slimmed down example that I will post here soon if I can recreate it.

Thanks,
Kyle

Dave Cheney

unread,
Jul 30, 2015, 7:06:26 PM7/30/15
to golang-nuts
Without code to examine its hard to follow the example.you describe.

Have you built a race enabled version of this program and verified that updating loggers is data race safe ?

Thanks

Dave

Kyle Wolfe

unread,
Jul 31, 2015, 9:45:12 AM7/31/15
to golang-nuts, da...@cheney.net
By that do you mean 'go install -race ./...'? If so, yes, and no errors. go vet is also clean.

I can't recreate the issue for the life of me. It looks like I'm going to be stripping everything out of my app and introduce sections back in one at a time until it breaks again.
Reply all
Reply to author
Forward
0 new messages