You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Debug("Debug message")
Debugf("Debug message with format: %s", "hello")
Info("Info message")
Infof("Info message with format: %d", 123)
Warning("Warning message")
Warningf("Warning message with format: %f", 3.14)
Error("Error message")
Errorf("Error message with format: %t", true)
Fatal("Fatal message")
Fatalf("Fatal message with format: %v", "goodbye")
Notes:
The package will output logs to stdout and index them in Elasticsearch.
The package is concurrent safe and the elasticsearch client will be initiated only once.
If you want to change the timestamp format you can change the format by using the SetTimeFormat()function. Default layout is 2023-01-02 15:04:05
You can use the SetLogLevel function to filter the logs you want to see based on the log level.
Example:
package main
import (
"github.com/cploutarchou/go-elastic-logger/v8""github.com/elastic/go-elasticsearch/v8"
)
// setElasticClient sets the elasticsearch client to be used for logging.funcsetElasticClient() {
cnf:= elasticsearch.Config{
Addresses: []string{"http://localhost:9200"},
Username: "your_username",
Password: "your_password",
}
client, err:=elasticsearch.NewClient(cnf)
iferr!=nil {
panic(err)
}
//sets the client as the Elasticsearch client to be used.SetElasticsearchClient(client)
}
functestFnc() {
// sets the index name to be used for logging.SetIndex("logs")
//sets the log level to debug.SetLogLevel(DEBUG)
//sets the format of the timestamp in the logs.SetTimeFormat("2006-01-02 15:04:05")
//logs a debug message.Debug("This is a debug message")
return
}
funcmain() {
//sets the elasticsearch client to be used for logging.setElasticClient()
testFnc()
}