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 ErrXf(code int, format string, args ...any)
- func Errf(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 Log(msg *Message)
- 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) ErrXf(code int, format string, args ...any)
- func (m *Messenger) Errf(format string, args ...any) error
- 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) Log(msg *Message) 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 uint64 = iota TypeErr TypeErrX // An error message that will also exit TypeGood TypeInfo TypeMsg // Generic message TypeSubInfo TypeWarn )
Consts for log message types
const Version string = "1.8.8"
Version is the package version.
Variables ¶
var ( // Prefixes allows you to customize each log message prefix. Prefixes map[uint64]string = map[uint64]string{ TypeDebug: "[#]", TypeErr: "[!]", TypeErrX: "[!]", TypeGood: "[+]", TypeInfo: "[*]", TypeSubInfo: "[=]", TypeWarn: "[-]", } // Timestamp is used to determine whether a timestamp is printed // to stdout with the message. Timestamp bool )
Functions ¶
func Log ¶ added in v1.8.0
func Log(msg *Message)
Log allows for logging of custom message types. If you aren't using a custom Messenger, you probably just want to use log.Msg(...) instead.
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 uint64
// 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) ErrXf ¶ added in v1.7.0
ErrXf will log an error message using a format string and exit.
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 Message's Discard field to true to drop messages.