log0

package module
v0.173.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2021 License: BSD-3-Clause Imports: 16 Imported by: 0

README

log0

Build Status Go Reference

JSON logging for Go.
Source files are distributed under the BSD-style license found in the LICENSE file.

About

The software is considered to be at a alpha level of readiness - its extremely slow and allocates a lots of memory)

Install

go get github.com/kvlog/log0@v0.173.0

Usage

Set log0 as global logger

package main

import (
    "os"
    "log"

    "github.com/kvlog/log0"
)

func main() {
    l := &log0.Log{
        Output:  os.Stdout,
        Keys:    [4]encoding.TextMarshaler{log0.String("message"), log0.String("excerpt")},
        Trunc:   12,
        Marks:   [3][]byte{[]byte("…")},
        Replace: [][2][]byte{[2][]byte{[]byte("\n"), []byte(" ")}},
    }
    log.SetFlags(0)
    log.SetOutput(l)

    log.Print("Hello,\nWorld!")
}

Output:

{
    "message":"Hello,\nWorld!",
    "excerpt":"Hello, World…"
}

Use as GELF formater

package main

import (
    "log"
    "os"

    "github.com/kvlog/log0"
)

func main() {
    l := log0.GELF()
    l.Output = os.Stdout
    log.SetFlags(0)
    log.SetOutput(l)
    log.Print("Hello,\nGELF!")
}

Output:

{
    "version":"1.1",
    "short_message":"Hello, GELF!",
    "full_message":"Hello,\nGELF!",
    "timestamp":1602785340
}

Caveat: numeric types appears in the message as a string

package main

import (
    "log"
    "os"

    "github.com/kvlog/log0"
)

func main() {
    l := log0.Log{
        Output: os.Stdout,
        Keys:   [4]encoding.TextMarshaler{log0.String("message")},
    }
    log.SetFlags(0)
    log.SetOutput(l)

    log.Print(123)
    log.Print(3.21)
}

Output 1:

{
    "message":"123"
}

Output 2:

{
    "message":"3.21"
}

Benchmark

go test -bench=. ./...
goos: linux
goarch: amd64
pkg: github.com/kvlog/log0
cpu: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
BenchmarkLog0/io.Writer_77-8         	  163160	      7221 ns/op	    1722 B/op	      53 allocs/op
BenchmarkLog0/fmt.Fprint_io.Writer_1127-8         	  102769	     12399 ns/op	    3401 B/op	      61 allocs/op
PASS
ok  	github.com/kvlog/log0	3.835s

Documentation

Overview

Package log0 is a JSON logging.

Index

Constants

View Source
const (
	Original = iota
	Excerpt
	Trail
	File
)
View Source
const (
	Trunc = iota
	Empty
	Blank
)

Variables

This section is empty.

Functions

func Any

func Any(v interface{}) anyV

Any returns stringer/JSON/text marshaler for any type.

func Anys

func Anys(s ...interface{}) anyS

Anys returns stringer/JSON/text marshaler for the slice of any type.

func Bool

func Bool(v bool) boolV

Bool returns stringer/JSON/text marshaler for the bool type.

func Boolp

func Boolp(p *bool) boolP

Boolp returns stringer/JSON/text marshaler for the bool pointer type.

func Boolps

func Boolps(s ...*bool) boolPS

Boolps returns stringer/JSON/text marshaler for slice of bool pointers type.

func Bools

func Bools(s ...bool) boolS

Bools returns stringer/JSON/text marshaler for the bool slice type.

func Bytes

func Bytes(s ...byte) byteS

Bytes returns stringer/JSON/text marshaler for slice of bytes type.

func Bytesp

func Bytesp(p *[]byte) byteSP

Bytesp returns stringer/JSON/text marshaler for the pointer to byte slice type.

func Bytesps

func Bytesps(a ...*[]byte) byteSPS

Bytesps returns stringer/JSON/text marshaler for slice of pointers to byte slice type.

func Bytess

func Bytess(s ...[]byte) byteSS

Bytess returns stringer/JSON/text marshaler for the slice of byte slice type.

func Complex128

func Complex128(v complex128) complex128V

Complex128 returns stringer/JSON/text marshaler for the complex128 type.

func Complex128p

func Complex128p(p *complex128) complex128P

Complex128p returns stringer/JSON/text marshaler for the complex128 pointer type.

func Complex128ps

func Complex128ps(a ...*complex128) complex128PS

