GithubHelp home page GithubHelp logo

mx-psi / logzio-go Goto Github PK

View Code? Open in Web Editor NEW

This project forked from logzio/logzio-go

0.0 1.0 0.0 1.94 MB

Low level go client for Logz

Home Page: https://logz.io/

License: Apache License 2.0

Go 100.00%

logzio-go's Introduction

Logzio Golang API client

Sends logs to logz.io over HTTP. It is a low level lib that can to be integrated with other logging libs.

Prerequisites

go 1.x

Installation

$ go get -u github.com/logzio/logzio-go

Logzio golang api client offers two queue implementations that you can use:

Disk queue

Logzio go client uses goleveldb and goqueue as a persistent storage. Every 5 seconds logs are sent to logz.io (if any are available)

In memory queue

You can see the logzio go client queue implementation in inMemoryQueue.go file. The in memory queue is initialized with 500k log count limit and 20mb capacity by default. You can use the SetinMemoryCapacity() and SetlogCountLimit() functions to override default settings.

Quick Start

Disk queue

package main

import (
  "fmt"
  "github.com/logzio/logzio-go"
  "os"
  "time"
)

func main() {
  l, err := logzio.New(
  		"fake-token",
	  logzio.SetDebug(os.Stderr),
	  logzio.SetUrl("http://localhost:12345"),
	  logzio.SetDrainDuration(time.Minute*10),
	  logzio.SetTempDirectory("myQueue"),
	  logzio.SetDrainDiskThreshold(99),
  	) // token is required
  if err != nil {
    panic(err)
  }
  msg := fmt.Sprintf("{ \"%s\": \"%s\"}", "message", time.Now().UnixNano())

  err = l.Send([]byte(msg))
  if err != nil {
     panic(err)
  }

  l.Stop() //logs are buffered on disk. Stop will drain the buffer
}

In memory queue

package main

import (
  "fmt"
  "github.com/logzio/logzio-go"
  "os"
  "time"
)

func main() {
  l, err := logzio.New(
  		"fake-token",
	  logzio.SetDebug(os.Stderr),
	  logzio.SetUrl("http://localhost:12345"),
	  logzio.SetInMemoryQueue(true),
	  logzio.SetinMemoryCapacity(24000000),
	  logzio.SetlogCountLimit(6000000),
  	) // token is required
  if err != nil {
    panic(err)
  }
  msg := fmt.Sprintf("{ \"%s\": \"%s\"}", "message", time.Now().UnixNano())

  err = l.Send([]byte(msg))
  if err != nil {
     panic(err)
  }

  l.Stop() 
}

Usage

  • Set url mode: logzio.New(token, SetUrl(ts.URL))

  • Set drain duration (flush logs on disk): logzio.New(token, SetDrainDuration(time.Hour))

  • Set debug mode: logzio.New(token, SetDebug(os.Stderr))

  • Set queue dir: logzio.New(token, SetSetTempDirectory(os.Stderr))

  • Set the sender to check if it crosses the maximum allowed disk usage: logzio.New(token, SetCheckDiskSpace(true))

  • Set disk queue threshold, once the threshold is crossed the sender will not enqueue the received logs: logzio.New(token, SetDrainDiskThreshold(99))

  • Set the sender to Use in memory queue: logzio.New(token, SetInMemoryQueue(true))

  • Set the sender to Use in memory queue with log count limit and capacity: logzio.New(token, SetInMemoryQueue(true), SetinMemoryCapacity(500), SetlogCountLimit(6000000), )

Data compression

All bulks are compressed with gzip by default to disable compressing initialize the client with SetCompress(false):

  logzio.New(token, SetCompress(false),
  )

Tests

$ go test -v

Contributing

All PRs are welcome

Authors

  • Douglas Chimento - [dougEfresh][me]
  • Ido Halevi - idohalevi

License

This project is licensed under the Apache License - see the LICENSE file for details

Acknowledgments

Changelog

  • v1.0.1

    • Add gzip compression
    • Add option for in Memory queue
  • v1.0.2

    • Update dependencies

logzio-go's People

Contributors

buger avatar dougefresh avatar dvrkps avatar idohalevi avatar kylekampy avatar mend-bolt-for-github[bot] avatar yotamloe avatar yyyogev avatar

Watchers

 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.