Sends logs to logz.io over HTTP. It is a low level lib that can to be integrated with other logging libs.
go 1.x
$ go get -u github.com/logzio/logzio-goLogzio golang api client offers two queue implementations that you can use:
Logzio go client uses goleveldb and goqueue as a persistent storage. Every 5 seconds logs are sent to logz.io (if any are available)
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.
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
}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()
}-
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 error output. Transport/network failures, non-retryable HTTP responses and dropped logs are written here at error level (independently of debug mode). Defaults to
os.Stderr; passnilto silence:logzio.New(token, SetErrorOutput(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), )
All bulks are compressed with gzip by default to disable compressing initialize the client with SetCompress(false):
logzio.New(token,
SetCompress(false),
)$ go test -vAll PRs are welcome
- Douglas Chimento - dougEfresh
- Ido Halevi - idohalevi
- Yotam Loewenbach - yotamloe
This project is licensed under the Apache License - see the LICENSE file for details
- v1.0.10
- Add
SetErrorOutput(io.Writer)option to direct error-level messages to a configurable writer (defaults toos.Stderr; passnilto silence). - Emit transport/network send failures, non-retryable HTTP responses (400/401/403/404) and dropped-log events at error level instead of only debug level.
- Behavior change: these failure and dropped-log events were previously logged via
debugand only appeared whenSetDebugwas enabled. They are now written toos.Stderrby default, so after upgrading you may see new stderr output on transient send failures and queue drops. To silence error output entirely, passlogzio.SetErrorOutput(nil); to redirect it, pass your ownio.Writer.
- Add
- v1.0.9
- Update dependencies:
github.com/shirou/gopsutil/v3:v3.24.2->v3.24.5
- Handle http.NewRequest error
- Update dependencies:
- v1.0.8
- Add
AwaitDrainfunction to support ensuring all logs are drained in synchronous runtimes
- Add
- v1.0.7
- Added set http client option (@orelazar1)
- Update dependencies:
github.com/shirou/gopsutil/v3:v3.22.3->v3.24.2go.uber.org/atomic:v1.9.0->v1.11.0
- Update go version
1.15->1.20
- v1.0.6
- Change logging
- Remove draining queue log
- v1.0.5
- Change
tokenquery parameter to optional for generic use - Changed logging levels
- Change
- v1.0.4
- Update gopsutil version (v3.21.6 -> v3.22.3)
- v1.0.3
- Adjust buffer clearance
- Changed logging format
- v1.0.2
- Update dependencies
- v1.0.1
- Add gzip compression
- Add option for in Memory queue