log

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// DefaultMaxFileSize for logger rotation file
	DefaultMaxFileSize int64 = 100
)

Variables

View Source
var (

	// FileLoggingConfiguredCorrectly flag set during config check if file logging meets requirements
	FileLoggingConfiguredCorrectly bool

	// GlobalLogConfig holds global configuration options for logger
	GlobalLogConfig = NewConfig()

	// GlobalLogFile hold global configuration options for file logger
	GlobalLogFile = &Rotate{}

	// FilePath system path to store log files in
	FilePath string

	// RWM read/write mutex for logger
	RWM = &sync.RWMutex{}

	// SubLoggers map of global SubLoggers
	SubLoggers = map[string]*SubLogger{}

	// Global SubLoggers
	Global    *SubLogger
	Database  *SubLogger
	Webserver *SubLogger
)
View Source
var (

	// ErrSubLoggerAlreadyRegistered Returned when a sub logger is registered multiple times
	ErrSubLoggerAlreadyRegistered = errors.New("sub logger already registered")
)

Functions

func CloseLogger

func CloseLogger() error

CloseLogger is called on shutdown of application

func Debug

func Debug(sl *SubLogger, data string)

Debug takes a pointer SubLogger struct and string sends to multiWriter

func Debugf

func Debugf(sl *SubLogger, data string, v ...interface{})

Debugf takes a pointer SubLogger struct, string & interface formats and sends to Info()

func Debugln

func Debugln(sl *SubLogger, v ...interface{})

Debugln takes a pointer SubLogger struct, string and interface sends to newLogEvent

func Error

func Error(sl *SubLogger, data ...interface{})

Error takes a pointer SubLogger struct & interface formats and sends to newLogEvent()

func Errorf

func Errorf(sl *SubLogger, data string, v ...interface{})

Errorf takes a pointer SubLogger struct, string & interface formats and sends to Debug()

func Errorln

func Errorln(sl *SubLogger, v ...interface{})

Errorln takes a pointer SubLogger struct, string & interface formats and sends to newLogEvent()

func Fatal

func Fatal(sl *SubLogger, data ...interface{})

Fatal takes a pointer SubLogger struct & interface formats, sends to newLogEvent(), then exits the program

func Fatalf

func Fatalf(sl *SubLogger, data string, v ...interface{})

Fatalf takes a pointer SubLogger struct, string & interface formats and sends to Fatal()

func Info

func Info(sl *SubLogger, data string)

Info takes a pointer SubLogger struct and string sends to newLogEvent

func Infof

func Infof(sl *SubLogger, data string, v ...interface{})

Infof takes a pointer SubLogger struct, string & interface formats and sends to Info()

func Infoln

func Infoln(sl *SubLogger, v ...interface{})

Infoln takes a pointer SubLogger struct and interface sends to newLogEvent

func SetupGlobalLogger

func SetupGlobalLogger() error

SetupGlobalLogger set up the global loggers with the default global config values

func SetupSubLoggers

func SetupSubLoggers(s []SubLoggerConfig) error

SetupSubLoggers configure all sub loggers with provided configuration values

func Warn

func Warn(sl *SubLogger, data string)

Warn takes a pointer SubLogger struct & string and sends to newLogEvent()

func Warnf

func Warnf(sl *SubLogger, data string, v ...interface{})

Warnf takes a pointer SubLogger struct, string & interface formats and sends to Warn()

func Warnln

func Warnln(sl *SubLogger, v ...interface{})

Warnln takes a pointer SubLogger struct & interface formats and sends to newLogEvent()

Types

type Config

type Config struct {
	Enabled *bool `json:"enabled"`
	SubLoggerConfig
	LoggerFileConfig *loggerFileConfig `json:"fileSettings,omitempty"`
	AdvancedSettings advancedSettings  `json:"advancedSettings"`
	SubLoggers       []SubLoggerConfig `json:"subLoggers,omitempty"`
}

Config holds configuration settings loaded from bot config

func NewConfig

func NewConfig() *Config

NewConfig returns a pointer to a Config struct with default settings

type Levels

type Levels struct {
	Info, Debug, Warn, Error bool
}

Levels flags for each sub logger type

func Level

func Level(name string) (Levels, error)

Level retries the current sub logger levels

func SetLevel

func SetLevel(s, level string) (Levels, error)

SetLevel sets sub logger levels

type Logger

type Logger struct {
	ShowLogSystemName                                bool
	Timestamp                                        string
	InfoHeader, ErrorHeader, DebugHeader, WarnHeader string
	Spacer                                           string
}

Logger represents a single Logger instance with settings

type MultiWriter

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

func (*MultiWriter) Add

func (mw *MultiWriter) Add(writer io.Writer) error

Add appends a new writer to the writers slice

func (*MultiWriter) Remove

func (mw *MultiWriter) Remove(writer io.Writer) error

Remove removes existing writer from writers slice

func (*MultiWriter) Write

func (mw *MultiWriter) Write(p []byte) (int, error)

Write concurrent safe Write for each writer

type Rotate

type Rotate struct {
	FileName string
	Rotate   *bool
	MaxSize  int64
	// contains filtered or unexported fields
}

Rotate struct for each instance of Rotate

func (*Rotate) Close

func (r *Rotate) Close() error

Close handler for open file

func (*Rotate) Write

func (r *Rotate) Write(output []byte) (n int, err error)

Write implementation to satisfy io.Writer handles length check and rotation

type SubLogger

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

SubLogger defines a sub logger that can be used externally

func NewSubLogger

func NewSubLogger(name string) (*SubLogger, error)

NewSubLogger allows for a new sub logger to be registered.

func (*SubLogger) GetLevels

func (sl *SubLogger) GetLevels() Levels

GetLevels returns current functional log levels

func (*SubLogger) SetLevels

func (sl *SubLogger) SetLevels(newLevels Levels)

SetLevels overrides the default levels with new levels

func (*SubLogger) SetOutput

func (sl *SubLogger) SetOutput(o io.Writer)

SetOutput overrides the default output with a new writer

type SubLoggerConfig

type SubLoggerConfig struct {
	Name   string `json:"name,omitempty"`
	Level  string `json:"level"`
	Output string `json:"output"`
}

SubLoggerConfig holds sub logger configuration settings loaded from bot config

Jump to

Keyboard shortcuts

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