Skip to content

Omitting client.Stop() prevents logs being pushed to loki server #15

Description

@lfonosol

Hello

I managed to get logs pushed to my loki grafana setup (with some trial and error) and I was wondering if it is necessary to call client.Stop() in order for the logs to be pushed to the loki server?

`func SetDefaultLogger() {
url := "http://localhost:3100/loki/api/v1/push"

config, lokiErr := loki.NewDefaultConfig(url)
if lokiErr != nil {
	panic(lokiErr)
}

client, lokiErr := loki.New(config)
if lokiErr != nil {
	panic(lokiErr)
}

// Is this necessary?
defer client.Stop()

option := slogloki.Option{Level: slog.LevelDebug, Client: client}
handler := option.NewLokiHandler()
logger := slog.New(handler).With(slog.String("job", "audit-log"))

slog.SetDefault(logger)

log.Print("log.Print")
logger.Debug("logger.Debug")
logger.Info("logger.Info")
logger.Warn("logger.Warn")
logger.Error("logger.Error")

}`

If I remove the line defer client.Stop() I don't see the messages in Grafana.

The problem for me is that my application will hang if the client is stopped and I try and call the default logger elsewhere in the code.

Is there a way I can set this default logger without having to call client.Stop()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions