slog

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FormatUnknown defines the value to be used to declare an unknown
	// logger formatter format.
	FormatUnknown = "unknown"

	// FormatJSON defines the value to be used to declare a JSON
	// logger formatter format.
	FormatJSON = "json"
)
View Source
const (
	// StreamUnknown defines the value to be used to declare an unknown
	// logger stream type.
	StreamUnknown = "unknown"

	// StreamConsole defines the value to be used to declare a console
	// logger stream type.
	StreamConsole = "console"

	// StreamFile defines the value to be used to declare a file
	// logger stream type.
	StreamFile = "file"

	// StreamRotatingFile defines the value to be used to declare a file
	// logger stream type that rotates regarding the current date.
	StreamRotatingFile = "rotating-file"
)
View Source
const (
	// ContainerID defines the id to be used as the container
	// registration id of a logger instance, as a base id of all other log
	// package instances registered in the application container.
	ContainerID = slate.ContainerID + ".log"

	// ContainerFormatterStrategyTag defines the tag to be assigned to all
	// container formatter strategies.
	ContainerFormatterStrategyTag = ContainerID + ".formatter.strategy"

	// ContainerFormatterStrategyJSONID defines the id to be used as
	// the container registration id of a logger json formatter factory
	// strategy instance.
	ContainerFormatterStrategyJSONID = ContainerID + ".formatter.strategy.json"

	// ContainerFormatterFactoryID defines the id to be used as the
	// container registration id of a logger formatter factory instance.
	ContainerFormatterFactoryID = ContainerID + ".formatter.factory"

	// ContainerStreamStrategyTag defines the tag to be assigned to all
	// container stream strategies.
	ContainerStreamStrategyTag = ContainerID + ".stream.strategy"

	// ContainerStreamStrategyConsoleID defines the id to be used as the
	// container registration id of a logger console stream factory strategy
	// instance.
	ContainerStreamStrategyConsoleID = ContainerID + ".stream.strategy.console"

	// ContainerStreamStrategyFileID defines the id to be used as the
	// container registration id of a logger file stream factory strategy
	// instance.
	ContainerStreamStrategyFileID = ContainerID + ".stream.strategy.file"

	// ContainerStreamStrategRotatingFileID defines the id to be used as the
	// container registration id of a logger rotating file stream factory
	// strategy instance.
	ContainerStreamStrategRotatingFileID = ContainerID + ".stream.strategy.rotating_file"

	// ContainerStreamFactoryID defines the id to be used as the container
	// registration id of a logger stream factory instance.
	ContainerStreamFactoryID = ContainerID + ".stream.factory"

	// ContainerLoaderID defines the id to be used as the container
	// registration id of a logger loader instance.
	ContainerLoaderID = ContainerID + ".loader"
)
View Source
const (
	// EnvID defines the slate.slog package base environment variable name.
	EnvID = slate.EnvID + "_SLOG"
)

Variables

View Source
var (
	// LoaderActive defines the entry config source active flag
	// used to signal the config loader to load the streams or not
	LoaderActive = senv.Bool(EnvID+"_LOADER_ACTIVE", true)

	// LoaderConfigPath defines the entry config source path
	// to be used as the loader entry.
	LoaderConfigPath = senv.String(EnvID+"_LOADER_CONFIG_PATH", "log.streams")

	// LoaderObserveConfig defines the loader config observing flag
	// used to register in the config object an observer of the log
	// config entries list, so it can reload the logger streams.
	LoaderObserveConfig = senv.Bool(EnvID+"_LOADER_OBSERVE_CONFIG", true)

	// LoaderErrorChannel defines the loader error logging channel.
	LoaderErrorChannel = senv.String(EnvID+"_LOADER_ERROR_CHANNEL", "exec")
)
View Source
var LevelMap = map[string]Level{
	"fatal":   FATAL,
	"error":   ERROR,
	"warning": WARNING,
	"notice":  NOTICE,
	"info":    INFO,
	"debug":   DEBUG,
}

LevelMap defines a relation between a human-readable string and a code level identifier of a logging level.

View Source
var LevelMapName = map[Level]string{
	FATAL:   "fatal",
	ERROR:   "error",
	WARNING: "warning",
	NOTICE:  "notice",
	INFO:    "info",
	DEBUG:   "debug",
}

LevelMapName defines a relation between a code level identifier of a logging level and human-readable string representation of that level.

Functions

This section is empty.

Types

type FormatterFactory

type FormatterFactory []IFormatterStrategy

FormatterFactory defines the logger formatter factory structure used to instantiate logger formatters, based on registered instantiation strategies.

func (FormatterFactory) Create

func (f FormatterFactory) Create(format string, args ...interface{}) (IFormatter, error)

Create will instantiate and return a new content formatter.

func (*FormatterFactory) Register

func (f *FormatterFactory) Register(strategy IFormatterStrategy) error

Register will register a new formatter factory strategy to be used on requesting to create a formatter for a defined format.

type IFormatter added in v0.9.0

type IFormatter interface {
	Format(level Level, message string, ctx map[string]interface{}) string
}

IFormatter interface defines the methods of a logging formatter instance responsible to parse a logging request into the output string.

type IFormatterFactory added in v0.9.0

type IFormatterFactory interface {
	Register(strategy IFormatterStrategy) error
	Create(format string, args ...interface{}) (IFormatter, error)
}

IFormatterFactory defined the interface of a log formatter factory instance.

func GetFormatterFactory

func GetFormatterFactory(c slate.ServiceContainer) (IFormatterFactory, error)

GetFormatterFactory will try to retrieve the registered formatter factory instance from the application service container.

type IFormatterStrategy added in v0.9.0

type IFormatterStrategy interface {
	Accept(format string) bool
	Create(args ...interface{}) (IFormatter, error)
}

IFormatterStrategy interface defines the methods of the formatter factory strategy that can validate creation requests and instantiation of particular decoder.

func GetFormatterStrategies

func GetFormatterStrategies(c slate.ServiceContainer) ([]IFormatterStrategy, error)

GetFormatterStrategies will try to retrieve the registered the list of formatter strategies instances from the application service container.

type ILoader added in v0.9.0

type ILoader interface {
	Load() error
}

ILoader defines the interface of a log loader instance.

func GetLoader

func GetLoader(c slate.ServiceContainer) (ILoader, error)

GetLoader will try to retrieve the registered loader instance from the application service container.

type ILogger added in v0.9.0

type ILogger interface {
	io.Closer

	Signal(channel string, level Level, msg string, ctx map[string]interface{}) error
	Broadcast(level Level, msg string, ctx map[string]interface{}) error
	HasStream(id string) bool
	ListStreams() []string
	AddStream(id string, stream IStream) error
	RemoveStream(id string)
	RemoveAllStreams()
	Stream(id string) IStream
}

ILogger defines the interface of a logger instance.

func GetLogger

func GetLogger(c slate.ServiceContainer) (ILogger, error)

GetLogger will try to retrieve the registered logger manager instance from the application service container.

type IStream added in v0.9.0

type IStream interface {
	Level() Level

	Signal(channel string, level Level, message string, ctx map[string]interface{}) error
	Broadcast(level Level, message string, ctx map[string]interface{}) error

	HasChannel(channel string) bool
	ListChannels() []string
	AddChannel(channel string)
	RemoveChannel(channel string)
}

IStream interface defines the interaction methods with a logging stream.

type IStreamFactory added in v0.9.0

type IStreamFactory interface {
	Register(strategy IStreamStrategy) error
	Create(streamType string, args ...interface{}) (IStream, error)
	CreateFromConfig(cfg sconfig.IConfig) (IStream, error)
}

IStreamFactory defined the interface of a log stream factory instance.

func GetStreamFactory

