This shipper uses goleveldb and goqueue as a persistent storage implementation of a persistent queue, so the shipper backs up your logs to the local file system before sending them. Logs are queued in the buffer and 100% non-blocking. A background Go routine ships the logs every 5 seconds.
Set up the Logz.io Golang API client
Before you begin, you’ll need: Go 1.x or higher
Add the dependency to your project
Navigate to your project’s folder in the command line, and run this command to install the dependency.
go get -u github.com/logzio/logzio-go
Configure the client
Use the sample in the code block below as a starting point, and replace the sample with a configuration that matches your needs.
For a complete list of options, see the configuration parameters below the code block.👇
package main
import (
"fmt"
"os"
"time"
"github.com/logzio/logzio-go"
)
func main() {
// Replace these parameters with your configuration
l, err := logzio.New(
"<<LOG-SHIPPING-TOKEN>>",
logzio.SetDebug(os.Stderr),
logzio.SetUrl("https://<<LISTENER-HOST>>:8071"),
logzio.SetDrainDuration(time.Second * 5),
logzio.SetTempDirectory("myQueue"),
logzio.SetDrainDiskThreshold(99),
)
if err != nil {
panic(err)
}
// Because you're configuring directly in the code,
// you can paste the code sample here to send a test log.
//
// The code sample is below the parameters list. 👇
}
Parameters
| Parameter | Description | Required/Default |
|---|---|---|
| token | Your Logz.io log shipping token directs the data securely to your Logz.io Log Management account. The default token is auto-populated in the examples when you’re logged into the Logz.io app as an Admin. Manage your tokens. Replace <<LOG-SHIPPING-TOKEN>> with the token of the account you want to ship to. |
Required |
| SetUrl | Listener URL and port. Replace <<LISTENER-HOST>> with the host for your region. For example, listener.logz.io if your account is hosted on AWS US East, or listener-nl.logz.io if hosted on Azure West Europe. The required port depends whether HTTP or HTTPS is used: HTTP = 8070, HTTPS = 8071. |
Required (default: https://listener.logz.io:8071) |
| SetDebug | Debug flag. | false |
| SetDrainDuration | Time to wait between log draining attempts. | 5 * time.Second |
| SetTempDirectory | Filepath where the logs are buffered. | -- |
| SetCheckDiskSpace | To enable SetDrainDiskThreshold, set to true. Otherwise, false. |
true |
| SetDrainDiskThreshold | Maximum file system usage, in percent. Used only if SetCheckDiskSpace is set to true. If the file system storage exceeds this threshold, buffering stops and new logs are dropped. Buffering resumes if used space drops below the threshold. |
70.0 |
Code sample
msg := fmt.Sprintf("{\"%s\": \"%d\"}", "message", time.Now().UnixNano())
err = l.Send([]byte(msg))
if err != nil {
panic(err)
}
l.Stop() // Drains the log buffer