log

package module
Version: v0.0.0-...-d803520 Latest Latest
Warning

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

Go to latest
Published: May 6, 2020 License: MIT Imports: 6 Imported by: 2

README

package log deprecated use https://gitoa.ru/go-4devs/log

Build Status codecov GoDoc Go Report Card goreadme

Package log logged data by handler and use processor, exposes eight methods to write logs to the eight RFC 5424 levels.

Sub Packages


Created by goreadme

Documentation

Overview

Package log logged data by handler and use processor, exposes eight methods to write logs to the eight RFC 5424 levels.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Alert

func Alert(ctx context.Context, args ...interface{})

Alert log by alert level

func AlertKV

func AlertKV(ctx context.Context, msg string, args ...interface{})

AlertKV log by alert level and key-values

func Alertf

func Alertf(ctx context.Context, format string, args ...interface{})

Alertf log by alert level by format and arguments

func Crit

func Crit(ctx context.Context, args ...interface{})

Crit log by critical level

func CritKV

func CritKV(ctx context.Context, msg string, args ...interface{})

CritKV log by critcal level and key-values

func Critf

func Critf(ctx context.Context, format string, args ...interface{})

Critf log by critical level by format and arguments

func Debug

func Debug(ctx context.Context, args ...interface{})

Debug log by debug level

func DebugKV

func DebugKV(ctx context.Context, msg string, args ...interface{})

DebugKV log by debug level and key-values

func Debugf

func Debugf(ctx context.Context, format string, args ...interface{})

Debugf log by debug level by format and arguments

func Emerg

func Emerg(ctx context.Context, args ...interface{})

Emerg log by emergency level

func EmergKV

func EmergKV(ctx context.Context, msg string, args ...interface{})

EmergKV log by emergency level and key-values

func Emergf

func Emergf(ctx context.Context, format string, args ...interface{})

Emergf log by emergency level by format and arguments

func Err

func Err(ctx context.Context, args ...interface{})

Err log by error level

func ErrKV

func ErrKV(ctx context.Context, msg string, args ...interface{})

ErrKV log by error level and key-values

func Errf

func Errf(ctx context.Context, format string, args ...interface{})

Errf log by error level by format and arguments

func Info

func Info(ctx context.Context, args ...interface{})

Info log by info level

func InfoKV

func InfoKV(ctx context.Context, msg string, args ...interface{})

InfoKV log by info level and key-values

func Infof

func Infof(ctx context.Context, format string, args ...interface{})

Infof log by info level by format and arguments

func Notice

func Notice(ctx context.Context, args ...interface{})

Notice log by notice level

func NoticeKV

func NoticeKV(ctx context.Context, msg string, args ...interface{})

NoticeKV log by notice level and key-values

func Noticef

func Noticef(ctx context.Context, format string, args ...interface{})

Noticef log by notice level by format and arguments

func SetLogger

func SetLogger(l *Logger)

SetLogger set logger

func Warn

func Warn(ctx context.Context, args ...interface{})

Warn log by warning level

func WarnKV

func WarnKV(ctx context.Context, msg string, args ...interface{})

WarnKV log by warning level and key-values

func Warnf

func Warnf(ctx context.Context, format string, args ...interface{})

Warnf log by warning level by format and arguments

Types

type Field

type Field struct {
	Key   string
	Value interface{}
}

Field struct

func (Field) String

func (f Field) String() string

String implent stringer

type Fields

type Fields []Field

Fields slice field

func (Fields) String

func (f Fields) String() string

String implement stringer

type Handler

type Handler func(ctx context.Context, level Level, msg string, fields Fields)

Handler logged message

func NewHandler

func NewHandler(handler Handler, mw ...Middleware) Handler

NewHandler add middleware to handler

func NewStdHandler

func NewStdHandler(logger *log.Logger, lvl Level) Handler

NewStdHandler create handler for the log package

type Level

type Level uint8

Level log.

const (
	LevelEmergency Level = iota //emergency
	LevelAlert                  //alert
	LevelCritical               //critical
	LevelError                  //error
	LevelWarning                //warning
	LevelNotice                 //notice
	LevelInfo                   //info
	LevelDebug                  //debug
)

awailable log levels.

func (Level) String

func (i Level) String() string

type Logger

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

Logger log

func GetLogger

func GetLogger() *Logger

GetLogger get global logger

func New

func New(handler Handler, mw ...Middleware) *Logger

New create new logger by handler

Example
ctx := context.Background()

logger := New(NewStdHandler(log.New(os.Stdout, "", 0), LevelInfo))
logger.Info(ctx, "same message")
Output:

msg="same message"
Example (DebugKV)
ctx := context.Background()

logger := New(NewStdHandler(log.New(os.Stdout, "", 0), LevelDebug), levelInfo)
logger.DebugKV(ctx, "same message", "error", os.ErrNotExist)
Output:

msg="same message" error=file does not exist level=debug
Example (Errf)
ctx := context.Background()

