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 ¶
- func Errorf(ctx context.Context, format string, args ...any)
- func Exitf(ctx context.Context, format string, args ...any)
- func Fatalf(ctx context.Context, format string, args ...any)
- func Infof(ctx context.Context, format string, args ...any)
- func Log(ctx context.Context, e logging.Entry)
- func LogSync(ctx context.Context, e logging.Entry) error
- func NewContext(ctx context.Context, logger *Logger) context.Context
- func NewSpan(ctx context.Context, trace, spanID string, labels map[string]string) context.Context
- func Warningf(ctx context.Context, format string, args ...any)
- type Logger
- func (l *Logger) Close() error
- func (l *Logger) Entry(severity logging.Severity, payload any) logging.Entry
- func (l *Logger) Error(args ...any)
- func (l *Logger) Errorf(format string, args ...any)
- func (l *Logger) Errorln(args ...any)
- func (l *Logger) Exitf(format string, args ...any)
- func (l *Logger) Fatal(args ...any)
- func (l *Logger) Fatalf(format string, args ...any)
- func (l *Logger) Fatalln(args ...any)
- func (l *Logger) Info(args ...any)
- func (l *Logger) Infof(format string, args ...any)
- func (l *Logger) Infoln(args ...any)
- func (l *Logger) Log(e logging.Entry)
- func (l *Logger) LogSync(ctx context.Context, e logging.Entry) error
- func (l *Logger) Span(trace, spanID string, labels map[string]string) *Logger
- func (l *Logger) URL() string
- func (l *Logger) V(level int) bool
- func (l *Logger) Warning(args ...any)
- func (l *Logger) Warningf(format string, args ...any)
- func (l *Logger) Warningln(args ...any)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewContext ¶
NewContext sets the given logger to the context.
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 ¶
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) Fatal ¶
Fatal logs at fatal log level in the manner of fmt.Print with stacktrace, and exit.
func (*Logger) Fatalf ¶
Fatalf logs at fatal log level in the manner of fmt.Printf with stacktrace, and exit.
func (*Logger) Fatalln ¶
Fatalln logs at fatal log level in the manner of fmt.Println with stacktrace, and exit.