Skip to content

Commit d3cf3b7

Browse files
authored
feat: pass logger to automaxprocs (#270)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent cd853ca commit d3cf3b7

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

cmd/adder/main.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023 Blink Labs Software
1+
// Copyright 2024 Blink Labs Software
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -16,10 +16,11 @@ package main
1616

1717
import (
1818
"fmt"
19+
"log/slog"
1920
"net/http"
2021
"os"
2122

22-
_ "go.uber.org/automaxprocs"
23+
"go.uber.org/automaxprocs/maxprocs"
2324

2425
"github.com/blinklabs-io/adder/api"
2526
_ "github.com/blinklabs-io/adder/filter"
@@ -36,6 +37,10 @@ const (
3637
programName = "adder"
3738
)
3839

40+
func slogPrintf(format string, v ...any) {
41+
slog.Info(fmt.Sprintf(format, v...))
42+
}
43+
3944
func main() {
4045
cfg := config.GetConfig()
4146

@@ -86,6 +91,15 @@ func main() {
8691
// Configure logging
8792
logging.Configure()
8893
logger := logging.GetLogger()
94+
slog.SetDefault(logger)
95+
96+
// Configure max processes with our logger wrapper, toss undo func
97+
_, err := maxprocs.Set(maxprocs.Logger(slogPrintf))
98+
if err != nil {
99+
// If we hit this, something really wrong happened
100+
logger.Error(err.Error())
101+
os.Exit(1)
102+
}
89103

90104
// Start debug listener
91105
if cfg.Debug.ListenPort > 0 {

0 commit comments

Comments
 (0)