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

master
Noah 3 years ago
parent e046e3e7b0
commit f958476497
  1. 9
      golog.go
  2. 18
      terminal.go
  3. 6
      terminal_js.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.

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

@ -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
Loading…
Cancel
Save