diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 735f514b18ba9826c010cba8888278db6057295e..b0db098ad805c003e37bf55528e363129a4101eb 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -86,7 +86,7 @@ emoji-update: script: - go mod vendor -v - mkdir -p release - - go run -ldflags '-w -s' ./emoji/... -o emojiSet.json -v 2 + - go run -ldflags '-w -s' -trimpath ./emoji/... -o emojiSet.json -v 0 - cp emojiSet.json release/ artifacts: paths: diff --git a/Makefile b/Makefile index bc170d109666ddd78cbfd9a9dc0388b2559b5504..77bb960622c378a2a650eecbd5e68e05ecd13d8d 100644 --- a/Makefile +++ b/Makefile @@ -33,6 +33,9 @@ worker_binaries: GOOS=js GOARCH=wasm go build -ldflags '-w -s' -trimpath -o xxdk-dmIndexedDkWorker.wasm ./indexedDb/impl/dm/... GOOS=js GOARCH=wasm go build -ldflags '-w -s' -trimpath -o xxdk-logFileWorker.wasm ./logging/workerThread/... +emojis: + go run -ldflags '-w -s' -trimpath ./emoji/... -o emojiSet.json + binaries: binary worker_binaries wasm_tests: diff --git a/emoji/main.go b/emoji/main.go index 174414d9a9daa64f08e2c0dc9e2451ae93d1613d..7404448b68be319cc5db6715640ae9abfd323292 100644 --- a/emoji/main.go +++ b/emoji/main.go @@ -21,6 +21,7 @@ import ( "log" "net/http" "os" + "strconv" ) // emojiMartUrl is the URL pointing to the native.JSON from emoji-mart that is @@ -56,10 +57,8 @@ var cmd = &cobra.Command{ Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { - // Initialize the logging if set - if logFile != "" { - initLog(logLevel, logFile) - } + // Initialize the logging + initLog(jww.Threshold(logLevel), logFile) // Retrieve emoji-mart file from URL jww.INFO.Printf("Requesting file %s", requestURL) @@ -115,14 +114,22 @@ func init() { "Output JSON file path.") cmd.Flags().StringVarP(&logFile, "log", "l", "-", "Log output path. By default, logs are printed to stdout. "+ - "To disable logging, set this to empty.") - cmd.Flags().IntVarP(&logLevel, "logLevel", "v", 0, - "Verbosity level of logging. 0 = INFO, 1 = DEBUG, 2 = TRACE") + "To disable logging, set this to empty (\"\").") + cmd.Flags().IntVarP(&logLevel, "logLevel", "v", 4, + "Verbosity level of logging. 0 = TRACE, 1 = DEBUG, 2 = INFO, "+ + "3 = WARN, 4 = ERROR, 5 = CRITICAL, 6 = FATAL") } -// initLog will enable JWW logging. -func initLog(threshold int, logPath string) { - if logPath != "-" && logPath != "" { +// initLog will enable JWW logging to the given log path with the given +// threshold. If log path is empty, then logging is not enabled. Panics if the +// log file cannot be opened or if the threshold is invalid. +func initLog(threshold jww.Threshold, logPath string) { + if logPath == "" { + // Do not enable logging if no log file is set + return + } else if logPath != "-" { + // Set the log file if stdout is not selected + // Disable stdout output jww.SetStdoutOutput(io.Discard) @@ -135,19 +142,17 @@ func initLog(threshold int, logPath string) { jww.SetLogOutput(logOutput) } - if threshold > 1 { - jww.SetStdoutThreshold(jww.LevelTrace) - jww.SetLogThreshold(jww.LevelTrace) - jww.SetFlags(log.LstdFlags | log.Lmicroseconds) - jww.INFO.Printf("log level set to: %s", jww.LevelTrace) - } else if threshold == 1 { - jww.SetStdoutThreshold(jww.LevelDebug) - jww.SetLogThreshold(jww.LevelDebug) + if threshold < jww.LevelTrace || threshold > jww.LevelFatal { + panic("Invalid log threshold: " + strconv.Itoa(int(threshold))) + } + + // Display microseconds if the threshold is set to TRACE or DEBUG + if threshold == jww.LevelTrace || threshold == jww.LevelDebug { jww.SetFlags(log.LstdFlags | log.Lmicroseconds) - jww.INFO.Printf("log level set to: %s", jww.LevelDebug) - } else { - jww.SetStdoutThreshold(jww.LevelInfo) - jww.SetLogThreshold(jww.LevelInfo) - jww.INFO.Printf("log level set to: %s", jww.LevelInfo) } + + // Enable logging + jww.SetStdoutThreshold(threshold) + jww.SetLogThreshold(threshold) + jww.INFO.Printf("Log level set to: %s", threshold) }