This repository has been archived by the owner on Sep 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: thxCode <[email protected]>
- Loading branch information
Showing
2 changed files
with
37 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,43 @@ | ||
package apis | ||
|
||
import ( | ||
"bufio" | ||
"bytes" | ||
stdlog "log" | ||
"strings" | ||
|
||
"github.com/seal-io/seal/utils/log" | ||
) | ||
|
||
func newStdLogger(delegate log.Logger) *stdlog.Logger { | ||
return stdlog.New(logWriter{logger: delegate}, "", stdlog.Lshortfile) | ||
func newStdErrorLogger(delegate log.Logger) *stdlog.Logger { | ||
return stdlog.New(logWriter{logger: delegate}, "", 0) | ||
} | ||
|
||
type logWriter struct { | ||
logger log.Logger | ||
} | ||
|
||
func (l logWriter) Write(p []byte) (int, error) { | ||
s := bufio.NewScanner(bytes.NewReader(p)) | ||
for s.Scan() { | ||
if strings.HasSuffix(s.Text(), "tls: unknown certificate") { | ||
continue | ||
s := string(p) | ||
|
||
ok := true | ||
|
||
switch { | ||
case strings.HasPrefix(s, "http: TLS handshake error from"): | ||
switch { | ||
case strings.HasSuffix(s, "tls: unknown certificate\n"): | ||
// Ignore self-generated certificate errors from client. | ||
ok = false | ||
case strings.HasSuffix(s, "connection reset by peer\n"): | ||
// Reset TLS handshake errors from client. | ||
ok = false | ||
} | ||
case strings.Contains(s, "broken pipe"): | ||
// Terminate by client. | ||
ok = false | ||
} | ||
|
||
l.logger.Info(s.Text()) | ||
if ok { | ||
l.logger.Warn(s) | ||
} | ||
|
||
return len(p), s.Err() | ||
return len(p), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters