logging

package
v0.8.9 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2022 License: Apache-2.0 Imports: 16 Imported by: 487

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewService

func NewService() (service.Service, error)

NewService returns a new device Service

func SetLevel

func SetLevel(level Level)

SetLevel sets the root logger level

Types

type Config

type Config struct {
	Loggers map[string]LoggerConfig `yaml:"loggers"`
	Sinks   map[string]SinkConfig   `yaml:"sinks"`
}

Config logging configuration

func (Config) GetLogger added in v0.6.12

func (c Config) GetLogger(name string) (LoggerConfig, bool)

GetLogger returns a logger by name

func (Config) GetLoggers added in v0.6.12

func (c Config) GetLoggers() []LoggerConfig

GetLoggers returns the configured loggers

func (Config) GetRootLogger added in v0.6.12

func (c Config) GetRootLogger() LoggerConfig

GetRootLogger returns the root logger configuration

func (Config) GetSink added in v0.6.12

func (c Config) GetSink(name string) (SinkConfig, bool)

GetSink returns a sink by name

func (Config) GetSinks added in v0.6.12

func (c Config) GetSinks() []SinkConfig

GetSinks returns the configured sinks

type FileSinkConfig added in v0.6.12

type FileSinkConfig struct {
	Path string `yaml:"path"`
}

FileSinkConfig is the configuration for a file sink

type KafkaSinkConfig added in v0.6.12

type KafkaSinkConfig struct {
	Topic   string   `yaml:"topic"`
	Key     string   `yaml:"key"`
	Brokers []string `yaml:"brokers"`
}

KafkaSinkConfig is the configuration for a Kafka sink

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 = InfoLevel
)

func (Level) String

func (l Level) String() string

String :

type Logger

type Logger interface {
	Output

	// Name returns the logger name
	Name() string

	// GetLogger gets a descendant of this Logger
	GetLogger(names ...string) Logger

	// GetLevel returns the logger's level
	GetLevel() Level

	// SetLevel sets the logger's level
	SetLevel(level Level)
}

Logger represents an abstract logging interface.

func GetLogger

func GetLogger(names ...string) Logger

GetLogger gets a logger by name

type LoggerConfig

type LoggerConfig struct {
	Name   string                  `yaml:"name"`
	Level  *string                 `yaml:"level,omitempty"`
	Output map[string]OutputConfig `yaml:"output"`
}

LoggerConfig is the configuration for a logger

func (LoggerConfig) GetLevel added in v0.6.12

func (c LoggerConfig) GetLevel() Level

GetLevel returns the logger level

func (LoggerConfig) GetOutput added in v0.6.12

func (c LoggerConfig) GetOutput(name string) (OutputConfig, bool)

GetOutput returns an output by name

func (LoggerConfig) GetOutputs added in v0.6.12

func (c LoggerConfig) GetOutputs() []OutputConfig

GetOutputs returns the logger outputs

type Output added in v0.6.12

type Output 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{})
}

Output is a logging output

type OutputConfig added in v0.6.12

type OutputConfig struct {
	Name  string  `yaml:"name"`
	Sink  *string `yaml:"sink"`
	Level *string `yaml:"level,omitempty"`
}

OutputConfig is the configuration for a sink output

func (OutputConfig) GetLevel added in v0.6.12

func (c OutputConfig) GetLevel() Level

GetLevel returns the output level

func (OutputConfig) GetSink added in v0.6.12

func (c OutputConfig) GetSink() string

GetSink returns the output sink

type Server

type Server struct {
}

Server implements the logging gRPC service

func (*Server) GetLevel added in v0.6.14

GetLevel implements GetLevel rpc function to get a logger level

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 SinkConfig added in v0.6.12

type SinkConfig struct {
	Name     string            `yaml:"name"`
	Type     *SinkType         `yaml:"type,omitempty"`
	Encoding *SinkEncoding     `yaml:"encoding,omitempty"`
	Stdout   *StdoutSinkConfig `yaml:"stdout,omitempty"`
	Stderr   *StderrSinkConfig `yaml:"stderr,omitempty"`
	File     *FileSinkConfig   `yaml:"file,omitempty"`
	Kafka    *KafkaSinkConfig  `yaml:"kafka,omitempty"`
}

SinkConfig is the configuration for a sink

func (SinkConfig) GetEncoding added in v0.6.12

func (c SinkConfig) GetEncoding() SinkEncoding

GetEncoding returns the sink encoding

func (SinkConfig) GetFileSinkConfig added in v0.6.12

func (c SinkConfig) GetFileSinkConfig() FileSinkConfig

GetFileSinkConfig returns the file sink configuration

func (SinkConfig) GetKafkaSinkConfig added in v0.6.12

func (c SinkConfig) GetKafkaSinkConfig() KafkaSinkConfig

GetKafkaSinkConfig returns the Kafka sink configuration

func (SinkConfig) GetStderrSinkConfig added in v0.6.12

func (c SinkConfig) GetStderrSinkConfig() StderrSinkConfig

GetStderrSinkConfig returns the stderr sink configuration

func (SinkConfig) GetStdoutSinkConfig added in v0.6.12

func (c SinkConfig) GetStdoutSinkConfig() StdoutSinkConfig

GetStdoutSinkConfig returns the stdout sink configuration

func (SinkConfig) GetType added in v0.6.12

func (c SinkConfig) GetType() SinkType

GetType returns the sink type

type SinkEncoding added in v0.6.12

type SinkEncoding string

SinkEncoding is the encoding for a sink

const (
	// ConsoleEncoding is an encoding for outputs to the console
	ConsoleEncoding SinkEncoding = "console"
	// JSONEncoding is an encoding for JSON outputs
	JSONEncoding SinkEncoding = "json"
)

func (SinkEncoding) String added in v0.6.12

func (e SinkEncoding) String() string

type SinkType

type SinkType string

SinkType is the type of a sink

const (
	// StdoutSinkType is the sink type for stdout
	StdoutSinkType SinkType = "stdout"
	// StderrSinkType is the sink type for stderr
	StderrSinkType SinkType = "stderr"
	// FileSinkType is the type for a file sink
	FileSinkType SinkType = "file"
	// KafkaSinkType is the sink type for the Kafka sink
	KafkaSinkType SinkType = "kafka"
)

func (SinkType) String

func (t SinkType) String() string

type StderrSinkConfig added in v0.6.12

type StderrSinkConfig struct {
}

StderrSinkConfig is the configuration for an stderr sink

type StdoutSinkConfig added in v0.6.12

type StdoutSinkConfig struct {
}

StdoutSinkConfig is the configuration for an stdout sink

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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