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