glog

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2021 License: MIT Imports: 9 Imported by: 11

README

Glog

glog is an abstraction for various Go language log libraries.

The Logger interface is in maintenance-mode to prevent broken changes to projects based on it. But we will add more different implementations (wrappers) for various log libraries.

Logger doesn't implements "Fatal" level because logger shouldn't terminate a process. You can use Panic of Panicf methods without os.Exit(1) and terminate process clearly.

context.go implements helper functions to attach logger over a context. From context will return empty usable logger if there is no logger attached. It prevents app chash if context doesn't conains Logger implementations.

grpc_interceptors.go implemets gRPC interceptors to replace embeeded gRPC logger by the Logger implementations.

All interface implementations are located in different directories. You can use any of it or implement your own one.

This repository will be archived when Go implements it's own standard logger interface.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContext

func NewContext(parent context.Context, l Logger) context.Context

NewContext adds Logger to the Context.

func ReplaceGrpcLogger

func ReplaceGrpcLogger(l Logger)

ReplaceGrpcLogger sets the given Logger as a gRPC-level logger v2. This should be called *before* any other initialization, preferably from init() functions.

func StreamServerInterceptor

func StreamServerInterceptor(l Logger) grpc.StreamServerInterceptor

StreamServerInterceptor returns a new streaming server interceptor that adds Logger to the context.

func UnaryServerInterceptor

func UnaryServerInterceptor(l Logger) grpc.UnaryServerInterceptor

UnaryServerInterceptor returns a new unary server interceptors that adds Logger to the context.

Types

type Field

type Field struct {
	K string
	V interface{}
}

Field contains key-value parameter for log prefix.

type Logger

type Logger interface {
	// Set updates logger's additional fields.
	Set(fields ...Field)
	// With returns a copy of the logger with additional fields.
	With(fields ...Field) Logger

	// Trace prints a log message with "trace" log level.
	Trace(args ...interface{})
	// Tracef prints a log message with "trace" log level and specified format.
	Tracef(format string, args ...interface{})

	// Debug prints a log message with "debug" log level.
	Debug(args ...interface{})
	// Debugf prints a log message with "debug" log level and specified format.
	Debugf(format string, args ...interface{})

	// Info prints a log message with "info" log level.
	Info(args ...interface{})
	// Infof prints a log message with "info" log level and specified format.
	Infof(format string, args ...interface{})

	// Warning prints a log message with "warning" log level.
	Warning(args ...interface{})
	// Warningf prints a log message with "warning" log level and specified format.
	Warningf(format string, args ...interface{})

	// Error prints a log message with "error" log level.
	Error(args ...interface{})
	// Errorf prints a log message with "error" log level and specified format.
	Errorf(format string, args ...interface{})

	// Panic prints a log message with "panic" log level. Then calls panic().
	Panic(args ...interface{})
	// Panicf prints a log message with "error" log level and specified format. Then calls panic().
	Panicf(format string, args ...interface{})
}

Logger interface is responsible for various logging systems.

func FromContext

func FromContext(ctx context.Context) Logger

FromContext gets Logger from the Context.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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