Giter VIP home page Giter VIP logo

loggly's Introduction

loggly

A Go (Golang) package for communicating with Loggly using user credentials

Setup

This package expects an environment variable called LOGGLY_TOKEN to be assigned a value corresponding to the Customer Token provided by Loggly. This can be found in the Source Setup under the Customer Tokens tab.

In order to include this package in your Go application, you must import it as follows

import loggly "github.com/jamespearly/loggly"

Initialization

A connection to Loggly must be established before messages can be sent. Your program establishes its connection by first instantiating a client. The constructor requires a string parameter used as a tag for all messages sent by your application:

client = loggly.New('MyApplication')

Sending Messages

There are two functions provided for sending messages -- Send and EchoSend. Each function sends a valid log message to Loggly, but EchoSend additionally logs the message to the local console.

Both functions require two string parameters. The first is the message level. The following is a list of valid levels accepted by Loggly (in order of decreasing severity):

"error"
"warn"
"info"
"verbose"
"debug"
"silly"

The second string parameter is the message text. The following are valid example messages:

client.Send("debug", "This is a debug message");
client.EchoSend("silly", "This is a silly message that is logged to the console");

Example Program

Here is an example Go program that opens a connection and sends various types of messages. It also shows a variety of errors:

// This package is used to test the Loggly package
package main

import (
	"fmt"
	loggly "github.com/jamespearly/loggly"
)

func main() {

	var tag string
	tag = "My-Go-Demo"

	// Instantiate the client
	client := loggly.New(tag)

	// Valid EchoSend (message echoed to console and no error returned)
	err := client.EchoSend("info", "Good morning!")
	fmt.Println("err:", err)

	// Valid Send (no error returned)
	err = client.Send("error", "Good morning! No echo.")
	fmt.Println("err:", err)

	// Invalid EchoSend -- message level error
	err = client.EchoSend("blah", "blah")
	fmt.Println("err:", err)

}

loggly's People

Contributors

jamespearly avatar jimearly avatar nullwulf 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.