Skip to content

Commit

Permalink
add json log options
Browse files Browse the repository at this point in the history
  • Loading branch information
Sledro committed Nov 9, 2024
1 parent 648857d commit fcd3b17
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
27 changes: 14 additions & 13 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,27 @@ import (
var Version = "development"

func main() {
// create a new logger
Logger := slog.New(tint.NewHandler(os.Stderr, nil))
err := godotenv.Load()
if err != nil {
fmt.Println(".env file not found, will attempt to use environment variables from system")
}

// Configure logger
var handler slog.Handler
if useJSON, _ := strconv.ParseBool(os.Getenv("LOG_JSON")); useJSON {
handler = slog.NewJSONHandler(os.Stdout, nil)
} else {
handler = tint.NewHandler(os.Stdout, nil)
}

// set global logger with custom options
slog.SetDefault(slog.New(
tint.NewHandler(os.Stderr, &tint.Options{
Level: slog.LevelDebug,
}),
))
Logger := slog.New(handler)
slog.SetDefault(Logger)

Logger.Info("Starting ll-bridge-api ("+Version+")",
"Go Version", runtime.Version(),
"Operating System", runtime.GOOS,
"Architecture", runtime.GOARCH)

err := godotenv.Load()
if err != nil {
Logger.Warn(".env file not found, will attempt to use environment variables from system")
}

// L1

l1DefaultStartBlock, err := strconv.ParseUint(os.Getenv("L1_DEFAULT_START_BLOCK"), 10, 64)
Expand Down
4 changes: 3 additions & 1 deletion example.env
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ L1_FETCH_INTERVAL=
DATABASE_URI=
DATABASE_NAME=

API_PORT=
API_PORT=

LOG_JSON=

0 comments on commit fcd3b17

Please sign in to comment.