lightninglabs / lightninglabs/taproot-assets
[feature]/multi: start using newLogClosure where applicable
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 525
- Forks
- 150
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 31
Description
**Is your feature request related to a problem? Please describe.**
Today at times we'll call `spew` on a struct so we can get a pretty printable version.
With the way the log statement/function works, the arg will be evaluated even if the log level doesn't apply. As an example, if the log level is `info`, but a `trace` log uses spew, the struct will still get spewed even if we're not logging it. This can eat p some CPU over time
**Describe the solution you'd like**
We should start to use `newLogClosure` for all instances where we might spew something:
```go
// logClosure is used to provide a closure over expensive logging operations so
// don't have to be performed when the logging level doesn't warrant it.
type logClosure func() string
// String invokes the underlying function and returns the result.
func (c logClosure) String() string {
return c()
}
// newLogClosure returns a new closure over a function that returns a string
// which itself provides a Stringer interface so that it can be used with the
// logging system.
func newLogClosure(c func() string) logClosure {
return logClosure(c)
}
```
We can make a higher order function to make the setup+call a bit easier to use.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Search the repository for `spew` calls and existing uses of `newLogClosure` to identify logging paths that eagerly format values. Confirm that expensive formatting is deferred when the log level is disabled, and verify that all applicable instances use the closure pattern without changing logged output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100