logid

package
v0.9.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultLogIDGenerator

func DefaultLogIDGenerator(ctx context.Context) string

DefaultLogIDGenerator generates a default log ID using a combination of random numbers and timestamps. `SetLogIDExtra` can be used to add extra information to each log ID. The format is `<version><timestamp><extra><random>`, where - `<version>` is the version string, "02" by default - `<timestamp>` is the timestamp in milliseconds, consuming 13 digits - `<extra>` is the extra information string, empty by default - `<random>` is the random number, consuming 6 hex digits It returns a string that represents the generated log ID.

func GenerateStreamLogID

func GenerateStreamLogID(ctx context.Context) string

GenerateStreamLogID generates a stream log ID using the provided context.

ctx: The context used to generate the log ID. Returns: The generated stream log ID as a string.

Note: ctx is for generating the log id, but the log id will not be added to the context. You should call `NewCtxWithStreamLogID` to add the log id to the context.

func GetStreamLogID

func GetStreamLogID(ctx context.Context) string

GetStreamLogID returns the log ID from the context if it exists.

It takes a `context.Context` as a parameter. It returns a `string` which is the log ID, or an empty string if it doesn't exist.

func NewCtxWithStreamLogID

func NewCtxWithStreamLogID(ctx context.Context, logID string) context.Context

NewCtxWithStreamLogID returns a new context with the provided log ID added as a value.

Parameters:

  • ctx: The original context.
  • logID: The log ID to be added.

Return:

  • context.Context: The new context with the log ID added.

func SetLogIDExtra

func SetLogIDExtra(extra string)

SetLogIDExtra allows custom log id extra For example, local ip address can be used to improve the uniqueness

func SetLogIDGenerator

func SetLogIDGenerator(g func(ctx context.Context) string)

SetLogIDGenerator allows custom log id generator

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL