Skip to content

Commit

Permalink
logger: "Stderr" => "Output"
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Dec 31, 2020
1 parent 0ff7a0c commit 1bfd135
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion internal/bundler/bundler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1751,7 +1751,7 @@ func (cache *runtimeCache) parseRuntime(options *config.Options) (source logger.
if log.HasErrors() {
msgs := "Internal error: failed to parse runtime:\n"
for _, msg := range log.Done() {
msgs += msg.String(logger.StderrOptions{}, logger.TerminalInfo{})
msgs += msg.String(logger.OutputOptions{}, logger.TerminalInfo{})
}
panic(msgs[:len(msgs)-1])
}
Expand Down
2 changes: 1 addition & 1 deletion internal/bundler/bundler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func assertLog(t *testing.T, msgs []logger.Msg, expected string) {
t.Helper()
text := ""
for _, msg := range msgs {
text += msg.String(logger.StderrOptions{}, logger.TerminalInfo{})
text += msg.String(logger.OutputOptions{}, logger.TerminalInfo{})
}
assertEqual(t, text, expected)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/css_lexer/css_lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func lexerError(contents string) string {
Tokenize(log, test.SourceForTest(contents))
text := ""
for _, msg := range log.Done() {
text += msg.String(logger.StderrOptions{}, logger.TerminalInfo{})
text += msg.String(logger.OutputOptions{}, logger.TerminalInfo{})
}
return text
}
Expand Down
4 changes: 2 additions & 2 deletions internal/css_parser/css_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func expectParseError(t *testing.T, contents string, expected string) {
msgs := log.Done()
text := ""
for _, msg := range msgs {
text += msg.String(logger.StderrOptions{}, logger.TerminalInfo{})
text += msg.String(logger.OutputOptions{}, logger.TerminalInfo{})
}
test.AssertEqual(t, text, expected)
})
Expand All @@ -45,7 +45,7 @@ func expectPrintedCommon(t *testing.T, name string, contents string, expected st
text := ""
for _, msg := range msgs {
if msg.Kind == logger.Error {
text += msg.String(logger.StderrOptions{}, logger.TerminalInfo{})
text += msg.String(logger.OutputOptions{}, logger.TerminalInfo{})
}
}
assertEqual(t, text, "")
Expand Down
2 changes: 1 addition & 1 deletion internal/css_printer/css_printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func expectPrintedCommon(t *testing.T, name string, contents string, expected st
text := ""
for _, msg := range msgs {
if msg.Kind == logger.Error {
text += msg.String(logger.StderrOptions{}, logger.TerminalInfo{})
text += msg.String(logger.OutputOptions{}, logger.TerminalInfo{})
}
}
assertEqual(t, text, "")
Expand Down
2 changes: 1 addition & 1 deletion internal/js_lexer/js_lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func expectLexerError(t *testing.T, contents string, expected string) {
msgs := log.Done()
text := ""
for _, msg := range msgs {
text += msg.String(logger.StderrOptions{}, logger.TerminalInfo{})
text += msg.String(logger.OutputOptions{}, logger.TerminalInfo{})
}
test.AssertEqual(t, text, expected)
})
Expand Down
4 changes: 2 additions & 2 deletions internal/js_parser/js_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func expectParseErrorCommon(t *testing.T, contents string, expected string, opti
msgs := log.Done()
text := ""
for _, msg := range msgs {
text += msg.String(logger.StderrOptions{}, logger.TerminalInfo{})
text += msg.String(logger.OutputOptions{}, logger.TerminalInfo{})
}
test.AssertEqual(t, text, expected)
})
Expand Down Expand Up @@ -54,7 +54,7 @@ func expectPrintedCommon(t *testing.T, contents string, expected string, options
text := ""
for _, msg := range msgs {
if msg.Kind != logger.Warning {
text += msg.String(logger.StderrOptions{}, logger.TerminalInfo{})
text += msg.String(logger.OutputOptions{}, logger.TerminalInfo{})
}
}
test.AssertEqual(t, text, "")
Expand Down
4 changes: 2 additions & 2 deletions internal/js_parser/json_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func expectParseErrorJSON(t *testing.T, contents string, expected string) {
msgs := log.Done()
text := ""
for _, msg := range msgs {
text += msg.String(logger.StderrOptions{}, logger.TerminalInfo{})
text += msg.String(logger.OutputOptions{}, logger.TerminalInfo{})
}
test.AssertEqual(t, text, expected)
})
Expand All @@ -42,7 +42,7 @@ func expectPrintedJSONWithWarning(t *testing.T, contents string, warning string,
msgs := log.Done()
text := ""
for _, msg := range msgs {
text += msg.String(logger.StderrOptions{}, logger.TerminalInfo{})
text += msg.String(logger.OutputOptions{}, logger.TerminalInfo{})
}
test.AssertEqual(t, text, warning)
if !ok {
Expand Down
8 changes: 4 additions & 4 deletions internal/js_parser/ts_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func expectParseErrorTS(t *testing.T, contents string, expected string) {
msgs := log.Done()
text := ""
for _, msg := range msgs {
text += msg.String(logger.StderrOptions{}, logger.TerminalInfo{})
text += msg.String(logger.OutputOptions{}, logger.TerminalInfo{})
}
test.AssertEqual(t, text, expected)
})
Expand All @@ -43,7 +43,7 @@ func expectPrintedTS(t *testing.T, contents string, expected string) {
msgs := log.Done()
text := ""
for _, msg := range msgs {
text += msg.String(logger.StderrOptions{}, logger.TerminalInfo{})
text += msg.String(logger.OutputOptions{}, logger.TerminalInfo{})
}
test.AssertEqual(t, text, "")
if !ok {
Expand Down Expand Up @@ -73,7 +73,7 @@ func expectParseErrorTSX(t *testing.T, contents string, expected string) {
msgs := log.Done()
text := ""
for _, msg := range msgs {
text += msg.String(logger.StderrOptions{}, logger.TerminalInfo{})
text += msg.String(logger.OutputOptions{}, logger.TerminalInfo{})
}
test.AssertEqual(t, text, expected)
})
Expand All @@ -95,7 +95,7 @@ func expectPrintedTSX(t *testing.T, contents string, expected string) {
msgs := log.Done()
text := ""
for _, msg := range msgs {
text += msg.String(logger.StderrOptions{}, logger.TerminalInfo{})
text += msg.String(logger.OutputOptions{}, logger.TerminalInfo{})
}
test.AssertEqual(t, text, "")
if !ok {
Expand Down
2 changes: 1 addition & 1 deletion internal/js_printer/js_printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func expectPrintedCommon(t *testing.T, name string, contents string, expected st
msgs := log.Done()
text := ""
for _, msg := range msgs {
text += msg.String(logger.StderrOptions{}, logger.TerminalInfo{})
text += msg.String(logger.OutputOptions{}, logger.TerminalInfo{})
}
assertEqual(t, text, "")
if !ok {
Expand Down
22 changes: 11 additions & 11 deletions internal/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ type TerminalInfo struct {
Width int
}

func NewStderrLog(options StderrOptions) Log {
func NewStderrLog(options OutputOptions) Log {
var mutex sync.Mutex
var msgs SortableMsgs
terminalInfo := GetTerminalInfo(os.Stderr)
Expand Down Expand Up @@ -351,8 +351,8 @@ func PrintErrorToStderr(osArgs []string, text string) {
PrintMessageToStderr(osArgs, Msg{Kind: Error, Data: MsgData{Text: text}})
}

func StderrOptionsForArgs(osArgs []string) StderrOptions {
options := StderrOptions{IncludeSource: true}
func OutputOptionsForArgs(osArgs []string) OutputOptions {
options := OutputOptions{IncludeSource: true}

// Implement a mini argument parser so these options always work even if we
// haven't yet gotten to the general-purpose argument parsing code
Expand All @@ -377,7 +377,7 @@ func StderrOptionsForArgs(osArgs []string) StderrOptions {
}

func PrintMessageToStderr(osArgs []string, msg Msg) {
log := NewStderrLog(StderrOptionsForArgs(osArgs))
log := NewStderrLog(OutputOptionsForArgs(osArgs))
log.AddMsg(msg)
log.Done()
}
Expand All @@ -392,7 +392,7 @@ type Colors struct {
}

func PrintText(file *os.File, level LogLevel, osArgs []string, callback func(Colors) string) {
options := StderrOptionsForArgs(osArgs)
options := OutputOptionsForArgs(osArgs)

// Skip logging these if these logs are disabled
if options.LogLevel > level {
Expand Down Expand Up @@ -458,22 +458,22 @@ const colorBold = "\033[1m"
const colorResetBold = "\033[0;1m"
const colorResetUnderline = "\033[0;4m"

type StderrColor uint8
type UseColor uint8

const (
ColorIfTerminal StderrColor = iota
ColorIfTerminal UseColor = iota
ColorNever
ColorAlways
)

type StderrOptions struct {
type OutputOptions struct {
IncludeSource bool
ErrorLimit int
Color StderrColor
Color UseColor
LogLevel LogLevel
}

func (msg Msg) String(options StderrOptions, terminalInfo TerminalInfo) string {
func (msg Msg) String(options OutputOptions, terminalInfo TerminalInfo) string {
// Compute the maximum margin
maxMargin := 0
if options.IncludeSource {
Expand Down Expand Up @@ -515,7 +515,7 @@ func emptyMarginText(maxMargin int) string {
return fmt.Sprintf(" %s ╵ ", strings.Repeat(" ", maxMargin))
}

func msgString(options StderrOptions, terminalInfo TerminalInfo, kind MsgKind, data MsgData, maxMargin int) string {
func msgString(options OutputOptions, terminalInfo TerminalInfo, kind MsgKind, data MsgData, maxMargin int) string {
var kindColor string
textColor := colorBold
textResetColor := colorResetBold
Expand Down
10 changes: 5 additions & 5 deletions pkg/api/api_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func validateSourceMap(value SourceMap) config.SourceMap {
}
}

func validateColor(value StderrColor) logger.StderrColor {
func validateColor(value StderrColor) logger.UseColor {
switch value {
case ColorIfTerminal:
return logger.ColorIfTerminal
Expand Down Expand Up @@ -506,7 +506,7 @@ func convertMessagesToInternal(msgs []logger.Msg, kind logger.MsgKind, messages
// Build API

func buildImpl(buildOpts BuildOptions) BuildResult {
logOptions := logger.StderrOptions{
logOptions := logger.OutputOptions{
IncludeSource: true,
ErrorLimit: buildOpts.ErrorLimit,
Color: validateColor(buildOpts.Color),
Expand All @@ -524,7 +524,7 @@ func rebuildImpl(
buildOpts BuildOptions,
caches *cache.CacheSet,
plugins []config.Plugin,
logOptions logger.StderrOptions,
logOptions logger.OutputOptions,
log logger.Log,
) BuildResult {
// Convert and validate the buildOpts
Expand Down Expand Up @@ -736,7 +736,7 @@ func rebuildImpl(
// Transform API

func transformImpl(input string, transformOpts TransformOptions) TransformResult {
log := logger.NewStderrLog(logger.StderrOptions{
log := logger.NewStderrLog(logger.OutputOptions{
IncludeSource: true,
ErrorLimit: transformOpts.ErrorLimit,
Color: validateColor(transformOpts.Color),
Expand Down Expand Up @@ -1052,7 +1052,7 @@ func (h *apiHandler) notifyRequest(duration time.Duration, req *http.Request, st
}

func errorsToString(errors []Message) string {
stderrOptions := logger.StderrOptions{IncludeSource: true}
stderrOptions := logger.OutputOptions{IncludeSource: true}
terminalOptions := logger.TerminalInfo{}
sb := strings.Builder{}
limit := 5
Expand Down

0 comments on commit 1bfd135

Please sign in to comment.