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

chore(tiup-publisher): add logs #177

Merged
merged 1 commit into from
Oct 9, 2024
Merged

Conversation

wuhuizuo
Copy link
Contributor

@wuhuizuo wuhuizuo commented Oct 9, 2024

Signed-off-by: wuhuizuo wuhuizuo@126.com

Signed-off-by: wuhuizuo <wuhuizuo@126.com>
@ti-chi-bot ti-chi-bot bot requested a review from purelind October 9, 2024 05:15
Copy link

ti-chi-bot bot commented Oct 9, 2024

I have already done a preliminary review for you, and I hope to help you do a better job.

Based on the pull request title and description, it seems that this pull request is adding logs to the tiup-publisher package. Specifically, the change adds log statements to each of the three steps of the handler function. The logs will be used to track the success or failure of these steps.

Overall, this is a good change. Adding logs is important for debugging and monitoring. However, there are a few potential problems that should be addressed:

  1. The log level is dependent on an environment variable instead of being set in the code. This could lead to confusion if the environment variable is not set correctly. It would be better to set the default log level in the code itself.

  2. The logs are using the default log format. It would be better to use a structured log format, such as JSON, so that the logs can be easily parsed and analyzed.

  3. The logs are being sent to standard error. It would be better to send them to a dedicated log file or to a log aggregation service.

To address these issues, I suggest the following changes:

  1. Set the default log level in the code itself, as follows:
	logLevel := zerolog.InfoLevel
	if os.Getenv("LOG_LEVEL") != "" {
		level, err := zerolog.ParseLevel(os.Getenv("LOG_LEVEL"))
		if err == nil {
			logLevel = level
		}
	}
	log.Logger = log.Level(logLevel)
  1. Use a structured log format, such as JSON, as follows:
	log.Logger = zerolog.New(os.Stderr).With().Timestamp().Logger()
  1. Send the logs to a dedicated log file or to a log aggregation service, as follows:
	// log to a file
	logFile, err := os.OpenFile("/var/log/tiup-publisher.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
	if err != nil {
		log.Fatal().Err(err).Msg("failed to open log file")
	}
	log.Logger = log.Logger.Output(logFile)

	// or log to a log aggregation service
	log.Logger = log.Logger.Hook(logrustash.New(os.Stderr, logrustash.DefaultFormatter(logrus.Fields{})))

@ti-chi-bot ti-chi-bot bot added the size/S label Oct 9, 2024
Copy link
Contributor Author

@wuhuizuo wuhuizuo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

Copy link

ti-chi-bot bot commented Oct 9, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: wuhuizuo

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added the approved label Oct 9, 2024
@ti-chi-bot ti-chi-bot bot merged commit 0b8b9f9 into main Oct 9, 2024
3 checks passed
@ti-chi-bot ti-chi-bot bot deleted the feature/tiup-publisher-logs branch October 9, 2024 05:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant