log

package
v1.0.19 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (

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

Variables

View Source
var (

	// ErrSubLoggerAlreadyRegistered Returned when a sublogger 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 Debugf

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

Debugf is a logging function that takes a sublogger, a format string along with optional arguments. This writes to configured io.Writer(s) as an debug message which formats according to the format specifier. A new line is automatically added to the output.

func DebugfWithFields

func DebugfWithFields(sl *SubLogger, extra ExtraFields, format string, a ...interface{})

DebugfWithFields is a logging function that takes a sublogger, additional structured logging fields, a format string along with optional arguments. This writes to configured io.Writer(s) as an debug message which formats according to the format specifier. A new line is automatically added to the output. If structured logging is not enabled, the fields will be ignored.

func Debugln

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

Debugln is a logging function that takes a sublogger and an arbitrary number of interface{} arguments. This writes to configured io.Writer(s) as an debug message using default formats for its operands. A new line is automatically added to the output.

func DebuglnWithFields

func DebuglnWithFields(sl *SubLogger, extra ExtraFields, a ...interface{})

DebuglnWithFields is a logging function that takes a sublogger, additional structured logging fields and an arbitrary number of interface{} arguments. This writes to configured io.Writer(s) as an debug message using default formats for its operands. A new line is automatically added to the output. If structured logging is not enabled, the fields will be ignored.

func Errorf

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

Errorf is a logging function that takes a sublogger, a format string along with optional arguments. This writes to configured io.Writer(s) as an error message which formats according to the format specifier. A new line is automatically added to the output.

func ErrorfWithFields

func ErrorfWithFields(sl *SubLogger, extra ExtraFields, format string, a ...interface{})

ErrorfWithFields is a logging function that takes a sublogger, additional structured logging fields, a format string along with optional arguments. This writes to configured io.Writer(s) as an error message which formats according to the format specifier. A new line is automatically added to the output. If structured logging is not enabled, the fields will be ignored.

func Errorln

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

Errorln is a logging function that takes a sublogger and an arbitrary number of interface{} arguments. This writes to configured io.Writer(s) as an error message using default formats for its operands. A new line is automatically added to the output.

func ErrorlnWithFields

func ErrorlnWithFields(sl *SubLogger, extra ExtraFields, a ...interface{})

ErrorlnWithFields is a logging function that takes a sublogger, additional structured logging fields and an arbitrary number of interface{} arguments. This writes to configured io.Writer(s) as an error message using default formats for its operands. A new line is automatically added to the output. If structured logging is not enabled, the fields will be ignored.

func GetLogPath

func GetLogPath() string

GetLogPath returns path of log file

func Infof

func Infof(sl *SubLogger, format string, a ...interface{})

Infof is a logging function that takes a sublogger, a format string along with optional arguments. This writes to configured io.Writer(s) as an information message which formats according to the format specifier. A new line is automatically added to the output.

func InfofWithFields

func InfofWithFields(sl *SubLogger, extra ExtraFields, format string, a ...interface{})

InfofWithFields is a logging function that takes a sublogger, additional structured logging fields, a format string along with optional arguments. This writes to configured io.Writer(s) as an information message which formats according to the format specifier. A new line is automatically added to the output. If structured logging is not enabled, the fields will be ignored.

func Infoln

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

Infoln is a logging function that takes a sublogger and an arbitrary number of interface{} arguments. This writes to configured io.Writer(s) as an information message using default formats for its operands. A new line is automatically added to the output.

func InfolnWithFields

func InfolnWithFields(sl *SubLogger, extra ExtraFields, a ...interface{})

InfolnWithFields is a logging function that takes a sublogger, additional structured logging fields and an arbitrary number of interface{} arguments. This writes to configured io.Writer(s) as an information message using default formats for its operands. A new line is automatically added to the output. If structured logging is not enabled, the fields will be ignored.

func SetFileLoggingState

func SetFileLoggingState(correctlyConfigured bool)

SetFileLoggingState can set file logging state if it is correctly configured or not. This will bypass the ability to log to file if set as false.

func SetGlobalLogConfig

func SetGlobalLogConfig(incoming *Config) error

SetGlobalLogConfig sets the global config with the supplied config

func SetLogPath

func SetLogPath(newLogPath string) error

SetLogPath sets the log path for writing to file

func SetupGlobalLogger

func SetupGlobalLogger(botName string, structuredOutput bool) error

SetupGlobalLogger setup 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 Warnf

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

Warnf is a logging function that takes a sublogger, a format string along with optional arguments. This writes to configured io.Writer(s) as an warning message which formats according to the format specifier. A new line is automatically added to the output.

func WarnfWithFields

func WarnfWithFields(sl *SubLogger, extra ExtraFields, format string, a ...interface{})

WarnfWithFields is a logging function that takes a sublogger, additional structured logging fields, a format string along with optional arguments. This writes to configured io.Writer(s) as an warning message which formats according to the format specifier. A new line is automatically added to the output. If structured logging is not enabled, the fields will be ignored.

func Warnln

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

Warnln is a logging function that takes a sublogger and an arbitrary number of interface{} arguments. This writes to configured io.Writer(s) as an warning message using default formats for its operands. A new line is automatically added to the output.

func WarnlnWithFields

func WarnlnWithFields(sl *SubLogger, extra ExtraFields, a ...interface{})

WarnlnWithFields is a logging function that takes a sublogger, additional structured logging fields and an arbitrary number of interface{} arguments. This writes to configured io.Writer(s) as an warning message using default formats for its operands. A new line is automatically added to the output. If structured logging is not enabled, the fields will be ignored.

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 GenDefaultSettings

func GenDefaultSettings() *Config

GenDefaultSettings return struct with known sane/working logger settings

type ExtraFields

type ExtraFields map[Key]interface{}

ExtraFields is a map of key value pairs that can be added to a structured log output.

type Key

type Key string

Key is used for structured logging fields to ensure no collisions occur. Unexported keys are default fields which cannot be overwritten.

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 retrieves the current sublogger levels

func SetLevel

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

SetLevel sets sublogger levels

type Logger

type Logger struct {
	ShowLogSystemName                                bool
	BypassJobChannelFilledWarning                    bool
	TimestampFormat                                  string
	InfoHeader, ErrorHeader, DebugHeader, WarnHeader string
	Spacer                                           string
	Level                                            string
	// contains filtered or unexported fields
}

Logger each instance of logger settings

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 can be used externally for packages wanted to leverage GCT library logger features.

var (
	SubLoggers = map[string]*SubLogger{}

	Global           *SubLogger
	ConnectionMgr    *SubLogger
	CommunicationMgr *SubLogger
	APIServerMgr     *SubLogger
	ConfigMgr        *SubLogger
	DatabaseMgr      *SubLogger
	DataHistory      *SubLogger
	GCTScriptMgr     *SubLogger
	OrderMgr         *SubLogger
	PortfolioMgr     *SubLogger
	SyncMgr          *SubLogger
	TimeMgr          *SubLogger
	WebsocketMgr     *SubLogger
	EventMgr         *SubLogger
	DispatchMgr      *SubLogger

	RequestSys  *SubLogger
	ExchangeSys *SubLogger
	GRPCSys     *SubLogger
	RESTSys     *SubLogger

	Ticker    *SubLogger
	OrderBook *SubLogger
	Trade     *SubLogger
	Fill      *SubLogger
	Currency  *SubLogger
)

Global vars related to the logger package

func NewSubLogger

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

NewSubLogger allows for a new sub logger to be registered.

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