8000 [breaking] legacy: refactoring of the old `Logger` (part 1 of 2) by cmaglie · Pull Request #1621 · arduino/arduino-cli · GitHub
[go: up one dir, main page]

Skip to content

[breaking] legacy: refactoring of the old Logger (part 1 of 2) #1621

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 10 commits into from
Jan 11, 2022
Merged
Next Next commit
LoggerToCustomStreams must have pointer receiver
Becuase it has a mutex field that otherwise is copied.
  • Loading branch information
cmaglie committed Jan 10, 2022
commit 6b35b87c2f9b4506dc843130e984c8a062941e5a
2 changes: 1 addition & 1 deletion commands/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream

builderCtx.ExecStdout = outStream
builderCtx.ExecStderr = errStream
builderCtx.SetLogger(legacyi18n.LoggerToCustomStreams{Stdout: outStream, Stderr: errStream})
builderCtx.SetLogger(&legacyi18n.LoggerToCustomStreams{Stdout: outStream, Stderr: errStream})
builderCtx.Clean = req.GetClean()
builderCtx.OnlyUpdateCompilationDatabase = req.GetCreateCompilationDatabaseOnly()

Expand Down
14 changes: 7 additions & 7 deletions legacy/builder/i18n/i18n.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"sync"
)

var PLACEHOLDER = regexp.MustCompile("{(\\d)}")
var PLACEHOLDER = regexp.MustCompile(`{(\d)}`)

type Logger interface {
Fprintln(w io.Writer, level string, format string, a ...interface{})
Expand All @@ -43,7 +43,7 @@ type LoggerToCustomStreams struct {
mux sync.Mutex
}

func (s LoggerToCustomStreams) Fprintln(w io.Writer, level string, format string, a ...interface{}) {
func (s *LoggerToCustomStreams) Fprintln(w io.Writer, level string, format string, a ...interface{}) {
s.mux.Lock()
defer s.mux.Unlock()
target := s.Stdout
Expand All @@ -53,7 +53,7 @@ func (s LoggerToCustomStreams) Fprintln(w io.Writer, level string, format string
fmt.Fprintln(target, Format(format, a...))
}

func (s LoggerToCustomStreams) UnformattedFprintln(w io.Writer, str string) {
func (s *LoggerToCustomStreams) UnformattedFprintln(w io.Writer, str string) {
s.mux.Lock()
defer s.mux.Unlock()
target := s.Stdout
Expand All @@ -63,7 +63,7 @@ func (s LoggerToCustomStreams) UnformattedFprintln(w io.Writer, str string) {
fmt.Fprintln(target, str)
}

func (s LoggerToCustomStreams) UnformattedWrite(w io.Writer, data []byte) {
func (s *LoggerToCustomStreams) UnformattedWrite(w io.Writer, data []byte) {
s.mux.Lock()
defer s.mux.Unlock()
target := s.Stdout
Expand All @@ -73,15 +73,15 @@ func (s LoggerToCustomStreams) UnformattedWrite(w io.Writer, data []byte) {
target.Write(data)
}

func (s LoggerToCustomStreams) Println(level string, format string, a ...interface{}) {
func (s *LoggerToCustomStreams) Println(level string, format string, a ...interface{}) {
s.Fprintln(nil, level, format, a...)
}

func (s LoggerToCustomStreams) Flush() string {
func (s *LoggerToCustomStreams) Flush() string {
return ""
}

func (s LoggerToCustomStreams) Name() string {
func (s *LoggerToCustomStreams) Name() string {
return "LoggerToCustomStreams"
}

Expand Down
0