go-rethinklogger persists and bundles all your logs from stdio
and stderr
to RethinkDB.
β’ Can be used to monitor logs and analytics of your GO application remotely.
β’ It works and is compatible with literally all types of loggers. The API is exceptionally simple and you just need to do normal logging,
it automatically reads from stdio
and stderr
, persists logs for later use and echoes the same back to their respective streams.
β’ Using Go.
go get github.com/MustansirZia/go-rethinklogger
β’ Using Glide.
glide get github.com/MustansirZia/go-rethinklogger
glide up
β’ Using go-vendor.
govendor fetch github.com/MustansirZia/go-rethinklogger
// Start persisting logs. Call preferably from init.
// Start takes a rethinkDB address and the admin password
// as arguments. Don't worry though, admin user is only
// used to create the database and a user.
rethinklogger.Start("localhost:28015", "adminPassword")
fmt.Fprintln(os.Stdout, "Sample stdio log!")
fmt.Fprintln(os.Stderr, "Sample stderr log!")
...
...
// Query logs from anywhere in your application.
previousDay := time.Now().Add(0, 0, -1)
now := time.Now()
logs, err := rethinklogger.QueryLogs("localhost:28015", previousDay, now)
if err != nil {
fmt.Println(err.Error())
}
for _, log := range logs {
/*
log {
Log = "Sample stdio log!"
CreatedAtHuman = "17 Aug 17 15:04 +530"
CreatedAt = 1503162020
}
log {
Log = "Sample stderr log!"
CreatedAtHuman = "17 Aug 17 15:04 +530"
CreatedAt = 1503162020
}
*/
}
β’ This library is built over go-shipit which dispatches std logs to a io.Writer
interface. This library is basically a writer for shipit.
β’ To avoid our database from getting overwhelmed by logs, logs are first accumulated inside a buffer and then dispatched at an interval of 5 secs.
β’ Logging can also be started using StartWithBuffer
function which takes an additional buffer size argument. This is the minimum number of logs that must be accumulated inside the buffer before all the logs are dispatched to Rethink.
By default the value is 1
.
=> go-loggly - https://github.com/segmentio/go-loggly
=> Winston for nodejs - https://github.com/winstonjs/winston
See License.
Support my OSS work by buying me a coffee!