clog

package
v0.0.0-...-9febfc8 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2025 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package clog provides context aware logging. It can store trace, spandID, arbitrary labels to each context. The main use case is to add build action context to each log entry automatically.

TODO(b/269367111): It's also worth considering to use slog.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Errorf

func Errorf(ctx context.Context, format string, args ...any)

Errorf logs at error log level in the manner of fmt.Printf.

func Exitf

func Exitf(ctx context.Context, format string, args ...any)

Exitf logs at fatal log level in the manner of fmt.Printf, and exit.

func Fatalf

func Fatalf(ctx context.Context, format string, args ...any)

Fatalf logs at fatal log level in the manner of fmt.Printf with stacktrace, and exit.

func Infof

func Infof(ctx context.Context, format string, args ...any)

Infof logs at info log level in the manner of fmt.Printf.

func Log

func Log(ctx context.Context, e logging.Entry)

Log logs an entry for the context.

func LogSync

func LogSync(ctx context.Context, e logging.Entry) error

LogSync logs an entry syncrhonously for the context.

func NewContext

func NewContext(ctx context.Context, logger *Logger) context.Context

NewContext sets the given logger to the context.

func NewSpan

func NewSpan(ctx context.Context, trace, spanID string, labels map[string]string) context.Context

NewSpan sets a new logger.Span with the given labels to the context.

func Warningf

func Warningf(ctx context.Context, format string, args ...any)

Warningf logs at warning log level in the manner of fmt.Printf.

Types

type Logger

type Logger struct {
	// Formatter is a formatter of the entry for glog.
	// Default to `fmt.Sprintf("%v", e.Payload)`.
	Formatter func(e logging.Entry) string
	// contains filtered or unexported fields
}

Logger holds the trace, spanID, arbitrary labels of the context. It also can have custom formatter to generate a log content.

func FromContext

func FromContext(ctx context.Context) *Logger

FromContext returns a logger in the context, or returns a new logger.

func New

func New(ctx context.Context, client *logging.Client, logID, accessLogID string, res *mrpb.MonitoredResource, opts ...logging.LoggerOption) (*Logger, error)

New creates a new Logger.

func (*Logger) Close

func (l *Logger) Close() error

Close closes the logger. it will flush log entries.

func (*Logger) Entry

func (l *Logger) Entry(severity logging.Severity, payload any) logging.Entry

Entry creates a new log entry for the given severity.

func (*Logger) Error

func (l *Logger) Error(args ...any)

Error logs at error log level in the manner of fmt.Print.

func (*Logger) Errorf

func (l *Logger) Errorf(format string, args ...any)

Errorf logs at error log level in the manner of fmt.Printf.

func (*Logger) Errorln

func (l *Logger) Errorln(args ...any)

Errorln logs at error log level in the manner of fmt.Println.

func (*Logger) Exitf

func (l *Logger) Exitf(format string, args ...any)

Exitf logs at fatal log level in the manner of fmt.Printf, and exit.

func (*Logger) Fatal

func (l *Logger) Fatal(args ...any)

Fatal logs at fatal log level in the manner of fmt.Print with stacktrace, and exit.

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, args ...any)

Fatalf logs at fatal log level in the manner of fmt.Printf with stacktrace, and exit.

func (*Logger) Fatalln

func (l *Logger) Fatalln(args ...any)

Fatalln logs at fatal log level in the manner of fmt.Println with stacktrace, and exit.

func (*Logger) Info

func (l *Logger) Info(args ...any)

Info logs at info log level in the manner of fmt.Print.

func (*Logger) Infof

func (l *Logger) Infof(format string, args ...any)

Infof logs at info log level in the manner of fmt.Printf.

func (*Logger) Infoln

func (l *Logger) Infoln(args ...any)

Infoln logs at info log level in the manner of fmt.Println.

func (*Logger) Log

func (l *Logger) Log(e logging.Entry)

Log logs an entry.

func (*Logger) LogSync

func (l *Logger) LogSync(ctx context.Context, e logging.Entry) error

LogSync logs an entry synchronously for the context.

func (*Logger) Span

func (l *Logger) Span(trace, spanID string, labels map[string]string) *Logger

Span returns a sub logger for the trace span.

func (*Logger) URL

func (l *Logger) URL() string

URL returns url of cloud logging.

func (*Logger) V

func (l *Logger) V(level int) bool

V checks at verbose log level.

func (*Logger) Warning

func (l *Logger) Warning(args ...any)

Warning logs at warning log level in the manner of fmt.Print.

func (*Logger) Warningf

func (l *Logger) Warningf(format string, args ...any)

Warningf logs at warning log level in the manner of fmt.Printf.

func (*Logger) Warningln

func (l *Logger) Warningln(args ...any)

Warningln logs at warning log level in the manner of fmt.Println.

Jump to

Keyboard shortcuts

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