gostk: github.com/registrobr/gostk/log Index | Files

package log

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

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

Index

Package Files

log.go

Variables

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.

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

    // LocalLogger is the fallback log used when the remote logger isn't
    // available.
    LocalLogger *log.Logger
)
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.

func Alert Uses

func Alert(a ...interface{})

Alert log an emergency message

func Alertf Uses

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

Alertf log an emergency message with arguments

func Crit Uses

func Crit(a ...interface{})

Crit log an emergency message

func Critf Uses

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

Critf log an emergency message with arguments

func Debug Uses

func Debug(a ...interface{})

Debug log an emergency message

func Debugf Uses

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

Debugf log an emergency message with arguments

func Dial Uses

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 Uses

func Emerg(a ...interface{})

Emerg log an emergency message

func Emergf Uses

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

Emergf log an emergency message with arguments

func Error Uses

func Error(err error)

Error log an emergency message

func Errorf Uses

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

Errorf log an emergency message with arguments

func Info Uses

func Info(a ...interface{})

Info log an emergency message

func Infof Uses

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

Infof log an emergency message with arguments

func Notice Uses

func Notice(a ...interface{})

Notice log an emergency message

func Noticef Uses

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

Noticef log an emergency message with arguments

func Warning Uses

func Warning(a ...interface{})

Warning log an emergency message

func Warningf Uses

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

Warningf log an emergency message with arguments

type Level Uses

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 Uses

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.

Package log imports 9 packages (graph) and is imported by 2 packages. Updated 2016-11-06. Refresh now. Tools for package owners.