Complex128ps returns stringer/JSON/text marshaler for the complex128 pointer slice type.

func Complex128s

func Complex128s(s ...complex128) complex128S

Complex128s returns stringer/JSON/text marshaler for the complex128 slice type.

func Complex64

func Complex64(v complex64) complex64V

Complex64 returns stringer/JSON/text marshaler for the complex64 type.

func Complex64p

func Complex64p(p *complex64) complex64P

Complex64p returns stringer/JSON/text marshaler for the complex64 pointer type.

func Complex64ps

func Complex64ps(s ...*complex64) complex64PS

Complex64ps returns stringer/JSON/text marshaler for the slice of complex64 pointers type.

func Complex64s

func Complex64s(s ...complex64) complex64S

Complex64s returns stringer/JSON/text marshaler for the complex64 type.

func Duration

func Duration(v time.Duration) durationV

Duration returns stringer/JSON/text marshaler for the time duration type.

func Durationp

func Durationp(p *time.Duration) durationP

Durationp returns stringer/JSON/text marshaler for the time duration pointer type.

func Durationps

func Durationps(s ...*time.Duration) durationPS

Durationps returns stringer/JSON/text marshaler for the time duration pointer slice type.

func Durations

func Durations(s ...time.Duration) durationS

Durations returns stringer/JSON/text marshaler for time duration slice type.

func Error

func Error(v error) errorV

Error returns stringer/JSON/text marshaler for the error type.

func Errorp

func Errorp(p *error) errorP

Errorp returns stringer/JSON/text marshaler for the error pointer type.

func Errorps

func Errorps(s ...*error) errorPS

Errorps returns stringer/JSON/text marshaler for the slice of error pointers type.

func Errors

func Errors(s ...error) errorS

Errors returns stringer/JSON/text marshaler for the error slice type.

func Float32

func Float32(v float32) float32V

Float32 returns stringer/JSON/text marshaler for the float32 type.

func Float32p

func Float32p(p *float32) float32P

Float32p returns stringer/JSON/text marshaler for the float32 pointer type.

func Float32ps

func Float32ps(a ...*float32) float32PS

Float32ps returns stringer/JSON/text marshaler for the float32 pointer slice type.

func Float32s

func Float32s(s ...float32) float32S

Float32s returns stringer/JSON/text marshaler for the float32 slice type.

func Float64

func Float64(v float64) float64V

Float64 returns stringer/JSON/text marshaler for the float64 type.

func Float64p

func Float64p(p *float64) float64P

Float64p returns stringer/JSON/text marshaler for the float64 pointer type.

func Float64ps

func Float64ps(a ...*float64) float64PS

Float64ps returns stringer/JSON/text marshaler for the float64 pointer slice type.

func Float64s

func Float64s(s ...float64) float64S

Float64s returns stringer/JSON/text marshaler for the float64 slice type.

func Func

func Func(v func() KV) funcV

Func returns stringer/JSON/text marshaler for the custom function type.

func Int

func Int(v int) intV

Int returns stringer/JSON/text marshaler for the int type.

func Int16

func Int16(v int16) int16V

Int16 returns stringer/JSON/text marshaler for the int16 type.

func Int16p

func Int16p(p *int16) int16P

Int16p returns stringer/JSON/text marshaler for the int16 pointer type.

func Int16ps

func Int16ps(a ...*int16) int16PS

Int16ps returns stringer/JSON/text marshaler for the int16 pointer slice type.

func Int16s

func Int16s(s ...int16) int16S

Int16s returns stringer/JSON/text marshaler for the int16 slice type.

func Int32

func Int32(v int32) int32V

Int32 returns stringer/JSON/text marshaler for the int32 type.

func Int32p

func Int32p(p *int32) int32P

Int32p returns stringer/JSON/text marshaler for the int32 pointer type.

func Int32ps

func Int32ps(a ...*int32) int32PS

Int32ps returns stringer/JSON/text marshaler for the int32 pointer slice type.

func Int32s

func Int32s(s ...int32) int32S

Int32s returns stringer/JSON/text marshaler for the int32 slice type.

func Int64

func Int64(v int64) int64V

Int64 returns stringer/JSON/text marshaler for the int64 type.

func Int64p

func Int64p(p *int64) int64P

Int64p returns stringer/JSON/text marshaler for the int64 pointer type.

func Int64ps

func Int64ps(a ...*int64) int64PS

Int64ps returns stringer/JSON/text marshaler for the int64 pointer slice type.

