golog: github.com/moovweb/golog Index | Files | Directories

package golog

import "github.com/moovweb/golog"

Log Processor for outputting into the console.

Log Processor for outputting into a file. Currently we do not support rolling logs, but this could be fixed by simply implementing a new io.Writer object for files which will perform the rolling and use that writer in here instead of os.OpenFile(...)

The golog package is a logging framework for the Go language based on the go routine and channel features of the language. In essence, log messages sent to a logger are sent through a global channel where a go routine listens to and services each log write serially.

As of right now, all messages are sent through a single logger channel, guranteeing serialization of log messages. In the future, golog will switch to the model of having a channel and go routine per resource (such as file, network, console, etc...) so that writes to any single resource are serialized, but writes to different resources can be parallelized.

Index

Package Files

console.go dispatch.go file.go golog.go processor.go syslog.go udp.go

func DialSyslog Uses

func DialSyslog(network, raddr string) (sock io.WriteCloser, err error)

func DialUdp Uses

func DialUdp(host string) (sock io.WriteCloser, err error)

func FlushLogsAndDie Uses

func FlushLogsAndDie()

type DefaultProcessor Uses

type DefaultProcessor struct {
    Dispatcher *LogDispatcher // Dispatcher used to send messages to the channel
    TimeFormat string         // Format string for time, if blank, we use a default.
    Verbose    bool
    // contains filtered or unexported fields
}

func (*DefaultProcessor) Close Uses

func (df *DefaultProcessor) Close() error

func (*DefaultProcessor) GetPriority Uses

func (df *DefaultProcessor) GetPriority() Priority

func (*DefaultProcessor) Process Uses

func (df *DefaultProcessor) Process(entry *LogEntry)

func (*DefaultProcessor) SetPriority Uses

func (df *DefaultProcessor) SetPriority(p Priority)

Atomically set the new priority. All accesses to priority need to be through GetPriority in order to maintain thread safety.

func (*DefaultProcessor) SetTimeFormat Uses

func (df *DefaultProcessor) SetTimeFormat(timeFormat string)

type Facility Uses

type Facility int

Syslog facilities to log to. We only list the LOCAL set as others are reserved for specific purposes.

const (
    LOCAL0 Facility = iota + 16
    LOCAL1
    LOCAL2
    LOCAL3
    LOCAL4
    LOCAL5
    LOCAL6
    LOCAL7
)

func SyslogFacilities Uses

func SyslogFacilities() []Facility

type LogDispatcher Uses

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

**************************************************************************** The LogDispatcher will take incoming log messages, create LogMsg objects, and send them through the channel that it is associated with.

func NewLogDispatcher Uses

func NewLogDispatcher(writer io.WriteCloser) *LogDispatcher

Initializers of LogDispatcher

func (*LogDispatcher) Close Uses

func (lw *LogDispatcher) Close() error

func (*LogDispatcher) Send Uses

func (lw *LogDispatcher) Send(message string)

type LogEntry Uses

type LogEntry struct {
    Prefix   string    // Prefix to prepend to the log message.
    Priority Priority  // Priority of the log message.
    Msg      string    // The actual message payload
    Created  time.Time // Time this message was created.
}

Storage object used to pass the log data over to the Processor.

type LogMsg Uses

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

Object which is sent through the log channel

type LogProcessor Uses

type LogProcessor interface {
    GetPriority() Priority
    SetPriority(Priority)
    Process(*LogEntry)
    Close() error
    SetTimeFormat(string)
}

*************************************************************************** LogProcessor interface defines the method that we expect all LogProcessors to have. For most intents and purposes, a DefaultProcessor should suffice, however if special formatting is required, a new Processor could be made (see syslog.go).

The LogProcessor also offers the ability to change its default Priority level at runtime using the SetPriority(...) method. Implementing Processors need to make sure that SetPriority and GetPriority are thread safe. Use the DefaultProcessor as an example.

func NewConsoleProcessor Uses

func NewConsoleProcessor(priority Priority, verbose bool) LogProcessor

func NewFileProcessor Uses

func NewFileProcessor(priority Priority, filename string) (LogProcessor, error)

func NewProcessor Uses

func NewProcessor(priority Priority, dispatcher *LogDispatcher, verbose bool) LogProcessor

Initializers for LogProcessor

func NewProcessorFromWriter Uses

func NewProcessorFromWriter(priority Priority, writer io.WriteCloser, verbose bool) LogProcessor

func NewProcessorWithTimeFormat Uses

func NewProcessorWithTimeFormat(priority Priority, dispatcher *LogDispatcher, format string) LogProcessor

func NewSyslogProcessor Uses

func NewSyslogProcessor(f Facility, p Priority) (LogProcessor, error)

func NewSyslogProcessorAt Uses

func NewSyslogProcessorAt(network, addy string, f Facility, p Priority) (LogProcessor, error)

Initializer for the SyslogProcessor

func NewUdpProcessor Uses

func NewUdpProcessor(p Priority) (LogProcessor, error)

func NewUdpProcessorAt Uses

func NewUdpProcessorAt(host string, p Priority) (LogProcessor, error)

