log

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2022 License: MIT Imports: 14 Imported by: 1

Documentation

Overview

Package log implements a simple logging package

Index

Constants

View Source
const CtxKey = logContextKeyType("Ong-logID")

CtxKey is the name under which this library stores the http cookie, http header and context key for the logID.

Variables

This section is empty.

Functions

func GetId

func GetId(ctx context.Context) string

GetId returns a logID which is fetched either from the provided context or auto-generated.

Types

type F

type F map[string]interface{}

F is the fields to use as a log message.

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

func New

func New(
	ctx context.Context,
	w io.Writer,
	maxMsgs int,
) Logger

New creates a new logger.

func (Logger) Error

func (l Logger) Error(e error, fs ...F)

Error will log at the Info level.

func (Logger) Info

func (l Logger) Info(f F)

Info will log at the Info level.

func (Logger) StdLogger

func (l Logger) StdLogger() *stdLog.Logger

StdLogger returns a logger from the Go standard library log package. That logger will use l as its output. usage:

l := log.New(ctx, os.Stdout, 100, true)
stdLogger := l.StdLogger()
stdLogger.Println("hey")

func (Logger) WithCaller

func (l Logger) WithCaller() Logger

WithCaller return a new logger, based on l, that will include callers info in its output.

func (Logger) WithCtx

func (l Logger) WithCtx(ctx context.Context) Logger

WithCtx return a new logger, based on l, with the given ctx.

func (Logger) WithFields

func (l Logger) WithFields(f F) Logger

WithFields return a new logger, based on l, that will include the given fields in all its output.

func (Logger) WithImmediate

func (l Logger) WithImmediate() Logger

WithImmediate return a new logger, based on l, that will log immediately without buffering.

func (Logger) Write

func (l Logger) Write(p []byte) (n int, err error)

Write implements the io.Writer interface. This is useful if you want to set this logger as a writer for the standard library log.

usage:

l := log.New(ctx, os.Stdout, 100, true)
stdLogger := stdLog.New(l, "stdlib", stdLog.LstdFlags)
stdLogger.Println("hello world")

Jump to

Keyboard shortcuts

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