Code Monkey home page Code Monkey logo

golf's Introduction

golf

GoDoc Build Status codecov.io

Golf is an MIT-licensed Go client library for servers supporting the Graylog Extended Log Format (GELF, https://www.graylog.org/resources/gelf-2/).

If you run into any issues with the library or have any feature requests, please create issues for them!

As this library is very new, the API could still change. I don't expect it to change much because I'm pretty happy with how it is now but if anyone has suggestions easier ways to use the library via API changes I would be open to it.

Test coverage is an ongoing process!

Features

  • GELF 1.1 support
  • Native Go implementation
  • Supports Logger-level and Message-level attributes

Installation

The recommended way to install is via http://gopkg.in

go get gopkg.in/aphistic/golf.v0
...
import "gopkg.in/aphistic/golf.v0"

Golf can also be installed the standard way as well

go get github.com/aphistic/golf
...
import "github.com/aphistic/golf"

Examples

For brevity a lot of error checking has been omitted from these examples, be sure you do your checks!

The standard way to implement the golf library is by creating a Client, connecting to a server and creating Loggers off that Client:

package main

import (
    "gopkg.in/aphistic/golf.v0"
)

func main() {
    c, _ := golf.NewClient()
    c.Dial("udp://192.168.30.150")

    l, _ := c.NewLogger()
    // Attributes set at the Logger level will automatically be included
    // on each message sent from that Logger.  This is helpful if there's
    // any consistent information you don't want to include every time you
    // log a message.
    l.SetAttr("facility", "golf.example")
    l.SetAttr("instance_id", 12345)

    for idx := 1; idx <= 10; idx++ {
        l.Dbgm(map[string]interface{}{
            "msg_attr1": 1234,
        }, "Test message %v", idx)
    }

    c.Close()
}

It is also possible to set a Logger as the default for the golf library so you don't need to keep track of a main Logger manually:

package main

import (
    "gopkg.in/aphistic/golf.v0"
)

func main() {
    c, _ := golf.NewClient()
    c.Dial("udp://192.168.30.150")

    l, _ := c.NewLogger()
    // Set l as the default logger
    golf.DefaultLogger(l)
    // Attributes set at the Logger level will automatically be included
    // on each message sent from that Logger.  This is helpful if there's
    // any consistent information you don't want to include every time you
    // log a message.
    l.SetAttr("facility", "golf.example")
    l.SetAttr("instance_id", 12345)

    for idx := 1; idx <= 10; idx++ {
        // Use the default logger to send the message
        golf.Dbgm(map[string]interface{}{
            "msg_attr1": 1234,
        }, "Test message %v", idx)
    }

    c.Close()
}

golf's People

Contributors

aphistic avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.