func Int64s

func Int64s(s ...int64) int64S

Int64s returns stringer/JSON/text marshaler for the int64 slice type.

func Int8

func Int8(v int8) int8V

Int8 returns stringer/JSON/text marshaler for the int8 type.

func Int8p

func Int8p(p *int8) int8P

Int8p returns stringer/JSON/text marshaler for the int8 pointer type.

func Int8ps

func Int8ps(a ...*int8) int8PS

Int8ps returns stringer/JSON/text marshaler for the int8 pointer slice type.

func Int8s

func Int8s(s ...int8) int8S

Int8s returns stringer/JSON/text marshaler for the int8 slice type.

func Intp

func Intp(p *int) intP

Intp returns stringer/JSON/text marshaler for the int pointer type.

func Intps

func Intps(a ...*int) intPS

Intps returns stringer/JSON/text marshaler for the int pointer slice type.

func Ints

func Ints(s ...int) intS

Ints returns stringer/JSON/text marshaler for the int slice type.

func JSON

func JSON(s ...KV) jsonV

JSON returns stringer/JSON/text marshaler for the KV slice type.

func JSONMarshalers

func JSONMarshalers(s ...json.Marshaler) jsonMarshalerS

JSONMarshalers returns stringer/JSON/text marshaler for the JSON marshaler slice type.

func Raw

func Raw(v []byte) rawV

Raw returns stringer/JSON/text marshaler for the raw byte slice.

func Rawp

func Rawp(p *[]byte) rawP

Rawp returns stringer/JSON/text marshaler for the raw byte slice pointer.

func Rawps

func Rawps(s ...*[]byte) rawPS

Rawps returns stringer/JSON/text marshaler for the slice of byte slice pointers type.

func Raws

func Raws(s ...[]byte) rawS

Raws returns stringer/JSON/text marshaler for the slice of byte slice type.

func Reflect

func Reflect(v interface{}) reflectV

func Reflects

func Reflects(s ...interface{}) reflectS

func Runes

func Runes(s ...rune) runeS

Runes returns stringer/JSON/text marshaler for the rune slice type.

func Runesp

func Runesp(p *[]rune) runeSP

Runesp returns stringer/JSON/text marshaler for the rune pointer slice type.

func Runesps

func Runesps(a ...*[]rune) runeSPS

Runesps returns stringer/JSON/text marshaler for slice of pointers to rune slice type.

func String

func String(v string) stringV

String returns stringer/JSON/text marshaler for the string type.

func StringAny

func StringAny(k string, v interface{}) kvm

func StringBool

func StringBool(k string, v bool) kvm

func StringBoolp

func StringBoolp(k string, v *bool) kvm

func StringBools

func StringBools(k string, v ...bool) kvm

func StringBytes

func StringBytes(k string, v ...byte) kvm

func StringBytesp

func StringBytesp(k string, v *[]byte) kvm

func StringBytess

func StringBytess(k string, v ...[]byte) kvm

func StringBytessp

func StringBytessp(k string, v ...*[]byte) kvm

func StringComplex128

func StringComplex128(k string, v complex128) kvm

func StringComplex128p

func StringComplex128p(k string, v *complex128) kvm

func StringComplex64

func StringComplex64(k string, v complex64) kvm

func StringComplex64p

func StringComplex64p(k string, v *complex64) kvm

func StringDuration

func StringDuration(k string, v time.Duration) kvm

func StringDurationp

func StringDurationp(k string, v *time.Duration) kvm

func StringError

func StringError(k string, v error) kvm

func StringErrors

func StringErrors(k string, v ...error) kvm

func StringFloat32

func StringFloat32(k string, v float32) kvm

func StringFloat32p

func StringFloat32p(k string, v *float32) kvm

func StringFloat64

func StringFloat64(k string, v float64) kvm

func StringFloat64p

func StringFloat64p(k string, v *float64) kvm

func StringFunc

func StringFunc(k string, v func() KV) kvm

func StringInt

func StringInt(k string, v int) kvm

func StringInt16

func StringInt16(k string, v int16) kvm

func StringInt16p

func StringInt16p(k string, v *int16) kvm

func StringInt32

func StringInt32(k string, v int32) kvm

func StringInt32p

func StringInt32p(k string, v *int32) kvm

func StringInt64

func StringInt64(k string, v int64) kvm

func StringInt64p

func StringInt64p(k string, v *int64) kvm

func StringInt8

func StringInt8(k string, v int8) kvm

