clog: github.com/go-clog/clog Index | Files

package clog

import "github.com/go-clog/clog"

Package clog is a channel-based logging package for Go.

Index

Package Files

clog.go console.go discord.go file.go logger.go message.go slack.go

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.

func Error Uses

func Error(format string, v ...interface{})

Error writes formatted log in Error level.

func ErrorDepth Uses

func ErrorDepth(skip int, format string, v ...interface{})

ErrorDepth writes formatted log with given skip depth in Error level.

func Fatal Uses

func Fatal(format string, v ...interface{})

Fatal writes formatted log in Fatal level then exits.

func FatalDepth Uses

func FatalDepth(skip int, format string, v ...interface{})

FatalDepth writes formatted log with given skip depth in Fatal level then exits.

func Info Uses

func Info(format string, v ...interface{})

Info writes formatted log in Info level.

func New Uses

func New(name string, initer Initer, opts ...interface{}) error

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.

This function is not concurrent safe.

func NewConsole Uses

func NewConsole(vs ...interface{}) error

NewConsole initializes and appends a new console logger with default name to the managed list.

func NewConsoleWithName Uses

func NewConsoleWithName(name string, vs ...interface{}) error

NewConsoleWithName initializes and appends a new console logger with given name to the managed list.

func NewDiscord Uses

func NewDiscord(vs ...interface{}) error

NewDiscord initializes and appends a new Discord logger with default name to the managed list.

func NewDiscordWithName Uses

func NewDiscordWithName(name string, vs ...interface{}) error

NewDiscordWithName initializes and appends a new Discord logger with given name to the managed list.

func NewFile Uses

func NewFile(vs ...interface{}) error

NewFile initializes and appends a new file logger with default name to the managed list.

func NewFileWithName Uses

func NewFileWithName(name string, vs ...interface{}) error

NewFileWithName initializes and appends a new file logger with given name to the managed list.

func NewFileWriter Uses

func NewFileWriter(filename string, cfg FileRotationConfig) (io.Writer, error)

NewFileWriter returns an io.Writer for synchronized file logger.

func NewSlack Uses

func NewSlack(vs ...interface{}) error

NewSlack initializes and appends a new Slack logger with default name to the managed list.

func NewSlackWithName Uses

func NewSlackWithName(name string, vs ...interface{}) error

NewSlackWithName initializes and appends a new Slack logger with given name to the managed list.

func Remove Uses

func Remove(name string)

Remove removes a logger with given name from the managed list.

This function is not concurrent safe.

func Stop Uses

func Stop()

Stop propagates cancellation to all loggers and waits for completion. This function should always be called before exiting the program.

func Trace Uses

func Trace(format string, v ...interface{})

Trace writes formatted log in Trace level.

func Warn Uses

func Warn(format string, v ...interface{})

Warn writes formatted log in Warn level.

type ConsoleConfig Uses

type ConsoleConfig struct {
    // Minimum logging level of messages to be processed.
    Level Level
}

ConsoleConfig is the config object for the console logger.

type DiscordConfig Uses

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 Uses

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 Uses

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 Uses

type Initer func(string, ...interface{}) (Logger, error)

Initer takes a name and arbitrary number of parameters needed for initalization and returns an initalized logger.

func ConsoleIniter Uses

func ConsoleIniter() Initer

ConsoleIniter returns the initer for the console logger.

func DiscordIniter Uses

func DiscordIniter() Initer

DiscordIniter returns the initer for the Discord logger.

func FileIniter Uses

func FileIniter() Initer

FileIniter returns the initer for the file logger.

func SlackIniter Uses

func SlackIniter() Initer

SlackIniter returns the initer for the Slack logger.

type Level Uses

type Level int

Level is the logging level.

const (
    LevelTrace Level = iota
    LevelInfo
    LevelWarn
    LevelError
    LevelFatal
)

Available logging levels.

func (Level) String Uses

func (l Level) String() string

type Logger Uses

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 Messager Uses

type Messager interface {
    // Level returns the level of the message.
    Level() Level
    fmt.Stringer
}

Messager is a message entry to be processed by logger.

type SlackConfig Uses

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.

Package clog imports 16 packages (graph) and is imported by 5 packages. Updated 2019-11-28. Refresh now. Tools for package owners.