diff --git a/golog.go b/golog.go index 8c3e9e9..96b8c1c 100644 --- a/golog.go +++ b/golog.go @@ -1,11 +1,8 @@ package log import ( - "os" "sync" "text/template" - - "golang.org/x/crypto/ssh/terminal" ) // An internal map of named loggers. This allows for GetLogger() to be called @@ -14,16 +11,10 @@ import ( var ( loggers map[string]*Logger loggerMutex sync.Mutex - - interactive bool // is an interactive shell ) func init() { loggers = map[string]*Logger{} - - // Detect if we're running in an interactive shell, so we can globally - // disable colors when redirecting to a log file. - interactive = terminal.IsTerminal(int(os.Stdout.Fd())) } // Logger stores the configuration for a named logger instance. diff --git a/terminal.go b/terminal.go new file mode 100644 index 0000000..796f043 --- /dev/null +++ b/terminal.go @@ -0,0 +1,18 @@ +// +build !js + +package log + +import ( + "os" + + "golang.org/x/crypto/ssh/terminal" +) + +// Terminal module determines if an interactive shell is in use. If +// not interactive, disable colors by default. This is so deployed web apps +// log their output in plain text. +var interactive = false + +func init() { + interactive = terminal.IsTerminal(int(os.Stdout.Fd())) +} diff --git a/terminal_js.go b/terminal_js.go new file mode 100644 index 0000000..0d1092c --- /dev/null +++ b/terminal_js.go @@ -0,0 +1,6 @@ +// +build js,wasm +package log + +// WASM builds don't have a terminal to query so interactive=false for plain +// text logs to the browser console. +var interactive = false