This commit is contained in:
parent
24cc151938
commit
c0fd74f1e6
@ -5,10 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/rs/zerolog"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type LokiWriter struct {
|
type LokiWriter struct {
|
||||||
@ -98,25 +95,3 @@ func (w *LokiWriter) Write(p []byte) (n int, err error) {
|
|||||||
|
|
||||||
return len(p), nil
|
return len(p), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
|
||||||
lokiURL := "http://your-loki-url/loki/api/v1/push"
|
|
||||||
labels := map[string]string{
|
|
||||||
"app": "your_app_name",
|
|
||||||
// Add more labels as needed
|
|
||||||
}
|
|
||||||
|
|
||||||
lokiWriter := NewLokiWriter(lokiURL, labels)
|
|
||||||
|
|
||||||
consoleWriter := zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC3339}
|
|
||||||
|
|
||||||
multiWriter := zerolog.MultiLevelWriter(consoleWriter, lokiWriter)
|
|
||||||
|
|
||||||
logger := zerolog.New(multiWriter).With().Timestamp().Logger()
|
|
||||||
|
|
||||||
// Configure the logger in the sublibrary
|
|
||||||
sublibrary.AddLogger(logger)
|
|
||||||
|
|
||||||
logger.Info().Msg("Main library log message")
|
|
||||||
sublibrary.SublibraryFunction()
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user