Skip to content

Commit

Permalink
Added check for log redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
Derek Collison committed Jan 10, 2015
1 parent 05a3e65 commit 7b6fd2b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions gnatsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package main

import (
"flag"
"os"
"strings"

"github.com/apcera/gnatsd/auth"
Expand Down Expand Up @@ -126,13 +127,19 @@ func configureLogger(s *server.Server, opts *server.Options) {
var log server.Logger

if opts.LogFile != "" {
log = logger.NewFileLogger(opts.LogFile, opts.Logtime, opts.Debug, opts.Trace)
log = logger.NewFileLogger(opts.LogFile, opts.Logtime, opts.Debug, opts.Trace, true)
} else if opts.RemoteSyslog != "" {
log = logger.NewRemoteSysLogger(opts.RemoteSyslog, opts.Debug, opts.Trace)
} else if opts.Syslog {
log = logger.NewSysLogger(opts.Debug, opts.Trace)
} else {
log = logger.NewStdLogger(opts.Logtime, opts.Debug, opts.Trace, true)
colors := true
// Check to see if stderr is being redirected and if so turn off color
stat, _ := os.Stderr.Stat()
if (stat.Mode() & os.ModeCharDevice) == 0 {
colors = false
}
log = logger.NewStdLogger(opts.Logtime, opts.Debug, opts.Trace, colors, true)
}

s.SetLogger(log, opts.Debug, opts.Trace)
Expand Down

0 comments on commit 7b6fd2b

Please sign in to comment.