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

【RFC】Design of Horizon Log Package Zap #139

Closed
cubxxw opened this issue Apr 20, 2023 · 2 comments
Closed

【RFC】Design of Horizon Log Package Zap #139

cubxxw opened this issue Apr 20, 2023 · 2 comments
Labels
no-issue-activity This issue is outdated RFC

Comments

@cubxxw
Copy link
Contributor

cubxxw commented Apr 20, 2023

Design of Horizon Log Package Zap

Introduction

Add an X-Request-ID field to all logs for a given HTTP request.

  • Fatal handlers: logrus allows one or more handlers to be registered, which are called when a fatal level log occurs. This feature is useful when our program needs to be gracefully shut down.

Disadvantages

  • Low execution efficiency, especially in high-concurrency scenarios
  • Does not support log rotation

Based on the above advantages and disadvantages, I propose the following solution:

  • Use zap as the log package for Horizon
  • zap is a high-performance, low-latency log package that supports log rotation and multiple output formats
  • zap is similar to logrus, easy to use and learn, and provides multiple log levels

By using zap, Horizon will obtain better performance and more complete logging functions.

Many excellent open source projects use zap as their log package, such as Kubernetes, etcd, and CockroachDB, as well as the k8s-iam project I am preparing in the future. Therefore, using zap as the log package for Horizon is also a good choice.

Why choose zap

Zap log package can be well compatible with glog. The encapsulation background is that when developing Horizon, we found that glog was used extensively in the Kubernetes source code, and the log package needed to be compatible with glog.

Why choose /pkg/log directory

Migrate the log package to the pkg/log directory instead of pkg/util/log.

  • The first one, the log package belongs to the Horizon project, and there are customization development contents;
  • The second one, the log package has complete and mature functions, and external projects can also use it.

Basic encapsulated log package support functions

  • Basic functions: support basic log information, support different log levels, support custom configuration, support output to standard output and files.
  • Advanced functions: support multiple log formats, can output by level, support structured logs, support log rotation, and have Hook capability.
  • Optional functions: support color output, compatible with the standard library log package, and support output to different locations.
@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the no-issue-activity This issue is outdated label May 21, 2023
@github-actions
Copy link

This issue was closed because it has been stalled for 5 days with no activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-issue-activity This issue is outdated RFC
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants