Documentation ¶
Index ¶
- Constants
- Variables
- func NewStreamRotatingFileWriter(fs afero.Fs, file string) (io.Writer, error)
- type Formatter
- type FormatterFactory
- type FormatterJSON
- type FormatterStrategy
- type FormatterStrategyJSON
- type Level
- type Loader
- type Logger
- func (l *Logger) AddStream(id string, stream Stream) 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) Stream
- type Stream
- type StreamFactory
- type StreamStrategy
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" )
Variables ¶
var ( // ErrNilPointer defines a nil pointer argument error ErrNilPointer = fmt.Errorf("invalid nil pointer") // ErrConversion defines a type conversion error ErrConversion = fmt.Errorf("invalid type conversion") // ErrInvalidFormat @todo doc ErrInvalidFormat = fmt.Errorf("invalid output format") // ErrInvalidLevel @todo doc ErrInvalidLevel = fmt.Errorf("invalid logger level") // ErrDuplicateStream @todo doc ErrDuplicateStream = fmt.Errorf("stream already registered") // ErrInvalidStreamType @todo doc ErrInvalidStreamType = fmt.Errorf("invalid stream type") // ErrInvalidStreamConfig @todo doc ErrInvalidStreamConfig = fmt.Errorf("invalid log stream config") )
var ( // LoaderConfigPath defines the entry config source path // to be used as the loader entry. LoaderConfigPath = genv.String("GLOG_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 = genv.Bool("GLOG_LOADER_OBSERVE_CONFIG", true) // LoaderErrorChannel defines the loader error logging channel. LoaderErrorChannel = genv.String("GLOG_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 ¶
func NewStreamRotatingFileWriter ¶
NewStreamRotatingFileWriter instantiates an io.Writer implementing structure that output to a file taking into account the file timestamp, so it can perform the rotation to a new file on day change.
Types ¶
type Formatter ¶
Formatter interface defines the methods of a logging formatter instance responsible to parse a logging request into the output string.
type FormatterFactory ¶
type FormatterFactory []FormatterStrategy
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{}) (Formatter, error)
Create will instantiate and return a new content formatter.
func (*FormatterFactory) Register ¶
func (f *FormatterFactory) Register(strategy FormatterStrategy) error
Register will register a new formatter factory strategy to be used on requesting to create a formatter for a defined format.
type FormatterJSON ¶
type FormatterJSON struct{}
FormatterJSON defines a JSON based logger formatter.
type FormatterStrategy ¶
type FormatterStrategy interface { Accept(format string) bool Create(args ...interface{}) (Formatter, error) }
FormatterStrategy interface defines the methods of the formatter factory strategy that can validate creation requests and instantiation of particular decoder.
type FormatterStrategyJSON ¶
type FormatterStrategyJSON struct{}
FormatterStrategyJSON defines the logger formatter instantiation strategy to be registered in the factory so a Json based logger formatter could be instantiated.
func (FormatterStrategyJSON) Accept ¶
func (FormatterStrategyJSON) Accept(format string) bool
Accept will check if the formatter factory strategy can instantiate a formatter of the requested format.
func (FormatterStrategyJSON) Create ¶
func (FormatterStrategyJSON) Create(_ ...interface{}) (Formatter, error)
Create will instantiate the desired formatter instance.
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 Stream ¶
type Stream 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) }
Stream interface defines the interaction methods with a logging stream.
func NewStreamConsole ¶
NewStreamConsole instantiate a new console stream object that will write logging content into the standard output.
type StreamFactory ¶
type StreamFactory []StreamStrategy
StreamFactory @todo doc
func (StreamFactory) Create ¶
func (f StreamFactory) Create(streamType string, args ...interface{}) (Stream, error)
Create will instantiate and return a new config stream.
func (StreamFactory) CreateFromConfig ¶
func (f StreamFactory) CreateFromConfig(cfg gconfig.Config) (Stream, error)
CreateFromConfig will instantiate and return a new config stream loaded by a configuration instance.
func (*StreamFactory) Register ¶
func (f *StreamFactory) Register(strategy StreamStrategy) error
Register will register a new stream factory strategy to be used on creation requests.
type StreamStrategy ¶
type StreamStrategy interface { Accept(sourceType string) bool AcceptFromConfig(cfg gconfig.Config) bool Create(args ...interface{}) (Stream, error) CreateFromConfig(cfg gconfig.Config) (Stream, error) }
StreamStrategy interface defines the methods of the stream factory strategy that can validate creation requests and instantiation of particular type of stream.
func NewStreamStrategyConsole ¶
func NewStreamStrategyConsole(factory *FormatterFactory) (StreamStrategy, error)
NewStreamStrategyConsole instantiate a new console stream factory strategy that will enable the stream factory to instantiate a new console stream.
func NewStreamStrategyFile ¶
func NewStreamStrategyFile(fs afero.Fs, factory *FormatterFactory) (StreamStrategy, error)
NewStreamStrategyFile instantiate a new file stream factory strategy that will enable the stream factory to instantiate a new file stream.
func NewStreamStrategyRotatingFile ¶
func NewStreamStrategyRotatingFile(fs afero.Fs, factory *FormatterFactory) (StreamStrategy, error)
NewStreamStrategyRotatingFile instantiate a new file stream factory strategy that will enable the stream factory to instantiate a new file stream.
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
- 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