go logstash
expose Logger struct
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.
go get github.com/KaranJagtiani/go-logstash
import "github.com/KaranJagtiani/go-logstash"
logstash_logger
instance with your Logstash server details and connection type:logger := logstash_logger.Init("<host>", <port>, "protocol", <timeout>)
The logstash_logger.Init()
has the following configuration options:
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.