Skip to content

Commit

Permalink
Enable syslog when running as Windows service
Browse files Browse the repository at this point in the history
This writes logs to the Windows event log.
  • Loading branch information
Tyler Treat committed Jun 28, 2017
1 parent 032b0b4 commit 54e23a3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
9 changes: 8 additions & 1 deletion server/log.go
Expand Up @@ -37,11 +37,18 @@ func (s *Server) ConfigureLogger() {
opts = s.getOpts()
)

syslog := opts.Syslog
if isWindowsService() && opts.LogFile == "" {
// Enable syslog if no log file is specified and we're running as a
// Windows service so that logs are written to the Windows event log.
syslog = true
}

if opts.LogFile != "" {
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 {
} else if syslog {
log = logger.NewSysLogger(opts.Debug, opts.Trace)
} else {
colors := true
Expand Down
5 changes: 5 additions & 0 deletions server/service.go
Expand Up @@ -9,3 +9,8 @@ func Run(server *Server) error {
server.Start()
return nil
}

// isWindowsService indicates if NATS is running as a Windows service.
func isWindowsService() bool {
return false
}
6 changes: 6 additions & 0 deletions server/service_windows.go
Expand Up @@ -86,3 +86,9 @@ func Run(server *Server) error {
}
return run(serviceName, &winServiceWrapper{server})
}

// isWindowsService indicates if NATS is running as a Windows service.
func isWindowsService() bool {
isInteractive, _ := svc.IsAnInteractiveSession()
return !isInteractive
}

0 comments on commit 54e23a3

Please sign in to comment.