logging

package
v0.6.11 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2020 License: Apache-2.0 Imports: 16 Imported by: 487

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Sinks :
	Sinks = map[string]Sink{}
)

Functions

func AddConfiguredLoggers

func AddConfiguredLoggers(config Config)

AddConfiguredLoggers adds configured loggers

func Configure

func Configure(config Config)

Configure configures logging with the given configuration

func GetKey

func GetKey(name string) art.Key

GetKey returns a key object of radix tree

func GetLoggers

func GetLoggers() art.Tree

GetLoggers get loggers radix tree

func InitSink

func InitSink(u *url.URL) (zap.Sink, error)

InitSink initialize a kafka sink instance

func Load added in v0.6.1

func Load(config interface{}) error

Load loads the configuration

func NewService

func NewService() (service.Service, error)

NewService returns a new device Service

func SetLevel

func SetLevel(level Level, names ...string)

SetLevel change level of a logger and propagates the change to its children

Types

type Config

type Config struct {
	Loggers map[string]struct {
		Encoding string `yaml:"encoding"`
		Level    string `yaml:"level"`
		Sink     string `yaml:"sink"`
	} `yaml:"loggers"`
	Sinks map[string]struct {
		Key   string `yaml:"key"`
		Type  string `yaml:"type"`
		Topic string `yaml:"topic"`
		URI   string `yaml:"uri"`
	} `yaml:"sinks"`
}

Config logging configuration

type Debug

type Debug bool

Debug :

func (Debug) Println

func (d Debug) Println(s string, args ...interface{})

Println :

type Errors

type Errors []error

Errors concatenates multiple error into one error buf

func (Errors) Error

func (e Errors) Error() string

type Level

type Level int

Level :

const (
	// DebugLevel logs a message at debug level
	DebugLevel Level = iota
	// InfoLevel logs a message at info level
	InfoLevel
	// WarnLevel logs a message at warning level
	WarnLevel
	// ErrorLevel logs a message at error level
	ErrorLevel
	// FatalLevel logs a message, then calls os.Exit(1).
	FatalLevel
	// PanicLevel logs a message, then panics.
	PanicLevel
	// DPanicLevel logs at PanicLevel; otherwise, it logs at ErrorLevel
	DPanicLevel

	// EmptyLevel :
	EmptyLevel
)

func StringToInt

func StringToInt(l string) Level

StringToInt :

func (Level) String

func (l Level) String() string

String :

type Log

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

Log :

func AddLogger

func AddLogger(level Level, names ...string) *Log

AddLogger adds a logger based on a given level and a hierarchy of names

func FindLogger

func FindLogger(names ...string) (*Log, bool)

FindLogger :

func GetDefaultLogger

func GetDefaultLogger() Log

GetDefaultLogger gets the default logger

func GetLogger

func GetLogger(names ...string) *Log

GetLogger gets a logger based on a give name

func (*Log) DPanic

func (l *Log) DPanic(args ...interface{})

DPanic logs a message at DPanic level on the sugar logger

func (*Log) DPanicf

func (l *Log) DPanicf(template string, args ...interface{})

DPanicf logs a message at DPanicf level on the sugar logger.

func (*Log) DPanicw

func (l *Log) DPanicw(msg string, keysAndValues ...interface{})

DPanicw logs a message at DPanicw level on the sugar logger.

func (*Log) Debug

func (l *Log) Debug(args ...interface{})

Debug logs a message at Debug level on the sugar logger.

func (*Log) Debugf

func (l *Log) Debugf(template string, args ...interface{})

Debugf logs a message at Debugf level on the sugar logger.

func (*Log) Debugw

func (l *Log) Debugw(msg string, keysAndValues ...interface{})

Debugw logs a message at Debugw level on the sugar logger.

func (*Log) Error

func (l *Log) Error(args ...interface{})

Error logs a message at Error level on the sugar logger

func (*Log) Errorf

func (l *Log) Errorf(template string, args ...interface{})

Errorf logs a message at Errorf level on the sugar logger.

func (*Log) Errorw

func (l *Log) Errorw(msg string, keysAndValues ...interface{})

Errorw logs a message at Errorw level on the sugar logger.

func (*Log) Fatal

func (l *Log) Fatal(args ...interface{})

Fatal logs a message at Fatal level on the sugar logger

func (*Log) Fatalf

func (l *Log) Fatalf(template string, args ...interface{})

Fatalf logs a message at Fatalf level on the sugar logger.

