alog

package module
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2021 License: MIT Imports: 5 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewWriterFn added in v0.8.1

func NewWriterFn(fnWrite FnWrite, fnClose FnClose) *writerFn

Types

type ControlFn added in v0.5.0

type ControlFn func(Level, Tag) bool

ControlFn is used to trigger whether log or not in control. Once ControlFn is set, level/tag conditions will be ignored.

type Discard added in v0.7.6

type Discard struct{}

devNull is a type for discard

func (Discard) Close added in v0.8.0

func (Discard) Close() error

Close to meet alog.Writer interface

func (Discard) Write added in v0.7.6

func (Discard) Write([]byte) (int, error)

Write discards everything

func (Discard) WriteLt added in v0.8.0

func (Discard) WriteLt([]byte, Level, Tag) (int, error)

WriteLt is for Writer compatible; discards everything

type Entry added in v0.6.0

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

Entry is a log Entry will be used with a entryPool to reuse the resource. Entry is 120 bytes, use pointer.

func (*Entry) Bool added in v0.6.0

func (e *Entry) Bool(key string, val bool) *Entry

Bool adds KeyValue of boolean into kvs slice.

func (*Entry) Err added in v0.6.0

func (e *Entry) Err(val error) *Entry

Err adds KeyValue for error item.

func (*Entry) Ext added in v0.6.2

func (e *Entry) Ext(fn EntryFn) *Entry

Ext will take EntryFn and add an entry to it.

func (*Entry) Float added in v0.6.0

func (e *Entry) Float(key string, val float64) *Entry

Float adds KeyValue of float64 into kvs slice. To minimize the size of Entry, alog only supports float64.

func (*Entry) Int added in v0.6.0

func (e *Entry) Int(key string, val int) *Entry

Int adds KeyValue item for integer. This will convert int to int64. As both int and int64 are widely used, Alog has both Int and Int64 but they share same kind (Vint).

func (*Entry) Int64 added in v0.6.0

func (e *Entry) Int64(key string, val int64) *Entry

Int64 adds KeyValue item for 64 bit integer. As both int and int64 are widely used, Alog has both Int and Int64 but they share same kind (Vint).

func (*Entry) Str added in v0.6.0

func (e *Entry) Str(key string, val string) *Entry

Str adds KeyValue item of a string into kvs slice.

func (*Entry) Write added in v0.6.0

func (e *Entry) Write(msg ...string)

Writes will finalize the log message, format it, and write it to writer. Besides *logger.getEntry(), this is the only other method which isn't inline-able.

type EntryFn added in v0.6.2

type EntryFn func(*Entry) *Entry

EntryFn will

type Err added in v0.8.0

type Err string

func (Err) Error added in v0.8.0

func (e Err) Error() string

type Flag added in v0.6.0

type Flag uint32

Flag a bit-formatFlag formatFlag options that is used for variety of configuration.

const (
	WithLevel      Flag = 1 << iota // WithLevel show level in the log messsage.
	WithTag                         // WithTag will show tags
	WithDate                        // WithDate will show both CCYY and MMDD
	WithDay                         // WithDay will show 0-6 for JSON or (Sun-Mon)
	WithTime                        // WithTime will show HHMMSS
	WithTimeMs                      // WithTimeMs will show time + millisecond --> JSON: HHMMSS000, Text: HHMMSS,000
	WithUTC                         // WithUTC will show UTC time formats
	WithUnixTime                    // WithUnixTime will show unix time
	WithUnixTimeMs                  // WithUnixTimeMs will show unix time with millisecond

	// UseDefault holds default output format when no option is given.
	WithDefault = WithTime | WithDate | WithLevel | WithTag
)

Flag const

type FnClose added in v0.8.1

type FnClose func() error

type FnWrite added in v0.8.1

type FnWrite func(b []byte, level Level, tag Tag) (int, error)

type Formatter added in v0.5.0

type Formatter interface {
	// Init will initialize or update the formatter setting.
	// This will be run by Alog when used.
	//Init(writer io.Writer, format Flag, tagBucket *TagBucket)
	Init(writer Writer, format Flag, tagBucket *TagBucket)

	// Begin will be used for formats requiring prefix such as `{` in JSON.
	Begin([]byte) []byte

	// AddTime will add time to buffer.
	AddTime([]byte) []byte

	// AddLevel will add level to buffer.
	AddLevel([]byte, Level) []byte

	// AddTag will add a tag to buffer.
	AddTag([]byte, Tag) []byte

	// AddMsg will add default messages to buffer.
	AddMsg([]byte, string) []byte

	// AddKVs will add key value items to buffer
	AddKVs([]byte, []KeyValue) []byte

	// End will be used as suffix such as `}` and/or newline in JSON.
	End([]byte) []byte

	// Write will let the formatter write the buffer.
	// Depend on the setting of formatter, this can be
	// totally different than the writer than the logger's.
	// Using Write, AddLevel (and AddTag),
	// this Formatter interface will be used to create
	// multi output logger such as for a syslog.
	Write([]byte, Level, Tag) (int, error)

	// Close will, if applicable, close the writer.
	Close() error
}

Formatter is an interface for a combination of formatter and writer.

type KeyValue added in v0.6.0

type KeyValue struct {
	Key   string
	Vtype KvType
	Vint  int64
	Vf64  float64
	Vstr  string
	Vbool bool
	Verr  error
}

KeyValue holds Key and value info

