DanielBerman/logzio-go

Low level go client for Logz

★ 0Forks 0GoGitHub ↗Compare

Project website ↗

README

Logz.io Golang API client

Sends logs to Logz.io over HTTP. It is a low level library that can be integrated with other logging libraries.

GoDoc Build Status Coverage Status Go Report

Prerequisites

go 1.x

Installation

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

Quick Start

package main

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

func main() {
  l, err := logzio.New(
  		"fake-token",
  		SetDebug(os.Stderr),
  		SetUrl("http://localhost:12345"),
  		SetDrainDuration(time.Minute*10),
        SetSetTempDirectory("myQueue"),
        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
}

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))

Disk queue

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

Tests

$ go test -v

See travis.yaml for running benchmark tests

Contributing

All PRs are welcome

Authors

License

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

Acknowledgments

Contributors

dougEfreshDanielBermanidohalevidvrkpskylekampy

Issues