-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Refactor prism and go sdk logging and clean up messages #36484
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one or more | ||
| // contributor license agreements. See the NOTICE file distributed with | ||
| // this work for additional information regarding copyright ownership. | ||
| // The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| // (the "License"); you may not use this file except in compliance with | ||
| // the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package log | ||
|
|
||
| import ( | ||
| "context" | ||
| slogger "log/slog" | ||
| ) | ||
|
|
||
| // Structural is a wrapper over slog | ||
| type Structural struct{} | ||
|
|
||
| var loggerMap = map[Severity]func(string, ...any){ | ||
| SevUnspecified: slogger.Info, | ||
| SevDebug: slogger.Debug, | ||
| SevInfo: slogger.Info, | ||
| SevWarn: slogger.Warn, | ||
| SevError: slogger.Error, | ||
| SevFatal: slogger.Error, | ||
| } | ||
|
|
||
| // Log logs the message to the structural Go logger. For Panic, it does not | ||
| // perform the os.Exit(1) call, but defers to the log wrapper. | ||
| func (s *Structural) Log(ctx context.Context, sev Severity, _ int, msg string) { | ||
| loggerMap[sev](msg) | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -19,6 +19,7 @@ import ( | |||||||||||||||||||||||||||||||||||||||||
| "context" | ||||||||||||||||||||||||||||||||||||||||||
| "fmt" | ||||||||||||||||||||||||||||||||||||||||||
| "io" | ||||||||||||||||||||||||||||||||||||||||||
| "strings" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| "github.com/apache/beam/sdks/v2/go/container/tools" | ||||||||||||||||||||||||||||||||||||||||||
| "github.com/apache/beam/sdks/v2/go/pkg/beam" | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -138,7 +139,16 @@ func WaitForCompletion(ctx context.Context, client jobpb.JobServiceClient, jobID | |||||||||||||||||||||||||||||||||||||||||
| case msg.GetMessageResponse() != nil: | ||||||||||||||||||||||||||||||||||||||||||
| resp := msg.GetMessageResponse() | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| text := fmt.Sprintf("%v (%v): %v", resp.GetTime(), resp.GetMessageId(), resp.GetMessageText()) | ||||||||||||||||||||||||||||||||||||||||||
| var b strings.Builder | ||||||||||||||||||||||||||||||||||||||||||
| if resp.GetTime() != "" { | ||||||||||||||||||||||||||||||||||||||||||
| fmt.Fprintf(&b, "(time=%v)", resp.GetTime()) | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| if resp.GetMessageId() != "" { | ||||||||||||||||||||||||||||||||||||||||||
| fmt.Fprintf(&b, "(id=%v)", resp.GetMessageId()) | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| b.WriteString(resp.GetMessageText()) | ||||||||||||||||||||||||||||||||||||||||||
| text := b.String() | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+142
to
+151
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
| log.Output(ctx, messageSeverity(resp.GetImportance()), 1, text) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| if resp.GetImportance() >= jobpb.JobMessage_JOB_MESSAGE_ERROR { | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The configuration for the
devlog kind usesdevslog, which produces a human-readable format (e.g.,[<timestamp>] INFO ...). However, the 'After' log example in the pull request description shows akey=valueformat, which corresponds to thetextlog kind (slog.TextHandler). Since the defaultlog_kindfor Prism isdev, this discrepancy could be confusing. To align the default behavior with the example, you might consider changing the defaultlog_kindflag insdks/go/cmd/prism/prism.gototext, or updating the PR description to show an example of thedevslogoutput.