logs

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMessageFormat = "\t${Level}\t${Log}\t${Message}\t${Context}"
	DefaultTimeFormat    = "2006-01-02 15:04:05"
)

Variables

This section is empty.

Functions

func Module

func Module(m *di.Module)

func TestModule

func TestModule(m *di.Module)

Types

type Config

type Config []LoggerConfig

func NewConfig

func NewConfig() Config

type Level

type Level int
const (
	LevelUndefined Level = iota
	LevelTrace
	LevelDebug
	LevelInfo
	LevelWarn
	LevelError
)

func (Level) MarshalJSON

func (level Level) MarshalJSON() ([]byte, error)

UnmarshalJSON implements the json.Marshaler interface.

func (Level) MarshalYAML

func (level Level) MarshalYAML() (interface{}, error)

func (Level) String

func (level Level) String() string

func (*Level) UnmarshalJSON

func (level *Level) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Level) UnmarshalYAML

func (level *Level) UnmarshalYAML(unmarshal func(interface{}) error) error

type Log

type Log interface {
	Print(ctx context.Context, level Level, v ...interface{})
	Printf(ctx context.Context, level Level, f string, v ...interface{})

	Trace(ctx context.Context, v ...interface{})
	Tracef(ctx context.Context, f string, v ...interface{})

	Debug(ctx context.Context, v ...interface{})
	Debugf(ctx context.Context, f string, v ...interface{})

	Info(ctx context.Context, v ...interface{})
	Infof(ctx context.Context, f string, v ...interface{})

	Warn(ctx context.Context, v ...interface{})
	Warnf(ctx context.Context, f string, v ...interface{})

	Error(ctx context.Context, v ...interface{})
	Errorf(ctx context.Context, f string, v ...interface{})

	Stack(ctx context.Context, v ...interface{})
	Stackf(ctx context.Context, f string, v ...interface{})

	Fatal(ctx context.Context, v ...interface{})
	Fatalf(ctx context.Context, f string, v ...interface{})
}

type LoggerConfig

type LoggerConfig struct {
	Type    LoggerType `yaml:"type"`
	Level   Level      `yaml:"level"`
	Message string     `yaml:"format"`
	Time    string     `yaml:"time_format"`
	Context []string   `yaml:"context"`

	// File logger
	File           string `yaml:"file"`             // File path.
	FileMaxSize    int    `yaml:"file_max_size"`    // Maximum size in megabytes of a log file.
	FileMaxAge     int    `yaml:"file_max_age"`     // Maximum number of days to retain old log files.
	FileMaxBackups int    `yaml:"file_max_backups"` // Maximum number of old log files to retain.
}

type LoggerType

type LoggerType string
const (
	LoggerTypeDefault LoggerType = ""
	LoggerTypeConsole LoggerType = "console"
	LoggerTypeFile    LoggerType = "file"
)

type Logs

type Logs interface {
	Log(name string) Log
}

func New

func New(config Config) Logs

type Record

type Record struct {
	Log     string        // Write name.
	Time    time.Time     // Creation time.
	Level   Level         // Message level.
	Message string        // Optional format string.
	Args    []interface{} // Args to print or format args.
}

Record is a log request.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL