log

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2019 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package log deals with logging.

It contains configurable writers for the IPFS log, such as for writing to files with file rotation, or for writing colored output to a console.

Index

Constants

View Source
const (
	File   = "file"
	Stdout = "stdout"
	Stderr = "stderr"
)

Log writers.

View Source
const (
	Error = "error"
	All   = "all"
	Info  = "info"
)

Log levels.

View Source
const (
	JSON     = "json"
	Text     = "text"
	Color    = "color"
	Journald = "journald"
)

Log formatters.

Variables

View Source
var (
	// ErrInvalidWriterType is returned when a writer has an invalid type.
	ErrInvalidWriterType = errors.New("log writer has an invalid type")

	// ErrInvalidWriterLevel is returned when a writer has an invalid
	// level.
	ErrInvalidWriterLevel = errors.New("log writer has an invalid level")

	// ErrInvalidWriterFormatter is returned when a writer has an invalid
	// formatter.
	ErrInvalidWriterFormatter = errors.New("log writer has an invalid formatter")
)

Functions

func Close

func Close()

Close closes all the closers.

func NewFilteredWriter

func NewFilteredWriter(writer io.Writer, mu sync.Locker, filter FilterFunc) io.WriteCloser

NewFilteredWriter creates a new filtered writer.

func NewJournaldWriter

func NewJournaldWriter(writer io.Writer, mu sync.Locker, filter FilterFunc) io.WriteCloser

NewJournaldWriter creates a new journald writer.

func NewPrettyWriter

func NewPrettyWriter(writer io.Writer, mu sync.Locker, filter FilterFunc, color bool) io.WriteCloser

NewPrettyWriter creates a new pretty writer.

Types

type Config

type Config struct {
	// Writers are the writers for the log.
	Writers []WriterConfig `toml:"writers"`
}

Config contains configuration options for the log.

type ConfigHandler

type ConfigHandler struct {
	// contains filtered or unexported fields
}

ConfigHandler is the handler of the log configuration.

func (*ConfigHandler) Config

func (h *ConfigHandler) Config() interface{}

Config returns the current service configuration or creates one with good default values.

The default configuration writes to a single file using the JSON formatter and weekly rotations.

func (*ConfigHandler) ID

func (h *ConfigHandler) ID() string

ID returns the unique identifier of the configuration.

func (*ConfigHandler) SetConfig

func (h *ConfigHandler) SetConfig(config interface{}) error

SetConfig configures the service handler.

type FilterFunc

type FilterFunc func(map[string]interface{}) bool

FilterFunc filters log entries.

type FilteredWriter

type FilteredWriter struct {
	io.WriteCloser
}

FilteredWriter filters log output.

type JournaldWriter

type JournaldWriter struct {
	io.WriteCloser
}

JournaldWriter prefixes error levels and removes the time.

type PrettyWriter

type PrettyWriter struct {
	io.WriteCloser
	// contains filtered or unexported fields
}

PrettyWriter writes nicely formatted log output to a console.

type WriterConfig

type WriterConfig struct {
	// Type is the type of the writer.
	Type string `toml:"type" comment:"The type of writer (file, stdout, stderr)."`

	// Level is the log level for the writer.
	Level string `toml:"level" comment:"The log level for the writer (info, error, all)."`

	// File is the log formatter for the writer.
	Formatter string `toml:"formatter" comment:"The formatter for the writer (json, text, color, journald)."`

	// Filename is the file for a file logger.
	Filename string `toml:"filename" comment:"The file for a file logger."`

	// MaximumSize is the maximum size of the file in megabytes before a
	// rotation.
	MaximumSize int `toml:"maximum_size" comment:"The maximum size of the file in megabytes before a rotation."`

	// MaximumAge is the maximum age of the file in days before a rotation.
	MaximumAge int `toml:"maximum_age" comment:"The maximum age of the file in days before a rotation."`

	// MaximumBackups is the maximum number of backups.
	MaximumBackups int `toml:"maximum_backups" comment:"The maximum number of backups."`

	// UseLocalTime is whether to use local time instead of UTC.
	UseLocalTime bool `toml:"use_local_time" comment:"Whether to use local time instead of UTC for backups."`

	// Compress is whether to compress the file.
	Compress bool `toml:"compress" comment:"Whether to compress the file."`
}

WriterConfig contains configuration for a log writer.

Jump to

Keyboard shortcuts

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