func GetStreamFactory(c slate.ServiceContainer) (IStreamFactory, error)

GetStreamFactory will try to retrieve the registered stream factory instance from the application service container.

type IStreamStrategy added in v0.9.0

type IStreamStrategy interface {
	Accept(sourceType string) bool
	AcceptFromConfig(cfg sconfig.IConfig) bool
	Create(args ...interface{}) (IStream, error)
	CreateFromConfig(cfg sconfig.IConfig) (IStream, error)
}

IStreamStrategy interface defines the methods of the stream factory strategy that can validate creation requests and instantiation of particular type of stream.

func GetStreamStrategies

func GetStreamStrategies(c slate.ServiceContainer) ([]IStreamStrategy, error)

GetStreamStrategies will try to retrieve the registered the list of stream strategies instances from the application service container.

type Level

type Level int

Level identifies a value type that describes a logging level.

const (
	// FATAL defines a fatal logging level.
	FATAL Level = 1 + iota
	// ERROR defines a error logging level.
	ERROR
	// WARNING defines a warning logging level.
	WARNING
	// NOTICE defines a notice logging level.
	NOTICE
	// INFO defines a info logging level.
	INFO
	// DEBUG defines a debug logging level.
	DEBUG
)

type Loader

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

Loader defines the logger instantiation and initialization of a new logger proxy.

func (Loader) Load

func (l Loader) Load() error

Load will parse the configuration and instantiates logging streams depending the data on the configuration.

type Logger

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

Logger defines a logging proxy for all the registered logging streams.

func (*Logger) AddStream

func (l *Logger) AddStream(id string, stream IStream) error

AddStream registers a new stream into the logger instance.

func (Logger) Broadcast

func (l Logger) Broadcast(level Level, msg string, ctx map[string]interface{}) error

Broadcast will propagate the logging request to all stored logging streams.

func (*Logger) Close

func (l *Logger) Close() error

Close will terminate all the logging stream associated to the logger.

func (Logger) HasStream

func (l Logger) HasStream(id string) bool

HasStream check if a stream is registered with the requested id.

func (Logger) ListStreams

func (l Logger) ListStreams() []string

ListStreams retrieve a list of id's of all registered streams on the logger.

func (*Logger) RemoveAllStreams

func (l *Logger) RemoveAllStreams()

RemoveAllStreams will remove all registered streams from the logger.

func (*Logger) RemoveStream

func (l *Logger) RemoveStream(id string)

RemoveStream will remove a registered stream with the requested id from the logger.

func (Logger) Signal

func (l Logger) Signal(channel string, level Level, msg string, ctx map[string]interface{}) error

Signal will propagate the channel filtered logging request to all stored logging streams.

func (Logger) Stream

func (l Logger) Stream(id string) IStream

Stream retrieve a stream from the logger that is registered with the requested id.

type Provider

type Provider struct{}

Provider defines the slate.log module service provider to be used on the application initialization to register the logging service.

func (Provider) Boot

Boot will start the logger package config instance by calling the logger loader with the defined provider base entry information.

func (Provider) Register

func (p Provider) Register(c slate.ServiceContainer) error

Register will register the logger package instances in the application container.

type StreamFactory

type StreamFactory []IStreamStrategy

StreamFactory is a logging stream generator based on a registered list of stream generation strategies.

func (StreamFactory) Create

func (f StreamFactory) Create(streamType string, args ...interface{}) (IStream, error)

Create will instantiate and return a new config stream.

func (StreamFactory) CreateFromConfig

func (f StreamFactory) CreateFromConfig(cfg sconfig.IConfig) (IStream, error)

CreateFromConfig will instantiate and return a new config stream loaded by a configuration instance.

func (*StreamFactory) Register

func (f *StreamFactory) Register(strategy IStreamStrategy) error

Register will register a new stream factory strategy to be used on creation requests.

Jump to

Keyboard shortcuts

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