log

package
v0.0.0-...-197d37f Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2016 License: MIT Imports: 9 Imported by: 4

Documentation

Overview

Package log connects to a local or remote syslog server with fallback to stderr output.

Index

Constants

This section is empty.

Variables

View Source
var Close = func() error {
	if remoteLogger == nil {
		return nil
	}

	err := remoteLogger.Close()
	if err == nil {
		remoteLogger = nil
	}
	return err
}

Close closes a connection to the syslog daemon. It is declared as a variable to allow an easy mocking.

View Source
var (
	// ErrDialTimeout returned when a syslog dial connection takes too long to be
	// established.
	ErrDialTimeout = errors.New("dial timeout")
)
View Source
var (

	// LocalLogger is the fallback log used when the remote logger isn't
	// available.
	LocalLogger *log.Logger
)
View Source
var NewLogger = func(id string) Logger {
	return &logger{
		identifier: "[" + id + "] ",
		caller:     3,
	}
}

NewLogger returns a internal instance of the Logger type tagging an identifier to every message logged. This identifier is useful to group many messages to one related transaction id.

Functions

func Alert

func Alert(a ...interface{})

Alert log an emergency message

func Alertf

func Alertf(m string, a ...interface{})

Alertf log an emergency message with arguments

func Crit

func Crit(a ...interface{})

Crit log an emergency message

func Critf

func Critf(m string, a ...interface{})

Critf log an emergency message with arguments

func Debug

func Debug(a ...interface{})

Debug log an emergency message

func Debugf

func Debugf(m string, a ...interface{})

Debugf log an emergency message with arguments

func Dial

func Dial(network, raddr, tag string, timeout time.Duration) error

Dial establishes a connection to a log daemon by connecting to address raddr on the specified network. Each write to the returned writer sends a log message with the given facility, severity and tag. If network is empty, Dial will connect to the local syslog server. A connection timeout defines how long it will wait for the connection until a timeout error is raised.

func Emerg

func Emerg(a ...interface{})

Emerg log an emergency message

func Emergf

func Emergf(m string, a ...interface{})

Emergf log an emergency message with arguments

func Error

func Error(err error)

Error log an emergency message

func Errorf

func Errorf(m string, a ...interface{})

Errorf log an emergency message with arguments

func Info

func Info(a ...interface{})

Info log an emergency message

func Infof

func Infof(m string, a ...interface{})

Infof log an emergency message with arguments

func Notice

func Notice(a ...interface{})

Notice log an emergency message

func Noticef

func Noticef(m string, a ...interface{})

Noticef log an emergency message with arguments

func Warning

func Warning(a ...interface{})

Warning log an emergency message

func Warningf

func Warningf(m string, a ...interface{})

Warningf log an emergency message with arguments

Types

type Level

type Level int

Level defines the severity of an error. For example, if a custom error is created as bellow:

  import "github.com/registrobr/gostk/log"

  type ErrDatabaseFailure struct {
  }

  func (e ErrDatabaseFailure) Error() string {
    return "database failure!"
  }

  func (e ErrDatabaseFailure) Level() log.Level {
    return log.LevelEmergency
  }

When used with the Logger type will be written in the syslog in the
corresponding log level.
const (
	// LevelEmergency sets a high priority level of problem advising that system
	// is unusable.
	LevelEmergency Level = 0

	// LevelAlert sets a high priority level of problem advising to correct
	// immediately.
	LevelAlert Level = 1

	// LevelCritical sets a medium priority level of problem indicating a failure
	// in a primary system.
	LevelCritical Level = 2

	// LevelError sets a medium priority level of problem indicating a non-urgent
	// failure.
	LevelError Level = 3

	// LevelWarning sets a low priority level indicating that an error will occur
	// if action is not taken.
	LevelWarning Level = 4

	// LevelNotice sets a low priority level indicating events that are unusual,
	// but not error conditions.
	LevelNotice Level = 5

	// LevelInfo sets a very low priority level indicating normal operational
	// messages that require no action.
	LevelInfo Level = 6

	// LevelDebug sets a very low priority level indicating information useful to
	// developers for debugging the application.
	LevelDebug Level = 7
)

Syslog level message, defined in RFC 5424, section 6.2.1

type Logger

type Logger interface {
	Emerg(m ...interface{})
	Emergf(m string, a ...interface{})
	Alert(m ...interface{})
	Alertf(m string, a ...interface{})
	Crit(m ...interface{})
	Critf(m string, a ...interface{})
	Error(e error)
	Errorf(m string, a ...interface{})
	Warning(m ...interface{})
	Warningf(m string, a ...interface{})
	Notice(m ...interface{})
	Noticef(m string, a ...interface{})
	Info(m ...interface{})
	Infof(m string, a ...interface{})
	Debug(m ...interface{})
	Debugf(m string, a ...interface{})

	// SetCaller defines the number of invocations to follow-up to retrieve the
	// actual caller of the log entry. For now is only used by the package easy
	// functions.
	SetCaller(n int)
}

Logger allows logging messages in all different level types. As it is an interface it can be replaced by mocks for test purposes.

Jump to

Keyboard shortcuts

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