logger := New(NewStdHandler(log.New(os.Stdout, "", 0), LevelInfo))
logger.Errf(ctx, "same message %d", 1)
Output:

msg="same message 1"
Example (Level)
ctx := context.Background()

logger := New(NewStdHandler(log.New(os.Stdout, "", 0), LevelError), levelInfo)
logger.Info(ctx, "same message")
// Output:

logger.Err(ctx, "same error message")
Output:

msg="same error message" level=error

func (*Logger) Alert

func (l *Logger) Alert(ctx context.Context, args ...interface{})

Alert log by alert level

func (*Logger) AlertKV

func (l *Logger) AlertKV(ctx context.Context, msg string, args ...interface{})

AlertKV log by alert level and key-values

func (*Logger) Alertf

func (l *Logger) Alertf(ctx context.Context, format string, args ...interface{})

Alertf log by alert level by format and arguments

func (*Logger) Crit

func (l *Logger) Crit(ctx context.Context, args ...interface{})

Crit log by critical level

func (*Logger) CritKV

func (l *Logger) CritKV(ctx context.Context, msg string, args ...interface{})

CritKV log by critcal level and key-values

func (*Logger) Critf

func (l *Logger) Critf(ctx context.Context, format string, args ...interface{})

Critf log by critical level by format and arguments

func (*Logger) Debug

func (l *Logger) Debug(ctx context.Context, args ...interface{})

Debug log by debug level

func (*Logger) DebugKV

func (l *Logger) DebugKV(ctx context.Context, msg string, args ...interface{})

DebugKV log by debug level and key-values

func (*Logger) Debugf

func (l *Logger) Debugf(ctx context.Context, format string, args ...interface{})

Debugf log by debug level by format and arguments

func (*Logger) Emerg

func (l *Logger) Emerg(ctx context.Context, args ...interface{})

Emerg log by emergency level

func (*Logger) EmergKV

func (l *Logger) EmergKV(ctx context.Context, msg string, args ...interface{})

EmergKV log by emergency level and key-values

func (*Logger) Emergf

func (l *Logger) Emergf(ctx context.Context, format string, args ...interface{})

Emergf log by emergency level by format and arguments

func (*Logger) Err

func (l *Logger) Err(ctx context.Context, args ...interface{})

Err log by error level

func (*Logger) ErrKV

func (l *Logger) ErrKV(ctx context.Context, msg string, args ...interface{})

ErrKV log by error level and key-values

func (*Logger) Errf

func (l *Logger) Errf(ctx context.Context, format string, args ...interface{})

Errf log by error level by format and arguments

func (*Logger) Info

func (l *Logger) Info(ctx context.Context, args ...interface{})

Info log by info level

func (*Logger) InfoKV

func (l *Logger) InfoKV(ctx context.Context, msg string, args ...interface{})

InfoKV log by info level and key-values

func (*Logger) Infof

func (l *Logger) Infof(ctx context.Context, format string, args ...interface{})

Infof log by info level by format and arguments

func (*Logger) Notice

func (l *Logger) Notice(ctx context.Context, args ...interface{})

Notice log by notice level

func (*Logger) NoticeKV

func (l *Logger) NoticeKV(ctx context.Context, msg string, args ...interface{})

NoticeKV log by notice level and key-values

func (*Logger) Noticef

func (l *Logger) Noticef(ctx context.Context, format string, args ...interface{})

Noticef log by notice level by format and arguments

func (*Logger) Warn

func (l *Logger) Warn(ctx context.Context, args ...interface{})

Warn log by warning level

func (*Logger) WarnKV

func (l *Logger) WarnKV(ctx context.Context, msg string, args ...interface{})

WarnKV log by warning level and key-values

func (*Logger) Warnf

func (l *Logger) Warnf(ctx context.Context, format string, args ...interface{})

Warnf log by warning level by format and arguments

type Middleware

type Middleware func(ctx context.Context, level Level, msg string, fields Fields, handler Handler)

Middleware handle

func ChainMiddlerware

func ChainMiddlerware(mw ...Middleware) Middleware

ChainMiddlerware chain one or more middleware

type Processor

type Processor func(ctx context.Context) Field

Processor processsed additional field

Example
var ctxKey ctxKey = "requestID"
ctx := context.WithValue(context.Background(), ctxKey, "6a5fa048-7181-11ea-bc55-0242ac130003")
l := log.New(os.Stdout, "", 0)

logger := New(
	NewStdHandler(l, LevelInfo),
	levelInfo, ctxProcessor(ctxKey), apiVersion, goVersion,
)
logger.Info(ctx, "same message")
Output:

msg="same message" level=info requestID=6a5fa048-7181-11ea-bc55-0242ac130003 api=0.1.0 go=go1.13.4

Directories

Path Synopsis
lorgus module
Package processor add processors for the logger
Package processor add processors for the logger
zap module

Jump to

Keyboard shortcuts

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