driver

package
v2.0.3+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2020 License: BSD-2-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArgsToMap

func ArgsToMap(args []interface{}) (map[string]interface{}, []string, error)

ArgsToMap turn args []interface{} to map dictionary and strings array index. Return: map[string]interface{}, []string, error

func ArgsToString

func ArgsToString(arg0 interface{}, args ...interface{}) (s string)

ArgsToString builds a format string by the arguments Return a format string which depends on the first argument:

  • arg[0] is a string When given a string as the first argument, this behaves like fmt.Sprintf the first argument is interpreted as a format for the latter arguments.
  • arg[0] is a func()string When given a closure of type func()string, this logs the string returned by the closure if it will be logged. The closure runs at most one time.
  • arg[0] is interface{} When given anything else, the return message will be each of the arguments formatted with %v and separated by spaces (ala Sprint).

func Register

func Register(name string, app Appender)

Register is called by 3rd appender's init() function to register the new appender interface.

Types

type Appender

type Appender interface {
	// Open opens and creates the appender.
	Open(dsn string, args ...interface{}) (Appender, error)

	// Set sets name-value option. Checkable
	Set(name string, value interface{}) error

	// Enabled returns true if the given recorder should be encoded
	// and written bytes after.
	//
	// Enabled can write the recorder directly with owner format,
	// and then return false.
	Enabled(*Recorder) bool

	// Write will be called to write the log bytes.
	Write([]byte) (int, error)

	// Close should clean up anything lingering about the Appender, as it is called before
	// the Appender is removed.  Write should not be called after Close.
	Close()
}

Appender is an interface for anything that should be able to write logs

func NewNopAppender

func NewNopAppender() Appender

NewNopAppender returns a no-op Layout.

func Open

func Open(name string, dsn string, args ...interface{}) (Appender, error)

Open opens and creates the named appender.

Return new appender and error

type Enabler

type Enabler interface {
	Enabled(*Recorder) bool
}

Enabler interface implemented to provide customized logging recorder filtering.

func AcceptAll

func AcceptAll() Enabler

AcceptAll return Enabler which accepts all logging recorder.

func AtAbove

func AtAbove(n int) Enabler

AtAbove return a very simple Enabler which accepts logging recorder's level at or above the value of the n level.

func DenyAll

func DenyAll() Enabler

DenyAll return Enabler which drops all logging recorder.

func MatchLevel

func MatchLevel(n int) Enabler

MatchLevel return a very simple Enabler which accepts logging recorder's level equals the value of the n level.

func RangeLevel

func RangeLevel(min, max int) Enabler

RangeLevel return a very simple Enabler which accepts logging recorder's level match the range.

type Filter

type Filter struct {
	Name string
	Enabler
	Layout
	Apps []Appender
}

Filter contains:

  • Enabler, the Enabler interface for filter log Recorder
  • Layout, the Layout interface for encoding log Recorder
  • Apps, the slice of the Appender interface

func (*Filter) Close

func (f *Filter) Close()

Close closes all log appenders in preparation for exiting the program. Calling this is not really imperative, unless you want to guarantee that all log messages are written.

Notice: Close() removes all appenders from the filter.

func (*Filter) Dispatch

func (f *Filter) Dispatch(r *Recorder)

Dispatch filters, encodes a log recorder to bytes, and writes it to all appenders.

  • Enabler.Enabled, filter log Recorder.
  • Layout.Encode, encode log Recorder to bytes.Buffer.
  • Apps[i].Enabled, filter log recorder by appender.
  • Apps[i].Write, append with log recorder encoded bytes.

type Layout

type Layout interface {
	// Set sets name-value option. Checkable.
	Set(name string, v interface{}) error

	// Encode encodes a log Recorder to bytes.
	Encode(out *bytes.Buffer, r *Recorder) int
}

Layout is is an interface for formatting log record

func NewNopLayout

func NewNopLayout() Layout

NewNopLayout returns a no-op Layout.

type Recorder

type Recorder struct {
	Prefix  string    // The message prefix
	Source  string    // The message source
	Line    int       // The source line
	Level   int       // The log level
	Message string    // The log message
	Created time.Time // The time at which the log message was created (nanoseconds)

	Data  map[string]interface{} // Contains all the fields set by the user.
	Index []string
}

Recorder contains all of the pertinent information for each message It is the final or intermediate logging entry also. It contains all the fields passed with With(key, value, ...). It's finally logged when Trace, Debug, Info, Warn, Error, Fatal or Panic is called on it.

func (*Recorder) With

func (r *Recorder) With(args ...interface{}) *Recorder

With sets name-value pairs to the log record.

func (*Recorder) WithMore

func (r *Recorder) WithMore(args ...interface{}) *Recorder

WithMore appends name-value pairs to the log record.

Jump to

Keyboard shortcuts

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