Logstash Logger written in Go that pushes logs directly to Logstash. It supports writing outputs to Logstash in JSON format as well as String format.
- Supports TCP and UDP protocols for sending logs to Logstash.
- Supports writing logs in both JSON and string formats.
- Provides customisable options for configuring the Logstash connection.
go get github.com/KaranJagtiani/go-logstash
import "github.com/KaranJagtiani/go-logstash"
logger := logstash_logger.Init("<host>", <port>, "protocol", <timeout>)
The logstash_logger.Init()
has the following configuration options:
- Host: Logstash server hostname.
- Port: Logstash server port number.
- Protocol: Logstash connection protocol, either "tcp" or "udp".
- Timeout: Connection timeout in seconds.
Example:
logger := logstash_logger.Init("logstash", 5228, "udp", 5)
payload := map[string]interface{}{
"message": "test message",
"error": false,
}
// Generic - For logging the payload as it is
logger.Log(payload)
// Adds a attribute called "severity": "INFO" to the payload
logger.Info(payload)
// Adds a attribute called "severity": "DEBUG" to the payload
logger.Debug(payload)
// Adds a attribute called "severity": "WARN" to the payload
logger.Warn(payload)
// Adds a attribute called "severity": "ERROR" to the payload
logger.Error(payload)
// For sending a string message to Logstash
logger.LogString("String Message")
Contributions to go-logstash are welcome! If you find a bug or want to add a new feature, please create an issue or submit a pull request here on GitHub.
- Fork this repository.
- Create your feature branch (git checkout -b my-new-feature).
- Commit your changes (git commit -am 'Add some feature').
- Push to the branch (git push origin my-new-feature).
- Create a new Pull Request.