glog

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 3, 2022 License: MIT Imports: 11 Imported by: 2

README

glog

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"
)

Variables

View Source
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")
)
View Source
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")
)
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

func NewStreamRotatingFileWriter

func NewStreamRotatingFileWriter(fs afero.Fs, file string) (io.Writer, error)

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

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

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.

func (FormatterJSON) Format

func (f FormatterJSON) Format(level Level, message string, ctx map[string]interface{}) string

Format will create the output JSON string message formatted with the content of the passed level, message and context

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.

func NewLoader

func NewLoader(config gconfig.Manager, logger *Logger, factory *StreamFactory) (*Loader, error)

NewLoader create a new logging configuration loader instance.

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 NewLogger

func NewLogger() *Logger

NewLogger create a new logger instance.

func (*Logger) AddStream

func (l *Logger) AddStream(id string, stream Stream) 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) Stream

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

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

func NewStreamConsole(formatter Formatter, channels []string, level Level) (Stream, error)

NewStreamConsole instantiate a new console stream object that will write logging content into the standard output.

func NewStreamFile

func NewStreamFile(writer io.Writer, formatter Formatter, channels []string, level Level) (Stream, error)

NewStreamFile instantiate a new file stream object that will write logging content into a file.

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.

Jump to

Keyboard shortcuts

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