Skip to content

Fixed race condition in legacy i18n.LoggerToCustomStreams #704

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

Merged
merged 1 commit into from
May 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions legacy/builder/i18n/i18n.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ type Logger interface {
type LoggerToCustomStreams struct {
Stdout io.Writer
Stderr io.Writer
mux sync.Mutex
}

func (s LoggerToCustomStreams) Fprintln(w io.Writer, level string, format string, a ...interface{}) {
s.mux.Lock()
defer s.mux.Unlock()
target := s.Stdout
if w == os.Stderr {
target = s.Stderr
Expand All @@ -51,6 +54,8 @@ func (s LoggerToCustomStreams) Fprintln(w io.Writer, level string, format string
}

func (s LoggerToCustomStreams) UnformattedFprintln(w io.Writer, str string) {
s.mux.Lock()
defer s.mux.Unlock()
target := s.Stdout
if w == os.Stderr {
target = s.Stderr
Expand All @@ -59,6 +64,8 @@ func (s LoggerToCustomStreams) UnformattedFprintln(w io.Writer, str string) {
}

func (s LoggerToCustomStreams) UnformattedWrite(w io.Writer, data []byte) {
s.mux.Lock()
defer s.mux.Unlock()
target := s.Stdout
if w == os.Stderr {
target = s.Stderr
Expand Down