Documentation
¶
Index ¶
- Constants
- Variables
- func ContextWithRequestID(ctx context.Context) context.Context
- func DBG(ctx context.Context, metadata any, message string)
- func ERR(ctx context.Context, err error, message string)
- func ErrMetadata(err error) map[string]any
- func FTL(ctx context.Context, err error, message string)
- func GenRequestID() string
- func GetActorID(ctx context.Context) int
- func GetActorIDFromMetadata(ctx context.Context) int
- func GetRequestID(ctx context.Context) string
- func INF(ctx context.Context, metadata any, message string)
- func Metadata(detail any) map[string]any
- func New(configs ...Config) error
- func NewContext(in ...context.Context) context.Context
- func SetActorID(ctx context.Context, id int) context.Context
- func SetRequestID(ctx context.Context, id string) context.Context
- func SetRequestIDFromMetadata(ctx context.Context) context.Context
- func TRC(ctx context.Context, metadata any, message string)
- func WRN(ctx context.Context, err error, message string)
- type Config
- type KV
- type Logger
- type PGX
- type ZeroLogger
- func (z *ZeroLogger) Debug(requestID string, actorID int, fields map[string]any, message string)
- func (z *ZeroLogger) Error(requestID string, actorID int, err error, fields map[string]any, ...)
- func (z *ZeroLogger) Fatal(requestID string, actorID int, err error, fields map[string]any, ...)
- func (z *ZeroLogger) Info(requestID string, actorID int, fields map[string]any, message string)
- func (z *ZeroLogger) Trace(requestID string, actorID int, fields map[string]any, message string)
- func (z *ZeroLogger) Warn(requestID string, actorID int, err error, fields map[string]any, ...)
Constants ¶
const ( // RequestID is a random generated string to identify each request. // Example: qwerty1234. RequestID = tags.RequestID UserID = tags.ActorID )
Key for standardized context value.
const ( CtxKeyRequestID = contextKey(RequestID) CtxKeyUserID = contextKey(UserID) )
Variables ¶
var ( // DefaultConfig is a configuration to create: // - Non JSON structured. // - No app name. // - Output to os.Stderr. DefaultConfig = Config{ Debug: true, AppName: "", Filename: "", } )
Functions ¶
func ContextWithRequestID ¶
ContextWithRequestID checks if current context has request id already and assign one if none found. Use for middleware and intercept all incoming requests to assign request id to the context if it doesn't exist.
func ErrMetadata ¶
ErrMetadata returns a metadata constructed from error. If you are printing a log, this metadata should always be set. Useful if you want to trace log with certain information.
func GetActorID ¶ added in v1.2.0
func GetActorIDFromMetadata ¶ added in v1.2.0
func GetRequestID ¶
GetContextID returns a request id assigned inside a context.
func NewContext ¶
NewContext returns a context with built-in request id.
func SetRequestID ¶
SetRequestID returns a context with assigned request id.
func SetRequestIDFromMetadata ¶
SetRequestIDFromMetadata returns a context with request id and context id value if they exists in metadata.
Types ¶
type Logger ¶
type Logger interface {
Trace(
requestID string,
actorID int,
fields map[string]any,
message string,
)
Debug(
requestID string,
actorID int,
fields map[string]any,
message string,
)
Info(
requestID string,
actorID int,
fields map[string]any,
message string,
)
Warn(
requestID string,
actorID int,
err error,
fields map[string]any,
message string,
)
Error(
requestID string,
actorID int,
err error,
fields map[string]any,
message string,
)
Fatal(
requestID string,
actorID int,
err error,
fields map[string]any,
message string,
)
}
Logger is an interface that provides logging functionality.