Documentation ¶
Index ¶
- func NewWriterFn(fnWrite FnWrite, fnClose FnClose) *writerFn
- type ControlFn
- type Discard
- type Entry
- func (e *Entry) Bool(key string, val bool) *Entry
- func (e *Entry) Err(val error) *Entry
- func (e *Entry) Ext(fn EntryFn) *Entry
- func (e *Entry) Float(key string, val float64) *Entry
- func (e *Entry) Int(key string, val int) *Entry
- func (e *Entry) Int64(key string, val int64) *Entry
- func (e *Entry) Str(key string, val string) *Entry
- func (e *Entry) Write(msg ...string)
- type EntryFn
- type Err
- type Flag
- type FnClose
- type FnWrite
- type Formatter
- type KeyValue
- type KvType
- type Level
- type Logger
- func (l Logger) Close() error
- func (l *Logger) Debug(tags ...Tag) *Entry
- func (l *Logger) Error(tags ...Tag) *Entry
- func (l Logger) Ext(fn LoggerFn) Logger
- func (l *Logger) Fatal(tags ...Tag) *Entry
- func (l *Logger) Info(tags ...Tag) *Entry
- func (l *Logger) Log(level Level, tag Tag) *Entry
- func (l Logger) NewTag(name string) Tag
- func (l Logger) Output() Writer
- func (l Logger) SetFormatter(f Formatter) Logger
- func (l Logger) SetOutput(w io.Writer) Logger
- func (l *Logger) Trace(tags ...Tag) *Entry
- func (l *Logger) Warn(tags ...Tag) *Entry
- type LoggerFn
- type Tag
- type TagBucket
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewWriterFn ¶ added in v0.8.1
Types ¶
type ControlFn ¶ added in v0.5.0
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
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) Float ¶ added in v0.6.0
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
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
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).
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 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 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
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 ¶
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) Ext ¶ added in v0.6.2
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) Log ¶ added in v0.4.0
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
NewTag will create a new tag Using value receiver as this won't be used many times anyway
func (Logger) SetFormatter ¶ added in v0.4.0
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 ¶
SetOutput will set the output writer to be used in the logger. If nil is given, it will discard the output.
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.
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) AppendTagForJSON ¶ added in v0.6.0
func (*TagBucket) MustGetTag ¶ added in v0.5.0
MustGetTag returns a tag if found. If not, create a new tag.