Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pass logger to automaxprocs #270

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions cmd/adder/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Blink Labs Software
// Copyright 2024 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -16,10 +16,11 @@ package main

import (
"fmt"
"log/slog"
"net/http"
"os"

_ "go.uber.org/automaxprocs"
"go.uber.org/automaxprocs/maxprocs"

"github.com/blinklabs-io/adder/api"
_ "github.com/blinklabs-io/adder/filter"
Expand All @@ -36,6 +37,10 @@ const (
programName = "adder"
)

func slogPrintf(format string, v ...any) {
slog.Info(fmt.Sprintf(format, v...))
}

func main() {
cfg := config.GetConfig()

Expand Down Expand Up @@ -86,6 +91,15 @@ func main() {
// Configure logging
logging.Configure()
logger := logging.GetLogger()
slog.SetDefault(logger)

// Configure max processes with our logger wrapper, toss undo func
_, err := maxprocs.Set(maxprocs.Logger(slogPrintf))
if err != nil {
// If we hit this, something really wrong happened
logger.Error(err.Error())
os.Exit(1)
}

// Start debug listener
if cfg.Debug.ListenPort > 0 {
Expand Down