# README
log
a lite golang log library, easy to get start and no dependency.
Features
-
consolt
andfilelog
support -
WithFields
support -
lite and easy to use
Install
go get -u github.com/yeqown/log
Quick Start
There is sample code of using log
.
package main
type embed struct {
FieldA string
FieldB int
}
func main() {
// using builtin logger
log.Info(1, 2, 3, 4, 5)
log.Infof("this is format: %d", 2)
log.
WithField("key1", "value1").
WithFields(log.Fields{
"key2": "value2",
"key3": "value3",
"key4": "value4",
"key5": "value5",
"key6": "value6",
"key7": "value7",
"key8": "value8",
}).Error("test error")
// using new logger
logger, _ := log.NewLogger(
log.WithLevel(log.LevelError),
log.WithGlobalFields(log.Fields{"global_key": "global_value"}),
)
logger.Info(1, 2, 3, 4, 5)
logger.Infof("this is format: %d", 2)
logger.WithField("logger", "it's me").
WithFields(log.Fields{
"key2": "value2",
"key3": "value3",
"key4": "value4",
"key5": "value5",
"key6": "value6",
"key7": "value7",
"embed": embed{
FieldA: "aaa",
FieldB: 112091,
},
"embed_ptr": &embed{
FieldA: "aaa",
FieldB: 112091,
},
}).Error("test error")
// [Error] file="/Users/yeqown/projects/opensource/log/logger_entry.go" fn="github.com/yeqown/log.(*entry).output"
// line="109" timestamp="1596090798" formatted_time="2020-07-30T14:33:18+08:00" embed="{aaa 112091}"
// embed_ptr="&{aaa 112091}" global_key="global_value" key2="value2" logger="it's me" msg="test error"
}
Migrate
Here is a broken change from d68941c
to v1.x
. v1.x
is advised to use.
shots
Here are some shots of using example.
1. stdout shots

2. file shots
output to stdout and file both.

# Packages
No description provided by the author
# Functions
Debug .
Debugf .
DefaultContextParserFunc use default field name as output context field name.
Error .
Errorf .
Fatal .
Fatalf .
only use for test.
Info .
Infof .
NewContextParserFunc parseFunc `func(ctx context.Context) interface{}` as the primary parameter, fieldName `string` as secondary parameter.
NewLogger using os.Stdout and LevelDebug to print log.
No description provided by the author
SetLogLevel .
No description provided by the author
Warn .
Warnf .
WithContext .
WithContextParser set a custom ContextParser for parsing context.
WithCustomWriter using custom writer to log.
WithField .
WithFields .
WithFieldsSort print fields in order of fields' keys lexicographical order.
WithFileLog store log into file, if autoRotate is set, it will start a goroutine to split log file by day.
WithGlobalFields set global fields those would be logged in every log.
WithLevel setting the level, this could change dynamic.
WithReportCaller b is a switch to open print caller or not.
WithStdout output to os.Stdout also.
WithTimeFormat to output time as the layout you want.
# Constants
LevelDebug .
LevelError .
LevelFatal .
LevelInfo .
LevelWarning .
# Interfaces
ContextParser want to to parse context into `context` field and log into fields.
Formatter to format entry fields and other field.
# Type aliases
Fields to contains a batch field to log.
No description provided by the author
LoggerOption to apply single function into `lo`.