Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
b225508c
Unverified
Commit
b225508c
authored
Sep 16, 2025
by
Michael Yang
Committed by
GitHub
Sep 16, 2025
Browse files
logutil: fix source field (#12279)
parent
fa1c987a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
2 deletions
+12
-2
logutil/logutil.go
logutil/logutil.go
+12
-2
No files found.
logutil/logutil.go
View file @
b225508c
...
@@ -5,6 +5,8 @@ import (
...
@@ -5,6 +5,8 @@ import (
"io"
"io"
"log/slog"
"log/slog"
"path/filepath"
"path/filepath"
"runtime"
"time"
)
)
const
LevelTrace
slog
.
Level
=
-
8
const
LevelTrace
slog
.
Level
=
-
8
...
@@ -29,10 +31,18 @@ func NewLogger(w io.Writer, level slog.Level) *slog.Logger {
...
@@ -29,10 +31,18 @@ func NewLogger(w io.Writer, level slog.Level) *slog.Logger {
}))
}))
}
}
type
key
string
func
Trace
(
msg
string
,
args
...
any
)
{
func
Trace
(
msg
string
,
args
...
any
)
{
slog
.
Log
(
context
.
TODO
(),
LevelTrace
,
msg
,
args
...
)
TraceContext
(
context
.
WithValue
(
context
.
TODO
(),
key
(
"skip"
),
1
)
,
msg
,
args
...
)
}
}
func
TraceContext
(
ctx
context
.
Context
,
msg
string
,
args
...
any
)
{
func
TraceContext
(
ctx
context
.
Context
,
msg
string
,
args
...
any
)
{
slog
.
Log
(
ctx
,
LevelTrace
,
msg
,
args
...
)
if
logger
:=
slog
.
Default
();
logger
.
Enabled
(
ctx
,
LevelTrace
)
{
skip
,
_
:=
ctx
.
Value
(
key
(
"skip"
))
.
(
int
)
pc
,
_
,
_
,
_
:=
runtime
.
Caller
(
1
+
skip
)
record
:=
slog
.
NewRecord
(
time
.
Now
(),
LevelTrace
,
msg
,
pc
)
record
.
Add
(
args
...
)
logger
.
Handler
()
.
Handle
(
ctx
,
record
)
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment