nats-io / nats-server

High-Performance server for NATS.io, the cloud and edge native messaging system.
https://nats.io
Apache License 2.0
15.65k stars 1.39k forks source link

Unable to log messages or trace in debug mode in NATS Embedded server #5569

Closed iamshreeram closed 3 months ago

iamshreeram commented 3 months ago

Observed behavior

When a message is posted to a given subject inside the NATS Embedded server, the trace or debug options do not print any details.

Expected behavior

I expect the payload to be printed when a message is posted to a given subject inside the NATS Embedded server, enabling effective debugging and message logging.

Server and client version

Server : 2.10 Client : 1.35

Host environment

Mac

Steps to reproduce

Start the embedded server with Trace or debug option like below -

...
    natsServer := natsserver.NewNatsServer()
    ns := natsServer.StartNatsServer(&server.Options{TraceVerbose: true})
    defer ns.WaitForShutdown()
...
func (ns *natsServer) StartNatsServer(opts *server.Options) *server.Server {
    ns.server, _ = server.NewServer(opts)
    go ns.server.Start()
    if !ns.server.ReadyForConnections(4 * time.Second) {
        panic("not ready for connection")
    }
    return ns.server
}
ripienaar commented 3 months ago

You need to configure the logger to initialize logging, also supports passing in your own logger.

https://github.com/nats-io/nats-server/blob/3d9cbb908704b1bea66be3f92805a18fd021ecac/server/log.go#L49

iamshreeram commented 3 months ago

@ripienaar , Thank you for the prompt reply.

I did have ns.ConfigureLogger() in place, but the issue was with the Options. I mistakenly used TraceVerbose instead of Trace. Correcting this with the snippet below resolved the problem.

    natsServer := natsserver.NewNatsServer()
    ns := natsServer.StartNatsServer(&server.Options{Trace: true})
    ns.ConfigureLogger()
    defer ns.WaitForShutdown()