Documentation ¶
Overview ¶
Package clog is a channel-based logging package for Go.
Index ¶
- Constants
- func Error(format string, v ...interface{})
- func ErrorDepth(skip int, format string, v ...interface{})
- func ErrorDepthTo(name string, skip int, format string, v ...interface{})
- func ErrorTo(name, format string, v ...interface{})
- func Fatal(format string, v ...interface{})
- func FatalDepth(skip int, format string, v ...interface{})
- func FatalDepthTo(name string, skip int, format string, v ...interface{})
- func FatalTo(name, format string, v ...interface{})
- func Info(format string, v ...interface{})
- func InfoTo(name, format string, v ...interface{})
- func New(name string, initer Initer, opts ...interface{}) error
- func NewConsole(vs ...interface{}) error
- func NewConsoleWithName(name string, vs ...interface{}) error
- func NewDiscord(vs ...interface{}) error
- func NewDiscordWithName(name string, vs ...interface{}) error
- func NewFile(vs ...interface{}) error
- func NewFileWithName(name string, vs ...interface{}) error
- func NewFileWriter(filename string, cfg FileRotationConfig) (io.Writer, error)
- func NewSlack(vs ...interface{}) error
- func NewSlackWithName(name string, vs ...interface{}) error
- func Remove(name string)
- func Stop()
- func Trace(format string, v ...interface{})
- func TraceTo(name, format string, v ...interface{})
- func Warn(format string, v ...interface{})
- func WarnTo(name, format string, v ...interface{})
- type ConsoleConfig
- type DiscordConfig
- type FileConfig
- type FileRotationConfig
- type Initer
- type Level
- type Logger
- type Messager
- type SlackConfig
Constants ¶
const DefaultConsoleName = "console"
DefaultConsoleName is the default name for the console logger.
const DefaultDiscordName = "discord"
DefaultDiscordName is the default name for the Discord logger.
const DefaultFileName = "file"
DefaultFileName is the default name for the file logger.
const DefaultSlackName = "slack"
DefaultSlackName is the default name for the Slack logger.
Variables ¶
This section is empty.
Functions ¶
func ErrorDepth ¶
ErrorDepth writes formatted log with given skip depth in Error level.
func ErrorDepthTo ¶ added in v2.2.0
ErrorDepthTo writes formatted log with given skip depth in Error level to the logger with given name.
func ErrorTo ¶ added in v2.2.0
func ErrorTo(name, format string, v ...interface{})
ErrorTo writes formatted log in Error level to the logger with given name.
func Fatal ¶
func Fatal(format string, v ...interface{})
Fatal writes formatted log in Fatal level then exits.
func FatalDepth ¶
FatalDepth writes formatted log with given skip depth in Fatal level then exits.
func FatalDepthTo ¶ added in v2.2.0
FatalDepthTo writes formatted log with given skip depth in Fatal level to the logger with given name then exits.
func FatalTo ¶ added in v2.2.0
func FatalTo(name, format string, v ...interface{})
FatalTo writes formatted log in Fatal level to the logger with given name then exits.
func InfoTo ¶ added in v2.2.0
func InfoTo(name, format string, v ...interface{})
InfoTo writes formatted log in Info level to the logger with given name.
func New ¶
New initializes and appends a new logger to the managed list. Calling this function multiple times will overwrite previous initialized logger with the same name.
Any integer type (i.e. int, int32, int64) will be used as buffer size. Otherwise, the value will be passed to the initer.
NOTE: This function is not concurrent safe.
func NewConsole ¶
func NewConsole(vs ...interface{}) error
NewConsole initializes and appends a new console logger with default name to the managed list.
func NewConsoleWithName ¶
NewConsoleWithName initializes and appends a new console logger with given name to the managed list.
func NewDiscord ¶
func NewDiscord(vs ...interface{}) error
NewDiscord initializes and appends a new Discord logger with default name to the managed list.
func NewDiscordWithName ¶
NewDiscordWithName initializes and appends a new Discord logger with given name to the managed list.
func NewFile ¶
func NewFile(vs ...interface{}) error
NewFile initializes and appends a new file logger with default name to the managed list.
func NewFileWithName ¶
NewFileWithName initializes and appends a new file logger with given name to the managed list.
func NewFileWriter ¶
func NewFileWriter(filename string, cfg FileRotationConfig) (io.Writer, error)
NewFileWriter returns an io.Writer for synchronized file logger.
func NewSlack ¶
func NewSlack(vs ...interface{}) error
NewSlack initializes and appends a new Slack logger with default name to the managed list.
func NewSlackWithName ¶
NewSlackWithName initializes and appends a new Slack logger with given name to the managed list.
func Remove ¶
func Remove(name string)
Remove removes a logger with given name from the managed list.
NOTE: This function is not concurrent safe.
func Stop ¶
func Stop()
Stop propagates cancellation to all loggers and waits for completion. This function should always be called before exiting the program.
Types ¶
type ConsoleConfig ¶
type ConsoleConfig struct { // Minimum logging level of messages to be processed. Level Level }
ConsoleConfig is the config object for the console logger.
type DiscordConfig ¶
type DiscordConfig struct { // Minimum logging level of messages to be processed. Level Level // Discord webhook URL. URL string // Username to be shown in the message. // Leave empty to use default as set in the Discord. Username string // Title for different levels, must have exact 5 elements in the order of // Trace, Info, Warn, Error, and Fatal. Titles []string // Colors for different levels, must have exact 5 elements in the order of // Trace, Info, Warn, Error, and Fatal. Colors []int }
DiscordConfig is the config object for the Discord logger.
type FileConfig ¶
type FileConfig struct { // Minimum level of messages to be processed. Level Level // File name to output messages. Filename string // Rotation related configurations. FileRotationConfig }
FileConfig is the config object for the file logger.
type FileRotationConfig ¶
type FileRotationConfig struct { // Do rotation for output files. Rotate bool // Rotate on daily basis. Daily bool // Maximum size in bytes of file for a rotation. MaxSize int64 // Maximum number of lines for a rotation. MaxLines int64 // Maximum lifetime of a output file in days. MaxDays int64 }
FileRotationConfig represents rotation related configurations for file mode logger. All the settings can take effect at the same time, remain zero values to disable them.
type Initer ¶
Initer takes a name and arbitrary number of parameters needed for initalization and returns an initalized logger.
func ConsoleIniter ¶
func ConsoleIniter() Initer
ConsoleIniter returns the initer for the console logger.
func DiscordIniter ¶
func DiscordIniter() Initer
DiscordIniter returns the initer for the Discord logger.
type Logger ¶
type Logger interface { // Name returns the name can used to identify the logger. Name() string // Level returns the minimum logging level of the logger. Level() Level // Write processes a Messager entry. Write(Messager) error }
Logger is an interface for a logger with a specific name and level.
type SlackConfig ¶
type SlackConfig struct { // Minimum logging level of messages to be processed. Level Level // Slack webhook URL. URL string // Colors for different levels, must have exact 5 elements in the order of // Trace, Info, Warn, Error, and Fatal. Colors []string }
SlackConfig is the config object for the Slack logger.