func StringInt8p

func StringInt8p(k string, v *int8) kvm

func StringIntp

func StringIntp(k string, v *int) kvm

func StringLevel

func StringLevel(k string, v string) kvl

func StringRaw

func StringRaw(k string, v []byte) kvm

func StringReflect

func StringReflect(k string, v interface{}) kvm

func StringRunes

func StringRunes(k string, v ...rune) kvm

func StringRunesp

func StringRunesp(k string, v *[]rune) kvm

func StringString

func StringString(k string, v string) kvm

func StringStringp

func StringStringp(k string, v *string) kvm

func StringStrings

func StringStrings(k string, v ...string) kvm

func StringTime

func StringTime(k string, v time.Time) kvm

func StringTimep

func StringTimep(k string, v *time.Time) kvm

func StringUint

func StringUint(k string, v uint) kvm

func StringUint16

func StringUint16(k string, v uint16) kvm

func StringUint16p

func StringUint16p(k string, v *uint16) kvm

func StringUint32

func StringUint32(k string, v uint32) kvm

func StringUint32p

func StringUint32p(k string, v *uint32) kvm

func StringUint64

func StringUint64(k string, v uint64) kvm

func StringUint64p

func StringUint64p(k string, v *uint64) kvm

func StringUint8

func StringUint8(k string, v uint8) kvm

func StringUint8p

func StringUint8p(k string, v *uint8) kvm

func StringUintp

func StringUintp(k string, v *uint) kvm

func StringUintptr

func StringUintptr(k string, v uintptr) kvm

func StringUintptrp

func StringUintptrp(k string, v *uintptr) kvm

func Stringp

func Stringp(p *string) stringP

Stringp returns stringer/JSON/text marshaler for the string pointer type.

func Stringps

func Stringps(a ...*string) stringPS

Stringps returns stringer/JSON/text marshaler for the string pointer slice type.

func Strings

func Strings(s ...string) stringS

Strings returns stringer/JSON/text marshaler for the string slice type.

func Text

func Text(v encoding.TextMarshaler) textV

Text returns stringer/JSON/text marshaler for the encoding.TextMarshaler type.

func TextAny

func TextAny(k encoding.TextMarshaler, v interface{}) kvm

func TextBool

func TextBool(k encoding.TextMarshaler, v bool) kvm

func TextBoolp

func TextBoolp(k encoding.TextMarshaler, v *bool) kvm

func TextBytes

func TextBytes(k encoding.TextMarshaler, v ...byte) kvm

func TextBytesp

func TextBytesp(k encoding.TextMarshaler, v *[]byte) kvm

func TextComplex128

func TextComplex128(k encoding.TextMarshaler, v complex128) kvm

func TextComplex128p

func TextComplex128p(k encoding.TextMarshaler, v *complex128) kvm

func TextComplex64

func TextComplex64(k encoding.TextMarshaler, v complex64) kvm

func TextComplex64p

func TextComplex64p(k encoding.TextMarshaler, v *complex64) kvm

func TextDuration

func TextDuration(k encoding.TextMarshaler, v time.Duration) kvm

func TextDurationp

func TextDurationp(k encoding.TextMarshaler, v *time.Duration) kvm

func TextError

func TextError(k encoding.TextMarshaler, v error) kvm

func TextFloat32

func TextFloat32(k encoding.TextMarshaler, v float32) kvm

func TextFloat32p

func TextFloat32p(k encoding.TextMarshaler, v *float32) kvm

func TextFloat64

func TextFloat64(k encoding.TextMarshaler, v float64) kvm

func TextFloat64p

func TextFloat64p(k encoding.TextMarshaler, v *float64) kvm

func TextFunc

func TextFunc(k encoding.TextMarshaler, v func() json.Marshaler) kvm

func TextInt

func TextInt(k encoding.TextMarshaler, v int) kvm

func TextInt16

func TextInt16(k encoding.TextMarshaler, v int16) kvm

func TextInt16p

func TextInt16p(k encoding.TextMarshaler, v *int16) kvm

func TextInt32

func TextInt32(k encoding.TextMarshaler, v int32) kvm

func TextInt32p

func TextInt32p(k encoding.TextMarshaler, v *int32) kvm

func TextInt64

func TextInt64(k encoding.TextMarshaler, v int64) kvm

func TextInt64p

func TextInt64p(k encoding.TextMarshaler, v *int64) kvm

func TextInt8

func TextInt8(k encoding.TextMarshaler, v int8) kvm

