Documentation ¶
Overview ¶
Implementations for github.com/msample/log2 LogFunc API supporting syslog, fileio, JSON, logrotate, and stepping through different logging configurations at runtime in response to OS signals.
Experimental work in progress. Incomplete. Sharp edges. Limited tests
Make sure Writers created by the writer factories are thread-safe per Write() to ensure concurrent Write() calls to the same Writer will not have their output interleaved.
Note: don't do log2 logging in the factories, filterers, serializers or writers used with logfu.Config
Index ¶
- Constants
- func FileWriterFac(filepath string) func() (io.Writer, error)
- func IdentityFilter(keyvals []interface{}) ([]interface{}, error)
- func JSONSerialize(w io.Writer, kvs []interface{}) error
- func LimitWriterFac(f func() (io.Writer, error), maxSizePerWrite int) func() (io.Writer, error)
- func LogfmtSerialize(w io.Writer, kvs []interface{}) error
- func MultiWriterFac(wfs ...func() (io.Writer, error)) func() (io.Writer, error)
- func RSWriterFac(f func() (io.Writer, error)) func() (io.Writer, error)
- func StderrWriter() (io.Writer, error)
- func StdoutWriter() (io.Writer, error)
- func SyncWriterFac(f func() (io.Writer, error)) func() (io.Writer, error)
- func SyslogWriterFac() func() (io.Writer, error)
- func TCPSyslogWriterFac(addr string) func() (io.Writer, error)
- func UDPSyslogWriterFac(addr string) func() (io.Writer, error)
- type Config
- type FilterFunc
- type Filterer
- type FiltererFac
- type Fsw
- type LimitWriter
- type Mode
- type MultiWriterCloser
- type RSWriter
- type Serializer
- type SerializerFac
- type SerializerFunc
- type WriterFac
Constants ¶
const (
SyslogPriority = syslog.LOG_INFO | syslog.LOG_LOCAL2 // all syslog usage gets this setup
)
Variables ¶
This section is empty.
Functions ¶
func FileWriterFac ¶
Returns a sync writer that append to the given file, creating the file if necessary. FIXME expose file mode as param
func IdentityFilter ¶
func IdentityFilter(keyvals []interface{}) ([]interface{}, error)
func JSONSerialize ¶
JSONSerialize is the JSON serializer implementation
func LimitWriterFac ¶
func LogfmtSerialize ¶
LogfmtSerialize is the log fmt serializer implementation
func MultiWriterFac ¶
func RSWriterFac ¶
Wraps the given Writer to an add an ascii RS (record separator) before each write and an LF after. Useful for producing json-seq when each individual write to the wrapped writer is a JSON value.
func SyncWriterFac ¶
Returns a wrapper version of the given Writer that only permits one write call at a time.
func SyslogWriterFac ¶
Returns a WriterFac that returns a thread-safe local syslog writer. Uses SyslogPriority as the priority and "" as the tag (FIXME - expose syslog tag as param?)
func TCPSyslogWriterFac ¶
Returns a WriterFac returns a syslog TCP Writer to the given address. Addr format is as per log/syslog.Dial().
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
func New ¶
func New(filtererFacs []FiltererFac, serializerFacs []SerializerFac, writerFacs []WriterFac, modes []Mode, recreateOnShift bool) (*Config, error)
New creates log configuration modes that can be stepped through to set the log2.Info, Debug etc funcs. Change modes using the NextMode, PrevMode and ChangeToMode methods. The Modes param defines the allowed configuration modes only one of which is in effect at a given time. Each mode references a specific combination of filterer, serializer and writer factories to be used to build the log levels. Filterers are given the raw log parameters and may add or remove keyavls, the resulting keyvals, if any, are serailized by the serializer to the writer.
New returns a Config without applying any mode. Use ChangeToMode to set the first logging mode.
Look at the example in logfu_test.go, this is a bit clunky
func (*Config) ChangeToMode ¶
ChangeToMode changes to the given mode index. Does nothing if already in that mode unless force is true.
Use this with force==true after first creating a Config to initialize the first mode you want.
func (*Config) HomeMode ¶
HomeMode loads modes[0] of the config. If already in home mode it does nothing
func (*Config) ReloadMode ¶
Recreate the current log config by re-creating the filters, serializers and writers and re-swapping them into their log2 levels (e.g. in response to HUP)
func (*Config) SignalControlOff ¶
func (o *Config) SignalControlOff()
SignalControlOff ceases changing log modes in response to signals
func (*Config) SignalControlOn ¶
func (o *Config) SignalControlOn()
SignalControlOn makes it so SIG_USR1 calls NextMode, SIG_USR2 calls HomeMode, and SIG_HUP reloads the current log mode.
type FilterFunc ¶
type FilterFunc func([]interface{}) ([]interface{}, error)
func (FilterFunc) Filter ¶
func (o FilterFunc) Filter(keyvals []interface{}) ([]interface{}, error)
type Filterer ¶
type Filterer interface {
Filter(inKeyvals []interface{}) (outKeyvals []interface{}, err error)
}
Filterer can add context to your log statements such as timestamp, or to mutate or remove fields from the Log call and upstream filters. If the return value from the Filter is zero length, the Log() call returns at that point (nothing is logged).
func IdentityFilterFac ¶
type FiltererFac ¶
type Fsw ¶
Fsw holds the FiltererFac, SerializerFac and WriterFac references that will be used together to produce log output. Filter->Serialize->Write.
type LimitWriter ¶
type LimitWriter struct {
// contains filtered or unexported fields
}
type Mode ¶
Mode defines a logging configuration by specifying the log levels that are not No-Ops in terms of a set of filter-serializer-writer tuples. Each log() call to a level has its keyvals fed through each filterer-serializer-writer tuple for that level (if any)
type MultiWriterCloser ¶
type MultiWriterCloser struct { io.Writer // wraps all writers for Write // contains filtered or unexported fields }
func NewMultiWriterCloser ¶
func NewMultiWriterCloser(w ...io.Writer) *MultiWriterCloser
func (*MultiWriterCloser) Close ¶
func (o *MultiWriterCloser) Close() error
type Serializer ¶
Serializer converts a series of kv pairs to a single []byte and writes it to the given Writer in a single Write call. Use a MultiWriter to avoid unecessary re-serialization.
func JSONSerializerFac ¶
func JSONSerializerFac() (Serializer, error)
JSONSerializerFac is a factory for JSON Serializers
func LogfmtSerializerFac ¶
func LogfmtSerializerFac() (Serializer, error)
LogfmtSerializerFac is a factory for JSON Serializers
type SerializerFac ¶
type SerializerFac func() (Serializer, error)
type SerializerFunc ¶
SerializerFunc type allows you convert a serializer function to a Serializer interface
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
lfuex1
lfuex1 uses a canned config and pflag commmand line setup with signal handling on.
|
lfuex1 uses a canned config and pflag commmand line setup with signal handling on. |
lib
|
|
lfucfg
lfucfg provides convenient functions to build and initialize common logging configurations.
|
lfucfg provides convenient functions to build and initialize common logging configurations. |