func (*Log) Fatalw

func (l *Log) Fatalw(msg string, keysAndValues ...interface{})

Fatalw logs a message at Fatalw level on the sugar logger.

func (*Log) Info

func (l *Log) Info(args ...interface{})

Info logs a message at Info level on the sugar logger

func (*Log) Infof

func (l *Log) Infof(template string, args ...interface{})

Infof logs a message at Infof level on the sugar logger.

func (*Log) Infow

func (l *Log) Infow(msg string, keysAndValues ...interface{})

Infow logs a message at Infow level on the sugar logger.

func (*Log) Panic

func (l *Log) Panic(args ...interface{})

Panic logs a message at Panic level on the sugar logger

func (*Log) Panicf

func (l *Log) Panicf(template string, args ...interface{})

Panicf logs a message at Panicf level on the sugar logger.

func (*Log) Panicw

func (l *Log) Panicw(msg string, keysAndValues ...interface{})

Panicw logs a message at Panicw level on the sugar logger.

func (*Log) SetLevel

func (l *Log) SetLevel(level Level)

SetLevel defines a new logger level and propagate the change its children

func (*Log) Warn

func (l *Log) Warn(args ...interface{})

Warn logs a message at Warn level on the sugar logger

func (*Log) Warnf

func (l *Log) Warnf(template string, args ...interface{})

Warnf logs a message at Warnf level on the sugar logger.

func (*Log) Warnw

func (l *Log) Warnw(msg string, keysAndValues ...interface{})

Warnw logs a message at Warnw level on the sugar logger.

type Logger

type Logger interface {
	Debug(...interface{})
	Debugf(template string, args ...interface{})
	Debugw(msg string, keysAndValues ...interface{})

	Info(...interface{})
	Infof(template string, args ...interface{})
	Infow(msg string, keysAndValues ...interface{})

	Error(...interface{})
	Errorf(template string, args ...interface{})
	Errorw(msg string, keysAndValues ...interface{})

	Fatal(...interface{})
	Fatalf(template string, args ...interface{})
	Fatalw(msg string, keysAndValues ...interface{})

	Panic(...interface{})
	Panicf(template string, args ...interface{})
	Panicw(msg string, keysAndValues ...interface{})

	DPanic(...interface{})
	DPanicf(template string, args ...interface{})
	DPanicw(msg string, keysAndValues ...interface{})

	Warn(...interface{})
	Warnf(template string, args ...interface{})
	Warnw(msg string, keysAndValues ...interface{})

	SetLevel(level Level)
}

Logger represents an abstract logging interface.

type LoggerBuilder

type LoggerBuilder interface {
	SetLevel(Level) LoggerBuilder
	SetEncoding(string) LoggerBuilder
	SetDevelopment(bool) LoggerBuilder
	SetOutputPaths([]string) LoggerBuilder
	SetErrorOutputPaths([]string) LoggerBuilder
	SetSinkURLs([]SinkURL) LoggerBuilder
	//SetInitialFields(Fields) LoggerBuilder
	SetECLevelKey(string) LoggerBuilder
	SetECMsgKey(string) LoggerBuilder
	SetECTimeKey(string) LoggerBuilder
	SetECStackTraceKey(string) LoggerBuilder
	SetECLineEnding(string) LoggerBuilder
	SetECEncodeLevel(zc.LevelEncoder) LoggerBuilder
	SetECTimeEncoder(zc.TimeEncoder) LoggerBuilder
	SetName(...string) LoggerBuilder
	SetECEncodeDuration(zc.DurationEncoder) LoggerBuilder
	SetECEncoderCaller(string, zc.CallerEncoder) LoggerBuilder
	Build() LoggerConfig
}

LoggerBuilder log configuration builder interface

type LoggerConfig

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

LoggerConfig log config structure

func (*LoggerConfig) Build

func (c *LoggerConfig) Build() LoggerConfig

Build builds a custom log configuration

func (*LoggerConfig) GetLogger

func (c *LoggerConfig) GetLogger() *Log

GetLogger :

func (*LoggerConfig) GetSinkURLs

func (c *LoggerConfig) GetSinkURLs() []SinkURL

GetSinkURLs gets sink urls

func (*LoggerConfig) GetZapConfig

func (c *LoggerConfig) GetZapConfig() zp.Config

GetZapConfig gets zap configuration

func (*LoggerConfig) SetDevelopment

func (c *LoggerConfig) SetDevelopment(development bool) LoggerBuilder

