skyhook

package module
v0.0.0-...-bf83924 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2019 License: MIT Imports: 8 Imported by: 0

README

Local Filesystem Hook for logrus

GoDoc

Sometimes developers like to write directly to a file on the filesystem. This is a hook for logrus which designed to allow users to do that. The log levels are dynamic at instantiation of the hook, so it is capable of logging at some or all levels.

Note:

User who run the go application must have read/write permissions to the selected log files. If the files do not exists yet, then user must have permission to the target directory.

Documentation

Overview

Package skyhook is hook for sirupsen/logrus that used for writing the logs to local files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PathMap

type PathMap map[logrus.Level]string

PathMap is map for mapping a log level to a file's path. Multiple levels may share a file, but multiple files may not be used for one level.

type SkyHook

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

SkyHook is a hook to handle writing to local log files.

func NewHook

func NewHook(output interface{}, formatter logrus.Formatter) *SkyHook

NewHook returns new Sky hook. Output can be a string, io.Writer, WriterMap or PathMap. If using io.Writer or WriterMap, user is responsible for closing the used io.Writer.

func (*SkyHook) Fire

func (hook *SkyHook) Fire(entry *logrus.Entry) error

Fire writes the log file to defined path or using the defined writer. User who run this function needs write permissions to the file or directory if the file does not yet exist.

func (*SkyHook) Levels

func (hook *SkyHook) Levels() []logrus.Level

Levels returns configured log levels.

func (*SkyHook) SetDefaultPath

func (hook *SkyHook) SetDefaultPath(defaultPath string)

SetDefaultPath sets default path for levels that don't have any defined output path.

func (*SkyHook) SetDefaultWriter

func (hook *SkyHook) SetDefaultWriter(defaultWriter io.Writer)

SetDefaultWriter sets default writer for levels that don't have any defined writer.

func (*SkyHook) SetFormatter

func (hook *SkyHook) SetFormatter(formatter logrus.Formatter)

SetFormatter sets the format that will be used by hook. If using text formatter, this method will disable color output to make the log file more readable.

type WriterMap

type WriterMap map[logrus.Level]io.Writer

WriterMap is map for mapping a log level to an io.Writer. Multiple levels may share a writer, but multiple writers may not be used for one level.

Jump to

Keyboard shortcuts

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