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

rslog.CapturingLogger: Messages returns its underlying message slice #207

Open
aronatkins opened this issue Jan 10, 2025 · 1 comment
Open

Comments

@aronatkins
Copy link
Contributor

aronatkins commented Jan 10, 2025

The capturing logger returns its underlying message slice, allowing a caller to modify the recorded message contents.

func (l *CapturingLogger) Messages() []string {
return l.hook.Messages()
}

func (h *captureMessageHook) Messages() []string {
h.mu.RLock()
defer h.mu.RUnlock()
return h.messages
}

Messages() should return a copy of its message slice.

@aronatkins
Copy link
Contributor Author

Related: Some callers want messages starting from a named offset, so they have code like:

messages := capLog.Messages()
selectedMessages := append([]string{}, messages[start:]...)

The capturing logger could include this functionality itself with MessagesFrom(start int). The result would be the selected subset of messages with no references to the underlying message slice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant