logger

package module
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2023 License: MIT Imports: 4 Imported by: 17 modules, 79 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

logger

-- import "github.com/pteich/logger"

Usage

type Logger
type Logger struct {
	zerolog.Logger
}

Logger represents a logger that embeds zerolog

func New
func New(opts ...Option) *Logger

New returns a new logger with specific options (zero to x)

func NewFromZerolog
func NewFromZerolog(logger zerolog.Logger) *Logger

NewFromZerolog returns a new logger from an existing zerolog instance

func (*Logger) Log
func (log *Logger) Log(v ...interface{}) error

Log implements a common log interface

type Option
type Option func(c *config)

Options is an config setting function

func WithLogConsole
func WithLogConsole() Option

WithLogConsole enabled human readable logging to console

func WithLogLevel
func WithLogLevel(logLevel string) Option

WithLogLevel sets a specific loglevel given as string (e.g. debug)

func WithNanoSeconds
func WithNanoSeconds() Option

WithNanoSeconds logs timestamp with nanos if millis are not enough

func WithServiceName
func WithServiceName(serviceName string) Option

WithServiceName sets a service name as log field

Documentation

Index

Constants

View Source
const (
	LogFieldService  = "service"
	LogFieldHostname = "hostname"
)

Variables

View Source
var StdLogger = New()

Functions

This section is empty.

Types

type Logger

type Logger struct {
	zerolog.Logger
}

Logger represents a logger that embeds zerolog

func New

func New(opts ...Option) *Logger

New returns a new logger with specific options (zero to x)

func NewFromZerolog

func NewFromZerolog(logger zerolog.Logger) *Logger

NewFromZerolog returns a new logger from an existing zerolog instance

func (*Logger) Debugf

func (log *Logger) Debugf(template string, args ...interface{})

func (*Logger) Errorf

func (log *Logger) Errorf(template string, args ...interface{})

func (*Logger) Fatalf added in v1.3.1

func (log *Logger) Fatalf(template string, args ...interface{})

func (*Logger) Infof

func (log *Logger) Infof(template string, args ...interface{})

func (*Logger) Log

func (log *Logger) Log(v ...interface{}) error

Log implements a common log interface

func (*Logger) SetLevel added in v1.3.3

func (log *Logger) SetLevel(lvl int)

func (*Logger) Tracef added in v1.3.2

func (log *Logger) Tracef(template string, args ...interface{})

func (*Logger) Warnf

func (log *Logger) Warnf(template string, args ...interface{})

type Option

type Option func(c *config)

Options is an config setting function

func WithCaller

func WithCaller() Option

WithCaller adds a field with the caller (Go file name and line)

func WithColor

func WithColor(color bool) Option

WithColor enables colored output for console logs

func WithHostname

func WithHostname(hostName string) Option

WithHostname sets a host name as log field

func WithLogConsole

func WithLogConsole(logConsole bool) Option

WithLogConsole enables human readable logging to console

func WithLogLevel

func WithLogLevel(logLevel string) Option

WithLogLevel sets a specific loglevel given as string (e.g. debug)

func WithNanoSeconds

func WithNanoSeconds() Option

WithNanoSeconds logs timestamp with nanos if millis are not enough

func WithServiceName

func WithServiceName(serviceName string) Option

WithServiceName sets a service name as log field

Jump to

Keyboard shortcuts

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