log

package
v0.0.0-...-35dc932 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2022 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

View Source
const ModuleSystem = "System"

Variables

View Source
var (
	Error   = log.Error
	ErrorIf = func(err error) {
		if err != nil {
			log.Error(err)
		}
	}
	Errorf   = log.Errorf
	Info     = log.Info
	Infof    = log.Infof
	Warning  = log.Warning
	Warningf = log.Warningf
	Fatal    = log.Fatal
	Fatalf   = log.Fatalf
	Debug    = log.Debug
	Debugf   = log.Debugf

	IsDebug = func() bool {
		return log.IsEnabledFor(logging.DEBUG)
	}
)

Functions

func FileSyslog

func FileSyslog(level logging.Level, logdir string, module string) logging.LeveledBackend

func Highlight

func Highlight(msg string, level logging.Level) string

func SetupLog

func SetupLog(level logging.Level, syslogaddr string, logdir string, module string)

func SetupSyslog

func SetupSyslog(level logging.Level, syslogaddr string, module string) logging.LeveledBackend

Types

type File

type File struct {
	sync.Mutex

	Location *time.Location
	// contains filtered or unexported fields
}

File describes a file that gets rotated daily

func NewFile

func NewFile(pathFormat string, onClose func(path string, didRotate bool)) (*File, error)

NewFile creates a new file that will be rotated daily (at midnight in specified location). pathFormat is file format accepted by time.Format that will be used to generate a name of the file. It should be unique in a given day e.g. 2006-01-02.txt. If you need more flexibility, use NewFileWithPathGenerator which accepts a function that generates a file path. onClose is an optional function that will be called every time existing file is closed, either as a result calling Close or due to being rotated. didRotate will be true if it was closed due to rotation. If onClose() takes a long time, you should do it in a background goroutine (it blocks all other operations, including writes) Warning: time.Format might format more than you expect e.g. time.Now().Format(`/logs/dir-2/2006-01-02.txt`) will change "-2" in "dir-2" to current day. For better control over path generation, use NewFileWithPathGenerator

func NewFileWithPathGenerator

func NewFileWithPathGenerator(pathGenerator func(time.Time) string, onClose func(path string, didRotate bool)) (*File, error)

NewFileWithPathGenerator creates a new file that will be rotated daily (at midnight in timezone specified by in specified location). pathGenerator is a function that will return a path for a daily log file. It should be unique in a given day e.g. time.Format of "2006-01-02.txt" creates a string unique for the day. onClose is an optional function that will be called every time existing file is closed, either as a result calling Close or due to being rotated. didRotate will be true if it was closed due to rotation. If onClose() takes a long time, you should do it in a background goroutine (it blocks all other operations, including writes)

func (*File) Close

func (f *File) Close() error

Close closes the file

func (*File) Flush

func (f *File) Flush() error

Flush flushes the file

func (*File) Path

func (f *File) Path() string

Path returns full path of the file we're currently writing to

func (*File) Write

func (f *File) Write(d []byte) (int, error)

Write writes data to a file

func (*File) Write2

func (f *File) Write2(d []byte, flush bool) (string, int64, int, error)

Write2 writes data to a file, optionally flushes. To enable users to later seek to where the data was written, it returns name of the file where data was written, offset at which the data was written, number of bytes and error

type Stdlog

type Stdlog struct{}

func (Stdlog) Write

func (s Stdlog) Write(p []byte) (n int, err error)

type SyslogBackend

type SyslogBackend struct {
	Writer *syslog.Writer
}

SyslogBackend is a simple logger to syslog backend. It automatically maps the internal log levels to appropriate syslog log levels.

func NewSyslogBackend

func NewSyslogBackend(prefix string, syslogaddr string, priority syslog.Priority) (b *SyslogBackend, err error)

NewSyslogBackend connects to the syslog daemon using UNIX sockets with the given prefix. If prefix is not given, the prefix will be derived from the launched command.

func NewSyslogBackendPriority

func NewSyslogBackendPriority(prefix string, priority syslog.Priority) (b *SyslogBackend, err error)

NewSyslogBackendPriority is the same as NewSyslogBackend, but with custom syslog priority, like syslog.LOG_LOCAL3|syslog.LOG_DEBUG etc.

func (*SyslogBackend) Log

func (b *SyslogBackend) Log(level logging.Level, calldepth int, rec *logging.Record) error

Log implements the Backend interface.

Jump to

Keyboard shortcuts

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