logid

package
v2.14.7 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: MIT Imports: 9 Imported by: 0

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 Gen

func Gen() string

Gen generates a new log ID string using the default generator.

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.

func Decode

func Decode(s string) (info Info)

Decode decodes a log ID string and returns the parsed information.

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"

func NewV1Gen

func NewV1Gen() *V1Gen

NewV1Gen creates a new v1 log ID generator.

func (*V1Gen) Gen added in v2.12.0

func (p *V1Gen) Gen() string

Gen generates a new log ID string.

type V1Info added in v2.12.0

type V1Info interface {
	Info
	Time() time.Time
	MachineID() string
	Random() string
}

V1Info holds parsed information of a v1 log ID string.

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"

func NewV2Gen

func NewV2Gen(ip net.IP) *V2Gen

NewV2Gen creates a new v2 log ID generator.

func (*V2Gen) Gen added in v2.12.0

func (p *V2Gen) Gen() string

Gen generates a new log ID string.

type V2Info added in v2.12.0

type V2Info interface {
	Info
	Time() time.Time
	IP() net.IP
	Random() string
}

V2Info holds parsed information of a v2 log ID string.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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