func TextInt8p

func TextInt8p(k encoding.TextMarshaler, v *int8) kvm

func TextIntp

func TextIntp(k encoding.TextMarshaler, v *int) kvm

func TextRaw

func TextRaw(k encoding.TextMarshaler, v []byte) kvm

func TextReflect

func TextReflect(k encoding.TextMarshaler, v interface{}) kvm

func TextRunes

func TextRunes(k encoding.TextMarshaler, v ...rune) kvm

func TextRunesp

func TextRunesp(k encoding.TextMarshaler, v *[]rune) kvm

func TextString

func TextString(k encoding.TextMarshaler, v string) kvm

func TextStringp

func TextStringp(k encoding.TextMarshaler, v *string) kvm

func TextText

func TextText(k, v encoding.TextMarshaler) kvm

func TextTime

func TextTime(k encoding.TextMarshaler, v time.Time) kvm

func TextTimep

func TextTimep(k encoding.TextMarshaler, v *time.Time) kvm

func TextUint

func TextUint(k encoding.TextMarshaler, v uint) kvm

func TextUint16

func TextUint16(k encoding.TextMarshaler, v uint16) kvm

func TextUint16p

func TextUint16p(k encoding.TextMarshaler, v *uint16) kvm

func TextUint32

func TextUint32(k encoding.TextMarshaler, v uint32) kvm

func TextUint32p

func TextUint32p(k encoding.TextMarshaler, v *uint32) kvm

func TextUint64

func TextUint64(k encoding.TextMarshaler, v uint64) kvm

func TextUint64p

func TextUint64p(k encoding.TextMarshaler, v *uint64) kvm

func TextUint8

func TextUint8(k encoding.TextMarshaler, v uint8) kvm

func TextUint8p

func TextUint8p(k encoding.TextMarshaler, v *uint8) kvm

func TextUintp

func TextUintp(k encoding.TextMarshaler, v *uint) kvm

func TextUintptr

func TextUintptr(k encoding.TextMarshaler, v uintptr) kvm

func TextUintptrp

func TextUintptrp(k encoding.TextMarshaler, v *uintptr) kvm

func Texts

func Texts(s ...encoding.TextMarshaler) textS

Texts returns stringer/JSON/text marshaler for the text marshaler slice type.

func Time

func Time(v time.Time) timeV

Time returns stringer/JSON/text marshaler for the time type.

func Timep

func Timep(p *time.Time) timeP

Timep returns stringer/JSON/text marshaler for the time pointer type.

func Timeps

func Timeps(a ...*time.Time) timePS

Timeps returns stringer/JSON/text marshaler for the time pointer slice type.

func Times

func Times(s ...time.Time) timeS

Times returns stringer/JSON/text marshaler for the slice of byte slice type.

func Uint

func Uint(v uint) uintV

Uint returns stringer/JSON/text marshaler for the uint type.

func Uint16

func Uint16(v uint16) uint16V

Uint16 returns stringer/JSON/text marshaler for the uint16 type.

func Uint16p

func Uint16p(p *uint16) uint16P

Uint16p returns stringer/JSON/text marshaler for the uint16 pointer type.

func Uint16ps

func Uint16ps(a ...*uint16) uint16PS

Uint16ps returns stringer/JSON/text marshaler for the uint16 pointer slice type.

func Uint16s

func Uint16s(s ...uint16) uint16S

Uint16s returns stringer/JSON/text marshaler for the uint16 slice type.

func Uint32

func Uint32(v uint32) uint32V

Uint32 returns stringer/JSON/text marshaler for the uint32 type.

func Uint32p

func Uint32p(p *uint32) uint32P

Uint32p returns stringer/JSON/text marshaler for the uint32 pointer type.

func Uint32ps

func Uint32ps(a ...*uint32) uint32PS

Uint32ps returns stringer/JSON/text marshaler for the uint32 pointer slice type.

func Uint32s

func Uint32s(s ...uint32) uint32S

Uint32s returns stringer/JSON/text marshaler for the uint32 slice type.

func Uint64

func Uint64(v uint64) uint64V

Uint64 returns stringer/JSON/text marshaler for the uint64 type.

func Uint64p

func Uint64p(p *uint64) uint64P

Uint64p returns stringer/JSON/text marshaler for the uint64 pointer type.

func Uint64ps

func Uint64ps(a ...*uint64) uint64PS

Uint64ps returns stringer/JSON/text marshaler for the uint64 pointer slice type.

