mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-29 22:26:15 -06:00
when appending log field only do so by minimal amount
This commit is contained in:
parent
45e1609377
commit
74b364ee14
1 changed files with 13 additions and 5 deletions
|
|
@ -22,7 +22,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/syslog"
|
"log/syslog"
|
||||||
"os"
|
"os"
|
||||||
"slices"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -420,11 +419,20 @@ func logf(ctx context.Context, depth int, lvl LEVEL, fields []kv.Field, s string
|
||||||
}
|
}
|
||||||
|
|
||||||
if s != "" {
|
if s != "" {
|
||||||
// Append message to log fields.
|
if len(fields) >= cap(fields) {
|
||||||
fields = slices.Grow(fields, 1)
|
// Reallocate fields to store JUST 1 more.
|
||||||
fields = append(fields, kv.Field{
|
fields2 := make([]kv.Field, len(fields)+1)
|
||||||
|
_ = copy(fields2, fields)
|
||||||
|
fields = fields2
|
||||||
|
} else {
|
||||||
|
// Reslice to JUST store one more.
|
||||||
|
fields = fields[:len(fields)+1]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Append msg as final log field.
|
||||||
|
fields[len(fields)-1] = kv.Field{
|
||||||
K: "msg", V: fmt.Sprintf(s, a...),
|
K: "msg", V: fmt.Sprintf(s, a...),
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append formatted fields to log buffer.
|
// Append formatted fields to log buffer.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue