Centralized logs to yours applications.
go get github.com/libercapital/liber-logger-go.git
package main
import "github.com/libercapital/liber-logger-go.git"
func main() {
ctx := Context.Background()
liberlogger.Init(os.Getenv("LOG_LEVEL"))
liberlogger.Info(ctx).Msg("send a msg with info level")
liberlogger.Debug(ctx).Msg("send a msg with debug level")
errorTest := errors.New("error test")
liberlogger.Error(ctx, errorTest).Msg("send a msg with error level")
liberlogger.Warn(ctx).Msg("send a msg with warn level")
errorTest = errors.New("fatal error test")
liberlogger.Fatal(ctx, errorTest).Msg("send a msg with error level")
}
Unredacted
package main
import(
"github.com/libercapital/liber-logger-go.git"
"github.com/labstack/echo/v4"
)
func main() {
liberlogger.Init(os.Getenv("LOG_LEVEL"))
e := echo.New()
e.Use(liberlogger.EchoV4([]string{"/health"}))
}
Redacted
package main
import(
"github.com/libercapital/liber-logger-go.git"
"github.com/labstack/echo/v4"
)
func main() {
liberlogger.Init(os.Getenv("LOG_LEVEL"))
e := echo.New()
e.Use(liberlogger.EchoV4Redacted(liberlogger.DefaultKeys, []string{}))
//aditional keys
redactKeys := liberlogger.DefaultKeys
copy(redactKeys, []string{"reference_uuid", "document_number"})
e.Use(liberlogger.EchoV4Redacted(redactKeys, []string{"/health"}))
}
Unredacted
package main
import (
"net/http"
"github.com/libercapital/liber-logger-go.git"
)
func main() {
liberlogger.Init(os.Getenv("LOG_LEVEL"))
httpClient := &http.Client{
Transport: liberlogger.HttpClient{
Proxied: http.DefaultTransport,
},
}
httpClient.Get("https://google.com.br")
}
Redacted
package main
import (
"net/http"
"github.com/libercapital/liber-logger-go.git"
)
func main() {
liberlogger.Init(os.Getenv("LOG_LEVEL"))
httpClient := &http.Client{
Transport: liberlogger.HttpClient{
Proxied: http.DefaultTransport,
RedactedKeys: liberlogger.DefaultKeys,
},
}
httpClient.Get("https://google.com.br")
}
Unredacted
package main
import (
"bytes"
"fmt"
"net/http"
"github.com/gorilla/mux"
"github.com/libercapital/liber-logger-go.git"
)
func main() {
liberlogger.Init(os.Getenv("LOG_LEVEL"))
r := mux.NewRouter()
r.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) {
fmt.Fprintf(rw, "ok")
})
r.Use(liberlogger.GorillaMux([]string{"/health"}))
http.ListenAndServe(":8085", r)
}
Redacted
package main
import (
"bytes"
"fmt"
"net/http"
"github.com/gorilla/mux"
"github.com/libercapital/liber-logger-go.git"
)
func main() {
liberlogger.Init(os.Getenv("LOG_LEVEL"))
r := mux.NewRouter()
r.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) {
fmt.Fprintf(rw, "ok")
})
r.Use(liberlogger.GorillaMuxRedacted(liberlogger.DefaultKeys, []string{"/health"}))
http.ListenAndServe(":8085", r)
}
ctx, span := liberlogger.StartContextAndTrace(liberlogger.StartContextAndTraceConfig{
Ctx: c.Request().Context(),
})
defer span.Finish()
ctx, span := liberlogger.StartContextAndTrace(liberlogger.StartContextAndTraceConfig{
ServiceName: "service-name",
OperationName: "invoice.cmd.creation",
})
defer span.Finish()