Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewLogger ¶
NewLogger creates a new instance of a zerolog.Logger configured with global settings.
The logger includes timestamps by default. If `withCaller` is enabled, it also includes caller information (file and line number).
Returns: - A new instance of zerolog.Logger.
func SetGlobalFormat ¶
func SetGlobalFormat(format string)
SetGlobalFormat sets the global log output format.
Supported formats: - "json": Logs will be written in JSON format (default). - Any other value: Logs will be written in a human-readable console format.
Parameters: - format: The desired log format ("json" or others).
func SetGlobalLevel ¶
func SetGlobalLevel(levelStr string)
SetGlobalLevel sets the global log level.
Supported levels: - "debug", "info", "warn", "error", "fatal", "panic", "trace".
If an invalid level string is provided, the log level defaults to "info", and a warning message is logged.
Parameters: - levelStr: The desired global log level as a string.
func WithCaller ¶
func WithCaller(enabled bool)
WithCaller enables or disables the inclusion of caller information (file and line number) in logs.
Parameters: - enabled: If true, logs will include caller information.
Types ¶
type RestyTracer ¶
type RestyTracer struct {
// contains filtered or unexported fields
}
RestyTracer is a custom tracer for Resty HTTP client, designed to log detailed trace information about HTTP requests and responses.
It leverages zerolog for structured logging and captures information such as DNS lookup time, connection time, TLS handshake duration, and more.
func NewRestyTracer ¶
func NewRestyTracer(logger zerolog.Logger) *RestyTracer
NewRestyTracer creates a new instance of RestyTracer.
Parameters: - logger: A zerolog.Logger instance to be used for logging.
Returns: - A pointer to the newly created RestyTracer.
func (*RestyTracer) Trace ¶
func (t *RestyTracer) Trace(r *resty.Response)
Trace logs detailed information about an HTTP request and its trace details using zerolog.
This method captures the following details: - Request URL, method, and status code. - Protocol used for the request. - Request and response headers. - TraceInfo metrics such as DNS lookup time, connection time, and more.
Parameters: - r: The Resty Response object containing the HTTP request and trace details.
type TraceInfo ¶
type TraceInfo struct { DNSLookup string ConnTime string TCPConnTime string TLSHandshake string ServerTime string ResponseTime string TotalTime string IsConnReused bool IsConnWasIdle bool ConnIdleTime string RequestAttempt int RemoteAddr net.Addr }
TraceInfo represents detailed timing and connection metrics for an HTTP request. It mirrors the trace information provided by Resty's TraceInfo, with fields formatted as strings for structured logging purposes.