Documentation ¶
Index ¶
- Constants
- Variables
- type FormatterFactory
- type IFormatter
- type IFormatterFactory
- type IFormatterStrategy
- type ILoader
- type ILogger
- type IStream
- type IStreamFactory
- type IStreamStrategy
- type Level
- type Loader
- type Logger
- func (l *Logger) AddStream(id string, stream IStream) error
- func (l Logger) Broadcast(level Level, msg string, ctx map[string]interface{}) error
- func (l *Logger) Close() error
- func (l Logger) HasStream(id string) bool
- func (l Logger) ListStreams() []string
- func (l *Logger) RemoveAllStreams()
- func (l *Logger) RemoveStream(id string)
- func (l Logger) Signal(channel string, level Level, msg string, ctx map[string]interface{}) error
- func (l Logger) Stream(id string) IStream
- type Provider
- type StreamFactory
Constants ¶
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" )
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" )
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" )
const ( // EnvID defines the slate.slog package base environment variable name. EnvID = slate.EnvID + "_SLOG" )
Variables ¶
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") )
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.
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.
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.
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.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger defines a logging proxy for all the registered logging streams.
func (Logger) Broadcast ¶
Broadcast will propagate the logging request to all stored logging streams.
func (Logger) ListStreams ¶
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 ¶
RemoveStream will remove a registered stream with the requested id from the logger.
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.
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.
Source Files ¶
- errors.go
- formatter.go
- formatter_factory.go
- formatter_json.go
- formatter_strategy.go
- formatter_strategy_json.go
- globals.go
- level.go
- loader.go
- logger.go
- provider.go
- stream.go
- stream_console.go
- stream_factory.go
- stream_file.go
- stream_rotating_file_writer.go
- stream_strategy.go
- stream_strategy_console.go
- stream_strategy_file.go
- stream_strategy_rotating_file.go