Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit76c621d

Browse files
committed
fixed log formatting
1 parent7365bf1 commit76c621d

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

‎coderd/httpmw/logger.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ func Logger(log slog.Logger) func(next http.Handler) http.Handler {
3838
logContext:=&RequestLoggerContext{
3939
log:&httplog,
4040
written:false,
41+
message:r.Method,
4142
}
4243
deferfunc() {
43-
logContext.WriteLog(r.Context(),"",sw.Status)
44+
logContext.WriteLog(r.Context(),sw.Status)
4445
}()
4546

4647
ctx:=context.WithValue(r.Context(),logContextKey{},logContext)
@@ -88,23 +89,24 @@ func Logger(log slog.Logger) func(next http.Handler) http.Handler {
8889
typeRequestLoggerContextstruct {
8990
log*slog.Logger
9091
writtenbool
92+
messagestring
9193
}
9294

9395
func (c*RequestLoggerContext)WithFields(fields...slog.Field) {
9496
newLogger:=c.log.With(fields...)
9597
c.log=&newLogger
9698
}
9799

98-
func (c*RequestLoggerContext)WriteLog(ctx context.Context,msgstring,statusint) {
100+
func (c*RequestLoggerContext)WriteLog(ctx context.Context,statusint) {
99101
ifc.written {
100102
return
101103
}
102104
c.written=true
103105

104106
ifstatus>=http.StatusInternalServerError {
105-
c.log.Error(ctx,msg)
107+
c.log.Error(ctx,c.message,"status_code",status)
106108
}else {
107-
c.log.Debug(ctx,msg)
109+
c.log.Debug(ctx,c.message,"status_code",status)
108110
}
109111
}
110112

‎coderd/provisionerjobs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ func (f *logFollower) follow() {
556556

557557
// write the initial logs to the connection
558558
httpmw.FromContext(f.ctx).WriteLog(
559-
f.ctx,"ProvisionerJobs log follower WS connection established",http.StatusAccepted)
559+
f.ctx,http.StatusAccepted)
560560

561561
// no need to wait if the job is done
562562
iff.complete {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp