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
- Variables
- func Close()
- func NewFilteredWriter(writer io.Writer, mu sync.Locker, filter FilterFunc) io.WriteCloser
- func NewJournaldWriter(writer io.Writer, mu sync.Locker, filter FilterFunc) io.WriteCloser
- func NewPrettyWriter(writer io.Writer, mu sync.Locker, filter FilterFunc, color bool) io.WriteCloser
- type Config
- type ConfigHandler
- type FilterFunc
- type FilteredWriter
- type JournaldWriter
- type PrettyWriter
- type WriterConfig
Constants ¶
const ( File = "file" Stdout = "stdout" Stderr = "stderr" )
Log writers.
const ( Error = "error" All = "all" Info = "info" )
Log levels.
const ( JSON = "json" Text = "text" Color = "color" Journald = "journald" )
Log formatters.
Variables ¶
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 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 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.