SetDevelopment sets log development

func (*LoggerConfig) SetECEncodeDuration

func (c *LoggerConfig) SetECEncodeDuration(encodeDuration zc.DurationEncoder) LoggerBuilder

SetECEncodeDuration sets log encoder config encode duration

func (*LoggerConfig) SetECEncodeLevel

func (c *LoggerConfig) SetECEncodeLevel(encodeLevel zc.LevelEncoder) LoggerBuilder

SetECEncodeLevel sets log encoder config encode level

func (*LoggerConfig) SetECEncoderCaller

func (c *LoggerConfig) SetECEncoderCaller(callerKey string, encoderCaller zc.CallerEncoder) LoggerBuilder

SetECEncoderCaller sets log encoder config encoder caller

func (*LoggerConfig) SetECLevelKey

func (c *LoggerConfig) SetECLevelKey(levelKey string) LoggerBuilder

SetECLevelKey sets log encoder config level key

func (*LoggerConfig) SetECLineEnding

func (c *LoggerConfig) SetECLineEnding(lineEnding string) LoggerBuilder

SetECLineEnding sets log encoder config line ending

func (*LoggerConfig) SetECMsgKey

func (c *LoggerConfig) SetECMsgKey(msgKey string) LoggerBuilder

SetECMsgKey sets log encoder config message key

func (*LoggerConfig) SetECStackTraceKey

func (c *LoggerConfig) SetECStackTraceKey(stackTraceKey string) LoggerBuilder

SetECStackTraceKey sets log encoder config start trace key

func (*LoggerConfig) SetECTimeEncoder

func (c *LoggerConfig) SetECTimeEncoder(timeEncoder zc.TimeEncoder) LoggerBuilder

SetECTimeEncoder sets log encoder config time encoder

func (*LoggerConfig) SetECTimeKey

func (c *LoggerConfig) SetECTimeKey(timeKey string) LoggerBuilder

SetECTimeKey sets log encoder config time key

func (*LoggerConfig) SetEncoding

func (c *LoggerConfig) SetEncoding(encoding string) LoggerBuilder

SetEncoding sets log encoding

func (*LoggerConfig) SetErrorOutputPaths

func (c *LoggerConfig) SetErrorOutputPaths(errorOutputPaths []string) LoggerBuilder

SetErrorOutputPaths sets log error output paths

func (*LoggerConfig) SetLevel

func (c *LoggerConfig) SetLevel(level Level) LoggerBuilder

SetLevel sets log level

func (*LoggerConfig) SetName

func (c *LoggerConfig) SetName(names ...string) LoggerBuilder

SetName sets encoder config name key

func (*LoggerConfig) SetOutputPaths

func (c *LoggerConfig) SetOutputPaths(outputPaths []string) LoggerBuilder

SetOutputPaths sets log output paths

func (*LoggerConfig) SetSinkURLs

func (c *LoggerConfig) SetSinkURLs(sinkURLs []SinkURL) LoggerBuilder

SetSinkURLs sets sink urls

type Server

type Server struct {
}

Server implements the logging gRPC service

func (*Server) SetDebug

SetDebug enable/disable debug mode for logging package

func (*Server) SetLevel

SetLevel implements SetLevel rpc function to set a logger level

type Service

type Service struct {
	service.Service
}

Service is an implementation of C1 service.

func (Service) Register

func (s Service) Register(r *grpc.Server)

Register registers the logging Service with the gRPC server.

type Sink

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

Sink a kafka sink

func (Sink) Close

func (s Sink) Close() error

Close implements zap.Sink Close function

func (Sink) Sync

func (s Sink) Sync() error

Sync implement zap.Sink func Sync

func (Sink) Write

func (s Sink) Write(b []byte) (n int, err error)

Write implements zap.Sink Write function

type SinkInfo

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

SinkInfo sink information

func ContainSink

func ContainSink(sinks []SinkInfo, sinkName string) (SinkInfo, bool)

ContainSink checks a sink is in the list of sinks

func GetSinks

func GetSinks(config Config) []SinkInfo

GetSinks get sinks info from the configuration

type SinkType

type SinkType int

SinkType :

const (
	// Kafka kafka sink type
	Kafka SinkType = iota

	// Stdout sink type
	Stdout
)

func (SinkType) String

func (s SinkType) String() string

String :

type SinkURL

type SinkURL struct {
	url.URL
}

SinkURL sink url

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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