From f9584764973f3d026c957b29baa49ea60caead82 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Sun, 22 Dec 2019 18:33:54 -0800 Subject: [PATCH] Make WASM compatible by not including ssh/terminal for JS builds --- golog.go | 9 --------- terminal.go | 18 ++++++++++++++++++ terminal_js.go | 6 ++++++ 3 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 terminal.go create mode 100644 terminal_js.go 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