fix(logging): fix logging parameter not taken into account

This commit is contained in:
Antoine Aflalo
2025-08-26 22:36:00 -04:00
parent e26cf7a26a
commit c2a6220fde
5 changed files with 27 additions and 24 deletions

1
.gitignore vendored
View File

@@ -103,3 +103,4 @@ fabric.properties
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
*__debug_bin*

29
.vscode/launch.json vendored
View File

@@ -1,16 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}"
}
]
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Optimize Testdata",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/cbzoptimizer",
"args": ["optimize", "${workspaceFolder}/testdata", "-l", "debug"],
"cwd": "${workspaceFolder}"
}
]
}

View File

@@ -60,8 +60,14 @@ func init() {
"Set log level; can be 'panic', 'fatal', 'error', 'warn', 'info', 'debug', or 'trace'")
// Add log level environment variable support
viper.SetEnvPrefix("")
viper.BindEnv("LOG_LEVEL")
viper.BindEnv("log", "LOG_LEVEL")
viper.BindPFlag("log", rootCmd.PersistentFlags().Lookup("log"))
rootCmd.PersistentPreRun = func(cmd *cobra.Command, args []string) {
ConfigureLogging()
}
// Ensure the configuration directory exists
err := os.MkdirAll(configFolder, os.ModePerm)
if err != nil {
@@ -95,7 +101,7 @@ func ConfigureLogging() {
level := zerolog.InfoLevel
// Check LOG_LEVEL environment variable first
envLogLevel := viper.GetString("LOG_LEVEL")
envLogLevel := viper.GetString("log")
if envLogLevel != "" {
if parsedLevel, err := zerolog.ParseLevel(envLogLevel); err == nil {
level = parsedLevel

View File

@@ -13,8 +13,5 @@ var (
func main() {
commands.SetVersionInfo(version, commit, date)
// Configure logging before executing commands
commands.ConfigureLogging()
commands.Execute()
}

2
go.mod
View File

@@ -2,8 +2,6 @@ module github.com/belphemur/CBZOptimizer/v2
go 1.25
toolchain go1.25.0
require (
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de
github.com/belphemur/go-webpbin/v2 v2.0.0