Documentation ¶
Index ¶
- func DefaultLogIDGenerator(ctx context.Context) string
- func GenerateStreamLogID(ctx context.Context) string
- func GetStreamLogID(ctx context.Context) string
- func NewCtxWithStreamLogID(ctx context.Context, logID string) context.Context
- func SetLogIDExtra(extra string)
- func SetLogIDGenerator(g func(ctx context.Context) string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultLogIDGenerator ¶
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 ¶
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 ¶
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 ¶
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 ¶
SetLogIDGenerator allows custom log id generator
Types ¶
This section is empty.