-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: simplify logging configuration
- Loading branch information
1 parent
80be4d3
commit 08be674
Showing
3 changed files
with
20 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,11 @@ | ||
package main | ||
|
||
import ( | ||
"log/slog" | ||
"os" | ||
|
||
"github.com/controlplaneio/simulator/controlplane/cli" | ||
) | ||
|
||
const ( | ||
LogLevel = "LOG_LEVEL" | ||
"github.com/controlplaneio/simulator/logging" | ||
) | ||
|
||
func main() { | ||
level, ok := os.LookupEnv(LogLevel) | ||
if !ok { | ||
level = "info" | ||
} | ||
|
||
var sLevel slog.Level | ||
|
||
switch level { | ||
case "debug": | ||
sLevel = slog.LevelDebug | ||
case "info": | ||
sLevel = slog.LevelInfo | ||
} | ||
|
||
logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{ | ||
Level: sLevel, | ||
})) | ||
slog.SetDefault(logger) | ||
|
||
logging.Configure() | ||
cli.Execute() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package logging | ||
|
||
import ( | ||
"log/slog" | ||
"os" | ||
) | ||
|
||
func Configure() { | ||
handlerOptions := &slog.HandlerOptions{ | ||
AddSource: true, | ||
Level: slog.LevelError, | ||
} | ||
|
||
logger := slog.New(slog.NewJSONHandler(os.Stdout, handlerOptions)) | ||
slog.SetDefault(logger) | ||
} |