Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only one backend being written to #22

Closed
jefferai opened this issue Sep 7, 2014 · 2 comments
Closed

Only one backend being written to #22

jefferai opened this issue Sep 7, 2014 · 2 comments

Comments

@jefferai
Copy link

jefferai commented Sep 7, 2014

This is almost certainly me doing something wrong. :-)

I'm setting two backends: one to stdout, one to a file. The file is successfully created and opened, but nothing is ever logged to it -- only to stdout. My simplified code looks like this:

var (
    logger                  = logging.MustGetLogger("aiab")
)

func main() {
    stdOutBackend := logging.NewLogBackend(os.Stdout, "", 0)
    logFileBaseName := "aiab-" + time.Now().Format(time.RFC3339)
    logFileName := os.Getenv("AIAB_LOGS") + "/" + logFileBaseName
    logFile, err := os.OpenFile(logFileName, os.O_APPEND|os.O_CREATE, 0664)
    if err != nil {
        panic("Could not open log file: " + err.Error())
    }
    logFileBackend := logging.NewLogBackend(logFile, "", 0)
    logging.SetBackend(stdOutBackend, logFileBackend)
    logging.SetFormatter(logging.GlogFormatter)
    logging.SetLevel(logging.DEBUG, "aiab")
}

What am I doing wrong? I've perused the various docs and I've tried some variations on the above but the same result: no error is ever reported, and the file is created successfully, but nothing is written to it, only stdout.

Thanks!

@op
Copy link
Owner

op commented Sep 9, 2014

Ah. Try adding a write flag to your flags, eg. O_WRONLY!

@op op closed this as completed Sep 9, 2014
@jefferai
Copy link
Author

Ah shucks, I stupidly figure APPEND was making that implicit. I'll try that out and reopen if it doesn't work. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants