Skip to content

Commit

Permalink
Suppress logrus entries that contain text related to ListenSocket (#…
Browse files Browse the repository at this point in the history
…6514) (#12491)

Signed-off-by: Modular Magician <magic-modules@google.com>

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Sep 7, 2022
1 parent 587d83d commit 1be6042
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/6514.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:none

```
14 changes: 12 additions & 2 deletions google/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,20 @@ type Formatter struct {
// Borrowed logic from https://github.com/sirupsen/logrus/blob/master/json_formatter.go and https://github.com/t-tomalak/logrus-easy-formatter/blob/master/formatter.go
func (f *Formatter) Format(entry *logrus.Entry) ([]byte, error) {
// Suppress logs if TF_LOG is not DEBUG or TRACE
// Also suppress frequent transport spam
if !logging.IsDebugOrHigher() || strings.Contains(entry.Message, "transport is closing") {
if !logging.IsDebugOrHigher() {
return nil, nil
}

// Also suppress based on log content
// - frequent transport spam
// - ListenSocket logs from gRPC
isTransportSpam := strings.Contains(entry.Message, "transport is closing")
listenSocketRegex := regexp.MustCompile(`\[Server #\d+( ListenSocket #\d+)*\]`) // Match patterns like `[Server #00]` or `[Server #00 ListenSocket #00]`
isListenSocketLog := listenSocketRegex.MatchString(entry.Message)
if isTransportSpam || isListenSocketLog {
return nil, nil
}

output := f.LogFormat
entry.Level = logrus.DebugLevel // Force Entries to be Debug

Expand Down

0 comments on commit 1be6042

Please sign in to comment.