stolostron / multicluster-global-hub

the main repository for the multicluster global hub
Apache License 2.0
21 stars 32 forks source link

Format the log #1178

Open yanmxa opened 10 hours ago

yanmxa commented 10 hours ago

Here's a comprehensive comparison of the specified logging libraries based on various features, including log format, log level configuration, dynamic change log level, log code location, and time formatting:

Library Log Format Log Level Configuration Control Log Level Log Code Location Time Formatting Support Dynamic Level Configuration Notes
glog Text-based Via command-line flags Set via -v flag for verbosity levels Yes, with log.V() calls Default format (RFC3339) No Simple interface, widely used in Go.
zap JSON or text Via config or code Configurable at initialization with log levels Yes, with caller information Customizable format Yes High performance, structured logging.
zapr JSON or text Via logr interface Same as zap; uses logr interface for config Yes, with caller information Follows zap configuration Yes Adapter for zap, integrates with logr.
logr Text-based (varies) Via context or runtime config Control via context or runtime configuration Yes, with WithValues Format varies by backend Yes Interface for structured logging, flexible.
klog Text-based Via command-line flags Set via --v flag for verbosity levels Yes, provides file and line Default format (RFC3339) No Designed for Kubernetes, simpler format.
yanmxa commented 9 hours ago

zap Vs zapr ?

yanmxa commented 7 hours ago

Suggest using the zapr, which can be invoked by the interface logr easily. The only concern is it only supports DEBUG, INFO, and ERROR