func Uint64s

func Uint64s(s ...uint64) uint64S

Uint64s returns stringer/JSON/text marshaler for the uint64 slice type.

func Uint8

func Uint8(v uint8) uint8V

Uint8 returns stringer/JSON/text marshaler for the uint8 type.

func Uint8p

func Uint8p(p *uint8) uint8P

Uint8p returns stringer/JSON/text marshaler for the uint8 pointer type.

func Uint8ps

func Uint8ps(a ...*uint8) uint8PS

Uint8ps returns stringer/JSON/text marshaler for the uint8 pointer slice type.

func Uint8s

func Uint8s(s ...uint8) uint8S

Uint8s returns stringer/JSON/text marshaler for the uint8 slice type.

func Uintp

func Uintp(p *uint) uintP

Uintp returns stringer/JSON/text marshaler for the uint pointer type.

func Uintps

func Uintps(a ...*uint) uintPS

Uintps returns stringer/JSON/text marshaler for the uint pointer slice type.

func Uintptr

func Uintptr(v uintptr) uintptrV

Uintptr returns stringer/JSON/text marshaler for the uintptr type.

func Uintptrp

func Uintptrp(p *uintptr) uintptrP

Uintptrp returns stringer/JSON/text marshaler for the uintptr pointer type.

func Uintptrps

func Uintptrps(a ...*uintptr) uintptrPS

Uintptrps returns stringer/JSON/text marshaler for the slice of a pointer to a uintptr type.

func Uintptrs

func Uintptrs(s ...uintptr) uintptrS

Uintptrs returns stringer/JSON/text marshaler for the uintptr slice type.

func Uints

func Uints(s ...uint) uintS

Uints returns stringer/JSON/text marshaler for the uint slice type.

Types

type Encoder

type Encoder interface {
	Encode(...KV) []byte
}

type KV

type KV interface {
	encoding.TextMarshaler
	json.Marshaler
}

KV is a key-value pair.

type KeyValuer

type KeyValuer interface {
	KeyValues() []KV
}

KeyValuer provides key-values slice.

type Leveler

type Leveler interface {
	Level() string
}

Leveler provides severity level.

type Log

type Log struct {
	Output  io.Writer                             // Output is a destination for output.
	Flag    int                                   // Flag is a log properties.
	KV      []KV                                  // KV is a key-values.
	Level   func(level string) (output io.Writer) // Level function receives severity level and returns a output writer for a severity level.
	Keys    [4]encoding.TextMarshaler             // Keys: 0 = original message; 1 = message excerpt; 2 = message trail; 3 = file path.
	Key     uint8                                 // Key is a default/sticky message key: all except 1 = original message; 1 = message excerpt.
	Trunc   int                                   // Trunc is a maximum length of an excerpt, after which it is truncated.
	Marks   [3][]byte                             // Marks: 0 = truncate; 1 = empty; 2 = blank.
	Replace [][2][]byte                           // Replace ia a pairs of byte slices to replace in the message excerpt.
}

Log is a JSON logger/writer.

func GELF

func GELF() *Log

GELF returns a GELF formater <https://docs.graylog.org/en/latest/pages/gelf.html>.

func (*Log) Close added in v0.173.0

func (l *Log) Close() error

Close puts a log into sync pool.

func (*Log) Encode

func (l *Log) Encode(kv ...KV) []byte

func (*Log) KeyValues

func (l *Log) KeyValues() []KV

func (*Log) Tee added in v0.173.0

func (l *Log) Tee(kv ...KV) Logger

Tee returns copy of the logger with additional key-values. If first key-value pair implements the Leveler interface and the Level field of the Log is not null then calls the function from Level field with the severity level as argument which obtained from Leveler interface. Then the function from Level field returns writer for output of the logger. Copy of the original key-values has the priority lower than the priority of the newer key-values.

func (Log) Truncate

func (l Log) Truncate(dst, src []byte) (int, error)

Truncate writes excerpt of the src to the dst and returns number of the written bytes and error if occurre.

func (*Log) Write

func (l *Log) Write(src []byte) (int, error)

Write implements io.Writer. Do nothing if log does not have output.

type Logger

type Logger interface {
	io.Writer
	// Tee returns copy of the logger with an additional key-values.
	// Copy of the original key-values should have a lower priority
	// than the priority of the newer key-values.
	Tee(...KV) Logger
	// Close puts the logger into the sync pool.
	Close() error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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