Skip to content
Snippets Groups Projects
Commit cd9d397d authored by Jono Wenger's avatar Jono Wenger
Browse files

Merge branch 'hotfix/emojiLogging' into 'release'

Improve emoji script logging and add it to the Makefile

See merge request !69
parents 51cd163e 0b759127
No related branches found
No related tags found
2 merge requests!69Improve emoji script logging and add it to the Makefile,!67fix for latest client release
......@@ -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:
......
......@@ -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:
......
......@@ -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)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment