mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 04:50:52 +08:00
Add dynamic log level adjustment and "type" field to auth files response
- Introduced `SetLogLevel` utility function for unified log level management. - Updated dynamic log level handling across server and watcher components. - Extended auth files response by extracting and including the `type` field from file content. - Updated management API documentation with the new `type` field in auth files response.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// Package util provides utility functions for the CLI Proxy API server.
|
||||
// It includes helper functions for proxy configuration, HTTP client setup,
|
||||
// and other common operations used across the application.
|
||||
// log level management, and other common operations used across the application.
|
||||
package util
|
||||
|
||||
import (
|
||||
|
||||
23
internal/util/util.go
Normal file
23
internal/util/util.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"github.com/luispater/CLIProxyAPI/internal/config"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// SetLogLevel configures the logrus log level based on the configuration.
|
||||
// It sets the log level to DebugLevel if debug mode is enabled, otherwise to InfoLevel.
|
||||
func SetLogLevel(cfg *config.Config) {
|
||||
currentLevel := log.GetLevel()
|
||||
var newLevel log.Level
|
||||
if cfg.Debug {
|
||||
newLevel = log.DebugLevel
|
||||
} else {
|
||||
newLevel = log.InfoLevel
|
||||
}
|
||||
|
||||
if currentLevel != newLevel {
|
||||
log.SetLevel(newLevel)
|
||||
log.Infof("log level changed from %s to %s (debug=%t)", currentLevel, newLevel, cfg.Debug)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user