Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var FallbackLogger = logrus.StandardLogger()
FallbackLogger is an alias for the standard logger
Functions ¶
func WithLogger ¶
func WithLogger(ctx context.Context, logger LoggerIface) context.Context
WithLogger returns a new context with the provided logger. Use in combination with logger.WithField(s) for great effect
Types ¶
type BrokerHook ¶
type BrokerHook struct {
// contains filtered or unexported fields
}
BrokerHook is the implementation of the logrus hook for publicating logs to subscribers
func NewBrokerHook ¶
func NewBrokerHook(ctx context.Context, level string) *BrokerHook
NewBrokerHook creates a LogHook to be added to an instance of logger
func (*BrokerHook) AddSubscriber ¶
func (hook *BrokerHook) AddSubscriber(msgCh MessageChanType)
AddSubscriber adds receiving channel to the subscription
func (*BrokerHook) Fire ¶
func (hook *BrokerHook) Fire(entry *logrus.Entry) error
Fire adds logrus log message to the internal queue for processing
func (*BrokerHook) Levels ¶
func (hook *BrokerHook) Levels() []logrus.Level
Levels returns the available logging levels
func (*BrokerHook) RemoveSubscriber ¶
func (hook *BrokerHook) RemoveSubscriber(msgCh MessageChanType)
RemoveSubscriber deletes receiving channel from the subscription
func (*BrokerHook) SetBrokerFormatter ¶
func (hook *BrokerHook) SetBrokerFormatter(formatter logrus.Formatter)
SetBrokerFormatter sets the format that will be used by hook.
type CmdOpts ¶
type CmdOpts struct { LogLevel string `` /* 164-byte string literal not displayed */ LogFile string `long:"log-file" mapstructure:"log-file" description:"File name to store logs"` LogFileFormat string `` /* 130-byte string literal not displayed */ LogFileRotate bool `long:"log-file-rotate" mapstructure:"log-file-rotate" description:"Rotate log files"` LogFileSize int `` /* 135-byte string literal not displayed */ LogFileAge int `` /* 129-byte string literal not displayed */ LogFileNumber int `` /* 138-byte string literal not displayed */ }
CmdOpts specifies the logging command-line options
type Formatter ¶
type Formatter struct { // FieldsOrder - default: fields sorted alphabetically FieldsOrder []string // TimestampFormat - default: time.StampMilli = "Jan _2 15:04:05.000" TimestampFormat string // HideKeys - show [fieldValue] instead of [fieldKey:fieldValue] HideKeys bool // NoColors - disable colors NoColors bool // NoFieldsColors - apply colors only to the level, default is level + fields NoFieldsColors bool // NoFieldsSpace - no space between fields NoFieldsSpace bool // ShowFullLevel - show a full level [WARNING] instead of [WARN] ShowFullLevel bool // NoUppercaseLevel - no upper case for level value NoUppercaseLevel bool // TrimMessages - trim whitespaces on messages TrimMessages bool // CallerFirst - print caller info first CallerFirst bool // CustomCallerFormatter - set custom formatter for caller info CustomCallerFormatter func(*runtime.Frame) string }
Formatter - logrus formatter, implements logrus.Formatter Forked from "github.com/antonfisher/nested-logrus-formatter"
func (*Formatter) Format ¶
Format an log entry
Example (Default) ¶
package main import ( "os" formatter "github.com/cybertec-postgresql/pgwatch/v3/internal/log" "github.com/sirupsen/logrus" ) func main() { l := logrus.New() l.SetOutput(os.Stdout) l.SetLevel(logrus.DebugLevel) l.SetFormatter(&formatter.Formatter{ NoColors: true, TimestampFormat: "-", }) l.Debug("test1") l.Info("test2") l.Warn("test3") l.Error("test4") }
Output: - [DEBU] test1 - [INFO] test2 - [WARN] test3 - [ERRO] test4
Example (Field_order) ¶
package main import ( "os" formatter "github.com/cybertec-postgresql/pgwatch/v3/internal/log" "github.com/sirupsen/logrus" ) func main() { l := logrus.New() l.SetOutput(os.Stdout) l.SetLevel(logrus.DebugLevel) l.SetFormatter(&formatter.Formatter{ NoColors: true, TimestampFormat: "-", FieldsOrder: []string{"component", "category"}, HideKeys: false, }) ll := l.WithField("component", "main") lll := ll.WithField("category", "rest") l.Info("test1") ll.Info("test2") lll.Info("test3") }
Output: - [INFO] test1 - [INFO] [component:main] test2 - [INFO] [component:main] [category:rest] test3
Example (Full_level) ¶
package main import ( "os" formatter "github.com/cybertec-postgresql/pgwatch/v3/internal/log" "github.com/sirupsen/logrus" ) func main() { l := logrus.New() l.SetOutput(os.Stdout) l.SetLevel(logrus.DebugLevel) l.SetFormatter(&formatter.Formatter{ NoColors: true, TimestampFormat: "-", ShowFullLevel: true, }) l.Debug("test1") l.Info("test2") l.Warn("test3") l.Error(" test4") }
Output: - [DEBUG] test1 - [INFO] test2 - [WARNING] test3 - [ERROR] test4
Example (Hide_keys) ¶
package main import ( "os" formatter "github.com/cybertec-postgresql/pgwatch/v3/internal/log" "github.com/sirupsen/logrus" ) func main() { l := logrus.New() l.SetOutput(os.Stdout) l.SetLevel(logrus.DebugLevel) l.SetFormatter(&formatter.Formatter{ NoColors: true, TimestampFormat: "-", HideKeys: true, }) ll := l.WithField("category", "rest") l.Info("test1") ll.Info("test2") }
Output: - [INFO] test1 - [INFO] [rest] test2
Example (No_fields_space) ¶
package main import ( "os" formatter "github.com/cybertec-postgresql/pgwatch/v3/internal/log" "github.com/sirupsen/logrus" ) func main() { l := logrus.New() l.SetOutput(os.Stdout) l.SetLevel(logrus.DebugLevel) l.SetFormatter(&formatter.Formatter{ NoColors: true, TimestampFormat: "-", FieldsOrder: []string{"component", "category"}, HideKeys: false, NoFieldsSpace: true, }) ll := l.WithField("component", "main") lll := ll.WithField("category", "rest") l.Info("test1") ll.Info("test2") lll.Info("test3") }
Output: - [INFO] test1 - [INFO][component:main] test2 - [INFO][component:main][category:rest] test3
Example (No_uppercase_level) ¶
package main import ( "os" formatter "github.com/cybertec-postgresql/pgwatch/v3/internal/log" "github.com/sirupsen/logrus" ) func main() { l := logrus.New() l.SetOutput(os.Stdout) l.SetLevel(logrus.DebugLevel) l.SetFormatter(&formatter.Formatter{ NoColors: true, TimestampFormat: "-", FieldsOrder: []string{"component", "category"}, NoUppercaseLevel: true, }) ll := l.WithField("component", "main") lll := ll.WithField("category", "rest") llll := ll.WithField("category", "other") l.Debug("test1") ll.Info("test2") lll.Warn("test3") llll.Error("test4") }
Output: - [debu] test1 - [info] [component:main] test2 - [warn] [component:main] [category:rest] test3 - [erro] [component:main] [category:other] test4
Example (Show_keys) ¶
package main import ( "os" formatter "github.com/cybertec-postgresql/pgwatch/v3/internal/log" "github.com/sirupsen/logrus" ) func main() { l := logrus.New() l.SetOutput(os.Stdout) l.SetLevel(logrus.DebugLevel) l.SetFormatter(&formatter.Formatter{ NoColors: true, TimestampFormat: "-", HideKeys: false, }) ll := l.WithField("category", "rest") l.Info("test1") ll.Info("test2") }
Output: - [INFO] test1 - [INFO] [category:rest] test2
Example (Sort_order) ¶
package main import ( "os" formatter "github.com/cybertec-postgresql/pgwatch/v3/internal/log" "github.com/sirupsen/logrus" ) func main() { l := logrus.New() l.SetOutput(os.Stdout) l.SetLevel(logrus.DebugLevel) l.SetFormatter(&formatter.Formatter{ NoColors: true, TimestampFormat: "-", HideKeys: false, }) ll := l.WithField("component", "main") lll := ll.WithField("category", "rest") l.Info("test1") ll.Info("test2") lll.Info("test3") }
Output: - [INFO] test1 - [INFO] [component:main] test2 - [INFO] [category:rest] [component:main] test3
Example (Trim_message) ¶
package main import ( "os" formatter "github.com/cybertec-postgresql/pgwatch/v3/internal/log" "github.com/sirupsen/logrus" ) func main() { l := logrus.New() l.SetOutput(os.Stdout) l.SetLevel(logrus.DebugLevel) l.SetFormatter(&formatter.Formatter{ TrimMessages: true, NoColors: true, TimestampFormat: "-", }) l.Debug(" test1 ") l.Info("test2 ") l.Warn(" test3") l.Error(" test4 ") }
Output: - [DEBU] test1 - [INFO] test2 - [WARN] test3 - [ERRO] test4
type LoggerHookerIface ¶
type LoggerHookerIface interface { LoggerIface AddHook(hook logrus.Hook) AddSubscriber(msgCh MessageChanType) RemoveSubscriber(msgCh MessageChanType) }
LoggerHookerIface adds AddHook method to LoggerIface for database logging hook
func Init ¶
func Init(opts CmdOpts) LoggerHookerIface
Init creates logging facilities for the application
type LoggerIface ¶
type LoggerIface logrus.FieldLogger
LoggerIface is the interface used by all components
func GetLogger ¶
func GetLogger(ctx context.Context) LoggerIface
GetLogger retrieves the current logger from the context. If no logger is available, the default logger is returned
type MessageChanType ¶
type MessageChanType chan MessageType
MessageChanType represents the format of the message channel
type PgxLogger ¶
type PgxLogger struct {
// contains filtered or unexported fields
}
PgxLogger is the struct used to log using pgx postgres driver
func NewPgxLogger ¶
func NewPgxLogger(l LoggerIface) *PgxLogger
NewPgxLogger returns a new instance of PgxLogger