rethinklogger

package module
Version: v0.0.0-...-685e688 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2018 License: MIT Imports: 5 Imported by: 0

README

go-rethinklogger

Documentation Go Report Card GitHub tag MIT Licence

go-rethinklogger persists and bundles all your logs from stdio and stderr to RethinkDB.

RethinkDB Logo

• 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.


Installation.

• 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


Usage.




    // 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
            }
        */

    }




Sidenotes.

• 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.


Inspiration.

=> go-loggly - https://github.com/segmentio/go-loggly

=> Winston for nodejs - https://github.com/winstonjs/winston


License.

See License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Start

func Start(dbAddress, adminPassword string) error

Start - Clients call this to start the persisting of logs.

func StartWithBuffer

func StartWithBuffer(dbAddress, adminPassword string, bufferSize int) error

StartWithBuffer - Clients call this to start the persisting of logs with a customizable buffer size.

Types

type RethinkLog

type RethinkLog struct {
	Log            string `gorethink:"Log,omitempty"`
	CreatedAt      int64  `gorethink:"CreatedAt,omitempty"`
	CreatedAtHuman string `gorethink:"CreatedAtHuman,omitempty"`
}

RethinkLog - struct to a hold a single rethink log.

func QueryLogs

func QueryLogs(dbAddress string, from, to time.Time) ([]RethinkLog, error)

QueryLogs - Only exported function apart from Start() and StartWithBuffer(). Used to Query past logs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL