Skip to content

Commit

Permalink
Use os.Stderr and os.Stdout instead of os.Stdout.Name() and os.OpenFi…
Browse files Browse the repository at this point in the history
…le(). Resolves #7.

STDOUT now default for logs
  • Loading branch information
aerth committed Feb 8, 2017
1 parent 8039549 commit 3e44640
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion 00-main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ var (
nolog = flag.Bool("nolog", false, "Logging: Logs to /dev/null")
fastcgi = flag.Bool("fastcgi", false, "Use fastcgi (for with nginx etc)")
secure = flag.Bool("secure", false, "HTTPS only.")
logfile = flag.String("log", "stderr", "Logging: Use a log `file` instead of stdout\n\tExample: cosgo -log cosgo.log -debug\n")
logfile = flag.String("log", "stdout", "Logging: Use a log `file` instead of stdout\n\tExample: cosgo -log cosgo.log -debug\n")
cookie = flag.String("cookie", "cosgo", "Custom cookie+form field name\n")
gpg = flag.String("gpg", "", "GPG: Path to ascii-armored `public-key` to encrypt mbox\n)")
sendgridKey = flag.String("sg", "", "Sendgrid: Sendgrid API `key` (disables mbox)\n")
Expand Down
5 changes: 5 additions & 0 deletions 02-internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ func openLogFile() {
}
if *logfile == "stdout" {
*logfile = os.Stdout.Name()
log.SetOutput(os.Stdout)
return
}
if *logfile == "stderr" {
*logfile = os.Stderr.Name()
log.SetOutput(os.Stderr)
return
}

f, ferr := os.OpenFile(*logfile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0600)
if ferr != nil {
log.Printf("error opening file: %v", ferr)
Expand Down

0 comments on commit 3e44640

Please sign in to comment.