-
Notifications
You must be signed in to change notification settings - Fork 3
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
logger v2 #7
base: main
Are you sure you want to change the base?
logger v2 #7
Conversation
WalkthroughThe recent update introduces a new logging system to enhance logging capabilities project-wide. This system brings in configurable log levels, formats, and file creation, aiming to streamline log handling for improved debugging and monitoring tailored to diverse developmental needs. Changes
Poem
Recent Review DetailsConfiguration used: CodeRabbit UI Files selected for processing (2)
Files skipped from review as they are similar to previous changes (2)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
internal/logger/logger_utils.go
Outdated
func Initialize(cfg Config) { | ||
config = cfg | ||
logrus.SetFormatter(config.LogFormat) | ||
switch config.LogLevel { | ||
case InfoLevel: | ||
logrus.SetLevel(logrus.InfoLevel) | ||
case WarnLevel: | ||
logrus.SetLevel(logrus.WarnLevel) | ||
case ErrorLevel: | ||
logrus.SetLevel(logrus.ErrorLevel) | ||
default: | ||
logrus.SetLevel(logrus.InfoLevel) | ||
} | ||
|
||
for _, file := range config.ModuleToFile { | ||
path := filepath.Dir(file) | ||
if err := os.MkdirAll(path, os.ModePerm); err != nil { | ||
logrus.WithError(err).Fatal("cannot create log directory") | ||
} | ||
file, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) | ||
if err != nil { | ||
logrus.WithError(err).Fatal("cannot open log file") | ||
} | ||
|
||
logrus.SetOutput(file) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logger output is set to the last file in the loop, which likely causes all logs to be written to the same file.
- logrus.SetOutput(file)
+ logger.SetOutput(file) // Ensure each logger instance has its correct output file.
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
func Initialize(cfg Config) { | |
config = cfg | |
logrus.SetFormatter(config.LogFormat) | |
switch config.LogLevel { | |
case InfoLevel: | |
logrus.SetLevel(logrus.InfoLevel) | |
case WarnLevel: | |
logrus.SetLevel(logrus.WarnLevel) | |
case ErrorLevel: | |
logrus.SetLevel(logrus.ErrorLevel) | |
default: | |
logrus.SetLevel(logrus.InfoLevel) | |
} | |
for _, file := range config.ModuleToFile { | |
path := filepath.Dir(file) | |
if err := os.MkdirAll(path, os.ModePerm); err != nil { | |
logrus.WithError(err).Fatal("cannot create log directory") | |
} | |
file, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) | |
if err != nil { | |
logrus.WithError(err).Fatal("cannot open log file") | |
} | |
logrus.SetOutput(file) | |
} | |
} | |
func Initialize(cfg Config) { | |
config = cfg | |
logrus.SetFormatter(config.LogFormat) | |
switch config.LogLevel { | |
case InfoLevel: | |
logrus.SetLevel(logrus.InfoLevel) | |
case WarnLevel: | |
logrus.SetLevel(logrus.WarnLevel) | |
case ErrorLevel: | |
logrus.SetLevel(logrus.ErrorLevel) | |
default: | |
logrus.SetLevel(logrus.InfoLevel) | |
} | |
for _, file := range config.ModuleToFile { | |
path := filepath.Dir(file) | |
if err := os.MkdirAll(path, os.ModePerm); err != nil { | |
logrus.WithError(err).Fatal("cannot create log directory") | |
} | |
file, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) | |
if err != nil { | |
logrus.WithError(err).Fatal("cannot open log file") | |
} | |
logger.SetOutput(file) // Ensure each logger instance has its correct output file. | |
} | |
} |
Summary by CodeRabbit