type KvType added in v0.7.7

type KvType uint8

KvType hold diff

const (
	KvInt     KvType = iota + 1 // KvInt indiciates int64 type KeyValue
	KvFloat64                   // KvFloat64 indicates float64 type KeyValue
	KvString                    // KvString indicates string type KeyValue
	KvBool                      // KvBool indicates bool type KeyValue
	KvError                     // KvError indicates error type KeyValue
)

KeyValue const

type Level added in v0.3.2

type Level uint8

level is a flag for logging level

const (
	TraceLevel Level = iota + 1 // TraceLevel shows trace level, the most detailed debugging level.
	DebugLevel                  // DebugLevel shows debug level or higher
	InfoLevel                   // InfoLevel shows information level or higher
	WarnLevel                   // WarnLevel is for a normal but a significant condition
	ErrorLevel                  // ErrorLevel shows error level or higher
	FatalLevel                  // FatalLevel shows fatal level or higher. This does not exit the process
)

Level const

func (Level) Name added in v0.6.0

func (l Level) Name() string

Name will print level'Vstr full name

func (Level) NameShort added in v0.6.0

func (l Level) NameShort() string

NameShort will print level'Vstr abbreviated name

type Logger

type Logger struct {
	Control control // 32 bytes
	Flag    Flag
	// contains filtered or unexported fields
}

Logger is a main struct for Alog. This struct is 80 bytes.

func New

func New(w io.Writer) Logger

New will return a Alog logger pointer with default values. This function will take an io.Writer and convert it to Writer. A user's custom Writer will let the user steer more control.

func (Logger) Close added in v0.1.6

func (l Logger) Close() error

Close will close io.Writer if applicable

func (*Logger) Debug

func (l *Logger) Debug(tags ...Tag) *Entry

Debug takes a tag (0 for no tag) and returns an Entry point.

func (*Logger) Error

func (l *Logger) Error(tags ...Tag) *Entry

Error takes a tag (0 for no tag) and returns an Entry point.

func (Logger) Ext added in v0.6.2

func (l Logger) Ext(fn LoggerFn) Logger

Ext will run functions that will act as a quick macro like settings for the logger. See <https://github.com/gonyyi/alog/ext> for examples.

func (*Logger) Fatal

func (l *Logger) Fatal(tags ...Tag) *Entry

Fatal takes a tag (0 for no tag) and returns an Entry point.

func (*Logger) Info

func (l *Logger) Info(tags ...Tag) *Entry

Info takes a tag (0 for no tag) and returns an Entry point.

func (*Logger) Log added in v0.4.0

func (l *Logger) Log(level Level, tag Tag) *Entry

Log will log the item. This is to be used when alog is embedded in other struct.

func (Logger) NewTag added in v0.3.0

func (l Logger) NewTag(name string) Tag

NewTag will create a new tag Using value receiver as this won't be used many times anyway

func (Logger) Output added in v0.3.0

func (l Logger) Output() Writer

Output will return currently used default writer.

func (Logger) SetFormatter added in v0.4.0

func (l Logger) SetFormatter(f Formatter) Logger

SetFormatter will take an object with Formatter interface For Alog, nil can be used to disable the override. See: <https://github.com/gonyyi/alog/ext> for examples.

func (Logger) SetOutput

func (l Logger) SetOutput(w io.Writer) Logger

SetOutput will set the output writer to be used in the logger. If nil is given, it will discard the output.

func (*Logger) Trace

func (l *Logger) Trace(tags ...Tag) *Entry

Trace takes a tag (0 for no tag) and returns an Entry point.

func (*Logger) Warn

func (l *Logger) Warn(tags ...Tag) *Entry

Warn takes a tag (0 for no tag) and returns an Entry point.

type LoggerFn added in v0.6.2

type LoggerFn func(Logger) Logger

LoggerFn will be used to manipulate multiple functionality at once.

type Tag added in v0.3.0

type Tag uint64

tag is a bit-formatFlag used to show only necessary part of process to show in the log. For instance, if there'Vstr an web service, there can be different tag such as UI, HTTP request, HTTP response, etc. By alConf a tag for each log using `Print` or `Printf`, a user can only print certain tag of log messages for better debugging.

func (Tag) Has added in v0.4.1

func (t Tag) Has(tag Tag) bool

func (Tag) Sub added in v0.8.2

func (t Tag) Sub(tag Tag) Tag

type TagBucket added in v0.5.0

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

TagBucket can issue a tag and also holds the total number of tags issued AND also names given to each tag. Not that TagBucket is not using any mutex as it is designed to be set at the very beginning of the process. Also, the maximum number of tag can be issue is limited to 63.

func (*TagBucket) AppendTag added in v0.6.0

func (t *TagBucket) AppendTag(dst []byte, tag Tag) []byte

func (*TagBucket) AppendTagForJSON added in v0.6.0

func (t *TagBucket) AppendTagForJSON(dst []byte, tag Tag) []byte

func (TagBucket) GetTag added in v0.5.0

func (t TagBucket) GetTag(name string) (tag Tag, ok bool)

GetTag returns a tag if found

func (*TagBucket) MustGetTag added in v0.5.0

func (t *TagBucket) MustGetTag(name string) Tag

MustGetTag returns a tag if found. If not, create a new tag.

type Writer added in v0.8.0

type Writer interface {
	WriteLt([]byte, Level, Tag) (int, error)
	Close() error
}

Writer is a Level and Tag writer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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