Documentation ¶
Overview ¶
Package logid provides log ID generators to help service observability, such as logging, tracing, metrics, etc.
Index ¶
Constants ¶
View Source
const IPUnknown = "0000000"
IPUnknown represents unknown IP address.
Variables ¶
This section is empty.
Functions ¶
func SetDefault ¶
func SetDefault(gen Generator)
SetDefault changes the default generator.
The default generator may be changed by the main program, but generally library code shall not call this function.
Types ¶
type Generator ¶
type Generator interface { // Gen generates a new log ID string, it should always return // a valid log ID, and don't generate duplicate log IDs. Gen() string }
type Info ¶
type Info interface { // Valid tells whether it is a valid log ID generated by this package. Valid() bool // Version returns the version of the log ID. Version() byte // String returns the human-friendly string representation of the log ID, // e.g. // "1|20240125.10:07:20.485+0800|M0RY2MKE72XWXGSW|140NFEAD8J" // "2|20240125.10:07:20.486+0800|fdbd:dc01:16:16::94|CBDDWZEJH4" String() string }
Info holds parsed information of a log ID string.
type V1Gen ¶ added in v2.12.0
type V1Gen struct {
// contains filtered or unexported fields
}
V1Gen is a v1 log ID generator.
A v1 log ID is consisted of the following parts:
- 9 bytes milli timestamp, in base32 form
- 16 bytes hash of the machine ID of current host if available, else 16 bytes random data
- 10 bytes random data
- 1 byte version flag "1"
e.g. "1HMZ5YAD5M0RY2MKE72XWXGSW140NFEAD8J1"
type V2Gen ¶ added in v2.12.0
type V2Gen struct {
// contains filtered or unexported fields
}
V2Gen is a v2 log ID generator.
A v2 log ID is consisted by the following parts:
- 9 bytes milli timestamp, in base32 form
- 7 bytes IPv4 address, or 26 bytes IPv6 address, in base32 form
- 10 bytes random data
- 1 byte version flag "2"
e.g.
- "1HMZ5YAD6041061072VFVV7C2J2"
- "1HMZ5YAD6ZPYXR0802R01C00000000000JGCBDDWZEJH42"
Click to show internal directories.
Click to hide internal directories.