type Logger Uses

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

**************************************************************************** The actual Logger structure, methods, and components. The current Logger is implemented by holding a map of LogProcessors. A new Logger can be created by calling the NewLogger methods further below. A Logger will be initialized with zero processors to begin with, and thus, will need to have LogProcessors added to it with AddProcessor before it can begin logging.

func NewLogger Uses

func NewLogger(prefix string) *Logger

Create a new empty Logger with the given prefix. The prefix will be prepended to every log message unless LogP(...) is used, in which case, the prefix supplied by the 'prefix' parameter will be used instead.

func (*Logger) AddProcessor Uses

func (dl *Logger) AddProcessor(name string, processor LogProcessor)

Add processors to this logger with the given name. Names need to be unique against all other processors. If a name conflict arises, we simply override the old processor with the same name with the new one.

func (*Logger) Alertf Uses

func (dl *Logger) Alertf(format string, args ...interface{})

func (*Logger) Close Uses

func (dl *Logger) Close()

func (*Logger) Criticalf Uses

func (dl *Logger) Criticalf(format string, args ...interface{})

func (*Logger) Debugf Uses

func (dl *Logger) Debugf(format string, args ...interface{})

func (*Logger) DisableProcessor Uses

func (dl *Logger) DisableProcessor(name string)

func (*Logger) Emergencyf Uses

func (dl *Logger) Emergencyf(format string, args ...interface{})

func (*Logger) Errorf Uses

func (dl *Logger) Errorf(format string, args ...interface{})

func (*Logger) GetMaxPriority Uses

func (dl *Logger) GetMaxPriority() Priority

func (*Logger) GetPriorities Uses

func (dl *Logger) GetPriorities() map[string]Priority

func (*Logger) GetPriority Uses

func (dl *Logger) GetPriority(procName string) (Priority, error)

func (*Logger) Infof Uses

func (dl *Logger) Infof(format string, args ...interface{})

func (*Logger) Logf Uses

func (dl *Logger) Logf(p Priority, format string, args ...interface{})

func (*Logger) Noticef Uses

func (dl *Logger) Noticef(format string, args ...interface{})

func (*Logger) Plogf Uses

func (dl *Logger) Plogf(priority Priority, prefix string, format string, args ...interface{})

Begin Logging interface. The following methods are used for logging messages to whatever processors this logger is associated with.

func (*Logger) SetPrefix Uses

func (dl *Logger) SetPrefix(newPrefix string)

func (*Logger) SetPriority Uses

func (dl *Logger) SetPriority(procName string, newPriority Priority) error

Set/Get the priority of the Processor with the given name. If no processor with the given name exists, we return an error.

func (*Logger) Warningf Uses

func (dl *Logger) Warningf(format string, args ...interface{})

type Priority Uses

type Priority int

**************************************************************************** Log Priority used to filter messages sent to the loggers.

const (

    // Using syslog standard priorities.
    // From /usr/include/sys/syslog.h.
    // These are the same on Linux, BSD, and OS X.
    LOG_EMERG Priority
    LOG_ALERT
    LOG_CRIT
    LOG_ERR
    LOG_WARNING
    LOG_NOTICE
    LOG_INFO
    LOG_DEBUG
)

func BoundPriority Uses

func BoundPriority(priority Priority) Priority

If a priority is out of bounds given any input, we'll simply truncate it to the closest valid priority.

func ParsePriority Uses

func ParsePriority(p string) Priority

func Priorities Uses

func Priorities() []Priority

func (Priority) ShortString Uses

func (p Priority) ShortString() string

func (Priority) String Uses

func (p Priority) String() string

type SyslogProcessor Uses

type SyslogProcessor struct {
    *DefaultProcessor
    // contains filtered or unexported fields
}

**************************************************************************** The SyslogProcessor implements the LogProcessor interface. It requires special formatting, thus why the DefaultProcessor could not be used. It also needs to keep track of which facility we're logging to as we can have multiple sysloggers logging to different facilities.

func (*SyslogProcessor) Process Uses

func (su *SyslogProcessor) Process(entry *LogEntry)

type SyslogWriter Uses

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

func (*SyslogWriter) Close Uses

func (sw *SyslogWriter) Close() (err error)

func (*SyslogWriter) Write Uses

func (sw *SyslogWriter) Write(data []byte) (n int, err error)

type UdpProcessor Uses

type UdpProcessor struct {
    *DefaultProcessor
}

func (*UdpProcessor) Process Uses

func (np *UdpProcessor) Process(entry *LogEntry)

type UdpWriter Uses

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

func (*UdpWriter) Close Uses

func (nw *UdpWriter) Close() error

func (*UdpWriter) Write Uses

func (nw *UdpWriter) Write(data []byte) (n int, err error)

Directories

PathSynopsis
bstormThis go file was written to test the latency on the user side when writing a lot of logs, or in other words, if I want to log something, what is the average time I'm going to wait on the call to log(...).

Package golog imports 11 packages (graph) and is imported by 7 packages. Updated 2018-06-05. Refresh now. Tools for package owners.