- Notifications
You must be signed in to change notification settings - Fork3
another GO logger. The main line is to provide a friendly and fast API to send your log wherever you want.
License
gol4ng/logger
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Gol4ng/Logger is another GO logger. The main line is to provide a friendly and fast API to send your log whenever you want.
When i start GO i searched a logger that can besimple to use,efficient,multi output,multi formats and quite easy toextend.That's why i created this logger with built-inhandlers(process a log),formatters(format log in another representation),middlewares(log modification before handler)
go get -u github.com/gol4ng/logger
package mainimport ("os""runtime""github.com/gol4ng/logger""github.com/gol4ng/logger/formatter""github.com/gol4ng/logger/handler")funcmain(){// logger will print on STDOUT with default line formatl:=logger.NewLogger(handler.Stream(os.Stdout,formatter.NewDefaultFormatter(formatter.WithContext(true))))l.Debug("Go debug information",logger.String("go_os",runtime.GOOS),logger.String("go_arch",runtime.GOARCH))// <debug> MyExample message {"go_arch":"amd64","go_os":"darwin"}l.Info("Another")//<info> Another}
This library expose some quite simple interfaces.
Simplest one
typeLogInterfaceinterface {Log(messagestring,levelLevel,field...Field)}
The friendly one
typeLoggerInterfaceinterface {LogInterfaceDebug(messagestring,field...Field)Info(messagestring,field...Field)Notice(messagestring,field...Field)Warning(messagestring,field...Field)Error(messagestring,field...Field)Critical(messagestring,field...Field)Alert(messagestring,field...Field)Emergency(messagestring,field...Field)}
Handlers are log entry processor. It received a log entry and process it in order to send log to it's destination
Available handlers:
- streamit will write formatted log in io.Writer
- socketit will write formatted log in net.Conn
- chansend all entry in provided go channel
- gelfformat to gelf and send to gelf server (TCP or UDP gzipped chunk)
- groupit will send log to all provided child handlers
- rotateit will write formatted log in file and rotate file (mode: interval/archive)
- syslogsend formatted log in syslog server
The formatter convert log entry to a string representation (text, json, gelf...)They are often inject in handler to do the conversion process
Available formatters:
- default
<info> My log message {"my_key":"my_value"}
- lineit's just a
fmt.Sprintf
facade format:%s %s %s
will produceMy log message info <my_key:my_value>
- gelfformat log entry to gelf
{"version":"1.1","host":"my_fake_hostname","level":6,"timestamp":513216000.000,"short_message":"My log message","full_message":"<info> My log message [ <my key:my_value> ]","_my_key":"my_value"}
- jsonformat log entry to json
{"Message":"My log message","Level":6,"Context":{"my_key":"my_value"}}
The middleware are handler decorator/wrapper. It will allow you to do some process around child handler
Available middleware:
- callerit will add caller file/line to context
<file:/my/example/path/file> <line:31>
- contextit permit to have a default context value useful when you want to set global context value
- errorit will print provided handler error (can be configure to silent it)
- filterit will permit to filter log entry level filter are available or you can use your own callback filter
- placeholderit will replace log message placeholder with contextual value
- recoverit will convert handler panic to error
- timestampit will add timestamp to log context
Writers are use by handler to write/send log to appropriate destination
Available writer:
- compressit will compress log to gzip/zlib
- gelf_chunkedit will chunked log entry into gelf chunk
- rotateit will write in io.Writer and rotate writer on demand
- time_rotateit's a rotate writer that rotate with
time.Ticker
benchmark
Implement all the handler
- SSE http endpoint
- websocket server
- socket server
- https://craig.is/writing/chrome-logger
- fingercross
- grpc / protobuf
- curl
- Slack
- hipchat
- amqp
- redis
- elasticsearch
- newrelic
- browser console
- couchdb
- cube
- ifttt
- InsightOps
- mandrill
- pushover
- raven
- rollbar
- sampling
- LogEntries
- ???
Implement all the formatter
- html
- proto
- slack
- flowdoc
- fluentd
- logstash
- mongodb
- wildfire
- log server with log routing
About
another GO logger. The main line is to provide a friendly and fast API to send your log wherever you want.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors4
Uh oh!
There was an error while loading.Please reload this page.