Make WASM compatible by not including ssh/terminal for JS builds

This commit is contained in:
Noah 2019-12-22 18:33:54 -08:00
parent e046e3e7b0
commit f958476497
3 changed files with 24 additions and 9 deletions

View File

@ -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.

18
terminal.go Normal file
View File

@ -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()))
}

6
terminal_js.go Normal file
View File

@ -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