log

package
v0.0.0-...-862e07f Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2019 License: MIT Imports: 18 Imported by: 0

README

Simple logging framework for go with SystemD support

Supports logging to file, syslog, systemd or stderr. Switchable loglevels. Alpha stage. GoDoc

Documentation

Overview

SystemD journal support based on CoreOS Implementation Copyright © 2015 CoreOS, Inc. License: Apache 2.0 http://www.apache.org/licenses/LICENSE-2.0

Other drivers written from scratch and MIT-licensed.

simple logging framework for go with support for syslog, file (including os.Stderr) and SystemD journal.

Copyright © 2019 Dmitry V. Papchenkoff

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Alert

func Alert(message string) error

Non-Sprintf variant of Alert, actually you can use Alertf without 3rd arg

func Alertf

func Alertf(format string, args ...interface{}) error

Sends message with P_Alert if current loglevel permits, uses Sprintf

func Configured

func Configured() bool

returns true if framework has configured driver

func Crit

func Crit(message string) error

Non-Sprintf variant of Critf, actually you can use Critf without 3rd arg

func Critf

func Critf(format string, args ...interface{}) error

Sends message with P_Crit if current loglevel permits, uses Sprintf

func Debug

func Debug(message string) error

Non-Sprintf variant of Debugf, actually you can use Debugf without 3rd arg

func Debugf

func Debugf(format string, args ...interface{}) error

Sends message with P_Debug if current loglevel permits, uses Sprintf

func Emerg

func Emerg(message string) error

Non-Sprintf variant of Emergf, actually you can use Emerg without 3rd arg

func Emergf

func Emergf(format string, args ...interface{}) error

Sends message with P_Emerg if current loglevel permits, uses Sprintf

func Err

func Err(message string) error

Non-Sprintf variant of Errf, actually you can use Errf without 3rd arg

func Errf

func Errf(format string, args ...interface{}) error

Sends message with P_Err if current loglevel permits, uses Sprintf

func Info

func Info(message string) error

Non-Sprintf variant of Infof, actually you can use Infof without 3rd arg

func Infof

func Infof(format string, args ...interface{}) error

Sends message with P_Info if current loglevel permits, uses Sprintf

func Log

func Log(priority Priority, depth int, message string) error

non-sprintf variant of Logf()

func Logf

func Logf(priority Priority, depth int, format string,
	args ...interface{}) error

Common function for sending log message with selected priority.

depth used for trace as in log.Output in standard logger. Uses fmt.Sprintf()

func Must

func Must(args ...interface{}) check.Values

calls Panic() on last arg, returns remaining does nothing if no args given, returns nil if less than 2 args

func Must2

func Must2(arg0, arg1 interface{}) interface{}

calls Panic(arg1), returns arg0, useful for one-line type-assertion

func Notice

func Notice(message string) error

Non-Sprintf variant of Noticef, actually you can use Noticef without 3rd arg

func Noticef

func Noticef(format string, args ...interface{}) error

Sends message with P_Notice if current loglevel permits, uses Sprintf

func Panic

func Panic(condition interface{}, args ...interface{})

Logs error and calls panic() if condition is non-nil error, true bool or any other type.

optional arguments, if given, must start from string and will be passed to fmt.Sprintf

func Trace

func Trace(depth int) (file string, line int, fun string, ok bool)

Generates trace information at depth

func Warning

func Warning(message string) error

Non-Sprintf variant of Warningf, actually you can use Warningf without 3rd arg

func Warningf

func Warningf(format string, args ...interface{}) error

Sends message with P_Warning if current loglevel permits, uses Sprintf

Types

type Driver

type Driver interface {
	Close() error
	Rotate() error
	// contains filtered or unexported methods
}

Common driver type. Rotate() implemented only for file drivers. On other drivers Rotate() always returns nil and does nothing.

func ConfigureFile

func ConfigureFile(path string, stdPriority Priority) (Driver, error)

Configures file log output. Uses os.Stderr if path is "", stdPriority is used for redirected standard logger. Output format is syslog-like, but shows priority instead of tag and pid. Output columns delimited by \t, so you can easily parse output with cut and other such tools.

func ConfigureJournal

func ConfigureJournal(stdPriority Priority) (Driver, error)

Configures output to systemd journal, stdPriority used for standard logger

func ConfigureSyslog

func ConfigureSyslog(network, raddr string, stdPriority syslog.Priority,
	tag string) (Driver, error)

Configures output to syslog, args passed to syslog.Dial(), stdPriority used for redirected standard logger

func ConfigureSyslogDefault

func ConfigureSyslogDefault() (Driver, error)

Configures output to syslog with default values (LOG_DAEMON facility, LOG_WARNING priority for standard logger)

type DrvFile

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

file driver type

func (*DrvFile) Close

func (d *DrvFile) Close() error

Closes output file and switches output to stderr, does nothing if it's already stderr

func (*DrvFile) Rotate

func (d *DrvFile) Rotate() error

Reopens log file if it is a file, switches logging to stderr if operation fails

func (*DrvFile) Write

func (d *DrvFile) Write(p []byte) (n int, err error)

Used only for redirected standard logger, do not use directly

type DrvJournal

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

type for journal driver

func (*DrvJournal) Close

func (d *DrvJournal) Close() error

Closes journal connection

func (*DrvJournal) Rotate

func (d *DrvJournal) Rotate() error

Does nothing

func (*DrvJournal) Write

func (d *DrvJournal) Write(p []byte) (n int, err error)

Used only for standard logger, do not use directly

type DrvSyslog

type DrvSyslog struct {
	*syslog.Writer
}

syslog driver type

func (DrvSyslog) Close

func (d DrvSyslog) Close() error

Closes syslog connection

func (DrvSyslog) Rotate

func (d DrvSyslog) Rotate() error

Does nothing

type Priority

type Priority uint
const (
	P_Emerg Priority = iota
	P_Alert
	P_Crit
	P_Err
	P_Warning
	P_Notice
	P_Info
	P_Debug
)

Priorities for messages, integer value compatible with syslog.

func SetLevel

func SetLevel(level Priority) Priority

Sets minimal loglevel, messages with higher priority silently skipped without heavy routines

func (Priority) String

func (p Priority) String() string

used for formatting

Jump to

Keyboard shortcuts

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