Skip to content
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

fix: use the logger from std lib at cmd entry #67

Merged
merged 1 commit into from
Dec 11, 2024
Merged

Conversation

dkeven
Copy link
Collaborator

@dkeven dkeven commented Dec 11, 2024

the logger in the "bytetrade.io/web3os/installer/pkg/core/logger" package, used across this project, is initialized in:

if err := base.InitLogger(consoleLogFileName, consoleLogTruncate); err != nil {

which is typically called in the Run method of a command like this:
if err := pipelines.CliInstallTerminusPipeline(o.InstallOptions); err != nil {
logger.Fatalf("install Olares error: %v", err)
}

but other errors might also be returned before the logger is actually initialized, resulting in a nil pointer panic.
we should just simply use the logger from the standard library in this case, because:

  • if the command errors out before the logger is initialized, it means no task has been executed, thus a simple console log is enough.
  • if the command errors out after the logger is initialized, the actual log is already handled by the logger and it's also ok to use the standard log lib to print the error message at the end and exit.

@dkeven dkeven requested a review from eball December 11, 2024 03:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants