Documentation
¶
Index ¶
- Constants
- Variables
- func Debug(msg string)
- func Debugf(format string, args ...any)
- func Err(msg string)
- func ErrX(code int, msg string)
- func Errf(format string, args ...any)
- func ErrfX(code int, format string, args ...any)
- func Good(msg string)
- func Goodf(format string, args ...any)
- func Info(msg string)
- func Infof(format string, args ...any)
- func Msg(msg string)
- func Msgf(format string, args ...any)
- func SetColor(enabled bool)
- func SubInfo(msg string)
- func SubInfof(format string, args ...any)
- func Warn(msg string)
- func Warnf(format string, args ...any)
- type CloseHandler
- type Message
- type Messenger
- func (m *Messenger) AddCloseHandler(handler CloseHandler)
- func (m *Messenger) AddMsgHandler(handler MsgHandler)
- func (m *Messenger) Close() error
- func (m *Messenger) Debug(msg string) error
- func (m *Messenger) Debugf(format string, args ...any) error
- func (m *Messenger) Err(msg string) error
- func (m *Messenger) ErrX(code int, msg string)
- func (m *Messenger) Errf(format string, args ...any) error
- func (m *Messenger) ErrfX(code int, format string, args ...any)
- func (m *Messenger) Good(msg string) error
- func (m *Messenger) Goodf(format string, args ...any) error
- func (m *Messenger) Info(msg string) error
- func (m *Messenger) Infof(format string, args ...any) error
- func (m *Messenger) Msg(msg string) error
- func (m *Messenger) Msgf(format string, args ...any) error
- func (m *Messenger) SetCloseHandler(handler CloseHandler)
- func (m *Messenger) SetColor(enabled bool)
- func (m *Messenger) SetMsgHandler(handler MsgHandler)
- func (m *Messenger) SetPreprocessor(handler Preprocessor)
- func (m *Messenger) SubInfo(msg string) error
- func (m *Messenger) SubInfof(format string, args ...any) error
- func (m *Messenger) Warn(msg string) error
- func (m *Messenger) Warnf(format string, args ...any) error
- type MsgHandler
- type Preprocessor
Constants ¶
const ( TypeDebug = iota // TypeDebug is a debug message TypeErr // TypeErr is an error message TypeErrX // TypeErrX is an error message that will exit TypeGood // TypeGood is a success message TypeInfo // TypeInfo is an informative message TypeMsg // TypeMsg is a generic/plain message TypeSubInfo // TypeSubInfo is an additional info message TypeWarn // TypeWarn is a warning message )
Consts for log message types
const Version string = "1.6.12"
Version is the package version.
Variables ¶
var Timestamp bool
Timestamp is used to determine whether a timestamp is printed to stdout with the message.
Functions ¶
Types ¶
type CloseHandler ¶
type CloseHandler func() error
CloseHandler is a function pointer. CloseHandlers are called when the Messengers is closed and allow for closing of files or sockets.
type Message ¶
type Message struct { Discard bool Raw string Type uint8 // contains filtered or unexported fields }
Message is struct containing all message related data.
func NewMessage ¶
NewMessage will return a new Message instance.
func (*Message) Preprocessed ¶
Preprocessed will return the preprocessed message text.
type Messenger ¶
Messenger will log to STDOUT as well as call a custom log handlers defined by the user. If Timestamp is true, then messages are prepended with an RFC3339 timestamp.
func NewFileMessenger ¶
NewFileMessenger will return a new Messenger instance for logging to a file. The log file will always show the timestamp, but STDOUT will only show the timestamp if Timestamp is true.
func NewMessenger ¶
NewMessenger will return a new Messenger instance for logging.
func (*Messenger) AddCloseHandler ¶
func (m *Messenger) AddCloseHandler(handler CloseHandler)
AddCloseHandler will add a handler for custom actions when the Messenger instance is closed.
func (*Messenger) AddMsgHandler ¶
func (m *Messenger) AddMsgHandler(handler MsgHandler)
AddMsgHandler will add a handler for custom actions when the Messenger logs a message.
func (*Messenger) SetCloseHandler ¶
func (m *Messenger) SetCloseHandler(handler CloseHandler)
SetCloseHandler will set the handler for custom actions when the Messenger instance is closed.
func (*Messenger) SetMsgHandler ¶
func (m *Messenger) SetMsgHandler(handler MsgHandler)
SetMsgHandler will set the handler for custom actions when the Messenger logs a message.
func (*Messenger) SetPreprocessor ¶
func (m *Messenger) SetPreprocessor(handler Preprocessor)
SetPreprocessor will set the handler for preprocessing messages when the Messenger logs a message.
type MsgHandler ¶
MsgHandler is a function pointer. MsgHandlers are called when a message is logged and allow for custom actions like writing to a file or a socket.
type Preprocessor ¶
type Preprocessor func(msg *Message)
Preprocessor is a function pointer. The Preprocessor is called before the message is logged and allows for reformatting of messages such as JSON. Set the Discard field to true to drop messages.