Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embedded nats servers with opt.LogFile have no logging #5411

Open
ZiRunHua opened this issue May 13, 2024 · 2 comments
Open

Embedded nats servers with opt.LogFile have no logging #5411

ZiRunHua opened this issue May 13, 2024 · 2 comments
Labels
defect Suspected defect such as a bug or regression

Comments

@ZiRunHua
Copy link

Observed behavior

Use an embedded nats server with opt.LogFile but logging is not logged

Expected behavior

The expected behavior is to see logging content in the specified log file, such as the following:
[1] 2024/05/13 11:48:57.455246 [TRC] 127.0.0.1:48990-cid :5 - <<- [SUB statisticUpdate 1]

Server and client version

tested with nats-server v2.10.12 and nats v1.33.1

Host environment

linux

Steps to reproduce

	natsLogPath := "log/nats.log"
	opts := &server.Options{LogFile: natsLogPath}
	nastServer, err := server.NewServer(opts)
	if err != nil {
		panic(err)
	}
	nastServer.Start()
	Nats, err = nats.Connect(nats.DefaultURL)
	if err != nil {
		panic(err)
	}
@ZiRunHua ZiRunHua added the defect Suspected defect such as a bug or regression label May 13, 2024
@ZiRunHua
Copy link
Author

I am not sure if this is a problem with options, I tried to add other options, but the log is still not recorded.
After that, I found the SetLoggerV2 method, which solved the problem for the time being.

nastServer.SetLoggerV2(logger.NewFileLogger(natsLogPath, true, false, true, true, logger.LogUTC(false)), false, true, false)

Now that the presentation has solved the problem, the log is recorded:

[1] 2024/05/13 14:38:27.067480 [TRC] 127.0.0.1:49120 - cid:5 - <<- [SUB statisticUpdate  1]
[1] 2024/05/13 14:38:36.644184 [TRC] 127.0.0.1:49120 - cid:5 - <<- [PUB statisticUpdate 134]
[1] 2024/05/13 14:38:36.644204 [TRC] 127.0.0.1:49120 - cid:5 - <<- MSG_PAYLOAD: ["{\"AccountId\":25,\"UserId\":24,\"IncomeExpense\":\"expense\",\"CategoryId\":615,\"TradeTime\":\"2024-05-13T10:24:52+08:00\",\"Amount\":800,\"Count\":1}"]
[1] 2024/05/13 14:38:36.644216 [TRC] 127.0.0.1:49120 - cid:5 - ->> [MSG statisticUpdate 1 134]

@neilalexander
Copy link
Member

neilalexander commented May 13, 2024

If you want to use the logging options in server.Options{}, you will need to call ConfigureLogger() on the server instance afterwards.

Then you shouldn't need to call SetLoggerV2() yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect Suspected defect such as a bug or regression
Projects
None yet
Development

No branches or pull requests

2 participants