Skip to content

Commit 4be87e5

Browse files
author
Federico Fissore
committed
Introducing log levels. ALL messages are now printed on stdout, with an initial
info/debug/warn/error log level. Output from child processes is still redirected to stdout/stderr Signed-off-by: Federico Fissore <[email protected]>
1 parent 2f78246 commit 4be87e5

17 files changed

+41
-36
lines changed

Diff for: src/arduino.cc/builder/add_build_board_property_if_missing.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (s *AddBuildBoardPropertyIfMissing) Run(context map[string]interface{}) err
4848
for _, board := range platform.Boards {
4949
if board.Properties[constants.BUILD_PROPERTIES_BUILD_BOARD] == constants.EMPTY_STRING {
5050
board.Properties[constants.BUILD_PROPERTIES_BUILD_BOARD] = strings.ToUpper(platform.PlatformId + "_" + board.BoardId)
51-
logger.Fprintln(os.Stderr, constants.MSG_MISSING_BUILD_BOARD, aPackage.PackageId, platform.PlatformId, board.BoardId, board.Properties[constants.BUILD_PROPERTIES_BUILD_BOARD])
51+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_WARN, constants.MSG_MISSING_BUILD_BOARD, aPackage.PackageId, platform.PlatformId, board.BoardId, board.Properties[constants.BUILD_PROPERTIES_BUILD_BOARD])
5252
}
5353
}
5454
}

Diff for: src/arduino.cc/builder/builder.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,13 @@ func printProgressIfProgressEnabledAndMachineLogger(progressEnabled bool, contex
203203

204204
log := utils.Logger(context)
205205
if log.Name() == "machine" {
206-
log.Println(constants.MSG_PROGRESS, strconv.FormatFloat(float64(progress), 'f', 2, 32))
206+
log.Println(constants.LOG_LEVEL_INFO, constants.MSG_PROGRESS, strconv.FormatFloat(float64(progress), 'f', 2, 32))
207207
}
208208
}
209209

210210
func PrintRingNameIfDebug(context map[string]interface{}, command types.Command) {
211211
if utils.DebugLevel(context) >= 10 {
212-
utils.Logger(context).Fprintln(os.Stderr, constants.MSG_RUNNING_COMMAND, strconv.FormatInt(time.Now().Unix(), 10), reflect.Indirect(reflect.ValueOf(command)).Type().Name())
212+
utils.Logger(context).Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, constants.MSG_RUNNING_COMMAND, strconv.FormatInt(time.Now().Unix(), 10), reflect.Indirect(reflect.ValueOf(command)).Type().Name())
213213
}
214214
}
215215

Diff for: src/arduino.cc/builder/builder_utils/utils.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func compileFileWithRecipe(sourcePath string, source string, buildPath string, b
154154
return "", utils.WrapError(err)
155155
}
156156
} else if verbose {
157-
logger.Println(constants.MSG_USING_PREVIOUS_COMPILED_FILE, properties[constants.BUILD_PROPERTIES_OBJECT_FILE])
157+
logger.Println(constants.LOG_LEVEL_INFO, constants.MSG_USING_PREVIOUS_COMPILED_FILE, properties[constants.BUILD_PROPERTIES_OBJECT_FILE])
158158
}
159159

160160
return properties[constants.BUILD_PROPERTIES_OBJECT_FILE], nil

Diff for: src/arduino.cc/builder/constants/constants.go

+4
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ const LIBRARY_PROPERTIES = "library.properties"
201201
const LIBRARY_SENTENCE = "sentence"
202202
const LIBRARY_URL = "url"
203203
const LIBRARY_VERSION = "version"
204+
const LOG_LEVEL_DEBUG = "debug"
205+
const LOG_LEVEL_ERROR = "error"
206+
const LOG_LEVEL_INFO = "info"
207+
const LOG_LEVEL_WARN = "warn"
204208
const MSG_ARCH_FOLDER_NOT_SUPPORTED = "'arch' folder is no longer supported! See http://goo.gl/gfFJzU for more information"
205209
const MSG_BOARD_UNKNOWN = "Board {0} (platform {1}, package {2}) is unknown"
206210
const MSG_BOOTLOADER_FILE_MISSING = "Bootloader file specified but missing: {0}"

Diff for: src/arduino.cc/builder/ctags_parser.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func removeDefinedProtypes(tags []*types.CTag, context map[string]interface{}) {
118118
for _, tag := range tags {
119119
if definedPrototypes[tag.Prototype] {
120120
if utils.DebugLevel(context) >= 10 {
121-
utils.Logger(context).Fprintln(os.Stderr, constants.MSG_SKIPPING_TAG_ALREADY_DEFINED, tag.FunctionName)
121+
utils.Logger(context).Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, constants.MSG_SKIPPING_TAG_ALREADY_DEFINED, tag.FunctionName)
122122
}
123123
tag.SkipMe = true
124124
}
@@ -144,7 +144,7 @@ func skipTagsWhere(tags []*types.CTag, skipFunc skipFuncType, context map[string
144144
if !tag.SkipMe {
145145
skip := skipFunc(tag)
146146
if skip && utils.DebugLevel(context) >= 10 {
147-
utils.Logger(context).Fprintln(os.Stderr, constants.MSG_SKIPPING_TAG_WITH_REASON, tag.FunctionName, runtime.FuncForPC(reflect.ValueOf(skipFunc).Pointer()).Name())
147+
utils.Logger(context).Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, constants.MSG_SKIPPING_TAG_WITH_REASON, tag.FunctionName, runtime.FuncForPC(reflect.ValueOf(skipFunc).Pointer()).Name())
148148
}
149149
tag.SkipMe = skip
150150
}

Diff for: src/arduino.cc/builder/generate_buildpath_if_missing.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (s *GenerateBuildPathIfMissing) Run(context map[string]interface{}) error {
5656

5757
if utils.DebugLevel(context) > 5 {
5858
logger := context[constants.CTX_LOGGER].(i18n.Logger)
59-
logger.Fprintln(os.Stderr, constants.MSG_SETTING_BUILD_PATH, buildPath)
59+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_WARN, constants.MSG_SETTING_BUILD_PATH, buildPath)
6060
}
6161

6262
context[constants.CTX_BUILD_PATH] = buildPath

Diff for: src/arduino.cc/builder/i18n/i18n.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -43,29 +43,29 @@ import (
4343
var PLACEHOLDER = regexp.MustCompile("{(\\d)}")
4444

4545
type Logger interface {
46-
Fprintln(w io.Writer, format string, a ...interface{})
47-
Println(format string, a ...interface{})
46+
Fprintln(w io.Writer, level string, format string, a ...interface{})
47+
Println(level string, format string, a ...interface{})
4848
Name() string
4949
}
5050

5151
type NoopLogger struct{}
5252

53-
func (s NoopLogger) Fprintln(w io.Writer, format string, a ...interface{}) {}
53+
func (s NoopLogger) Fprintln(w io.Writer, level string, format string, a ...interface{}) {}
5454

55-
func (s NoopLogger) Println(format string, a ...interface{}) {}
55+
func (s NoopLogger) Println(level string, format string, a ...interface{}) {}
5656

5757
func (s NoopLogger) Name() string {
5858
return "noop"
5959
}
6060

6161
type HumanLogger struct{}
6262

63-
func (s HumanLogger) Fprintln(w io.Writer, format string, a ...interface{}) {
63+
func (s HumanLogger) Fprintln(w io.Writer, level string, format string, a ...interface{}) {
6464
fmt.Fprintln(w, Format(format, a...))
6565
}
6666

67-
func (s HumanLogger) Println(format string, a ...interface{}) {
68-
s.Fprintln(os.Stdout, Format(format, a...))
67+
func (s HumanLogger) Println(level string, format string, a ...interface{}) {
68+
s.Fprintln(os.Stdout, level, Format(format, a...))
6969
}
7070

7171
func (s HumanLogger) Name() string {
@@ -74,24 +74,24 @@ func (s HumanLogger) Name() string {
7474

7575
type MachineLogger struct{}
7676

77-
func (s MachineLogger) printWithoutFormatting(w io.Writer, format string, a []interface{}) {
77+
func (s MachineLogger) printWithoutFormatting(w io.Writer, level string, format string, a []interface{}) {
7878
a = append([]interface{}(nil), a...)
7979
for idx, value := range a {
8080
typeof := reflect.Indirect(reflect.ValueOf(value)).Kind()
8181
if typeof == reflect.String {
8282
a[idx] = url.QueryEscape(value.(string))
8383
}
8484
}
85-
fmt.Fprintf(w, "===%s ||| %s", format, a)
85+
fmt.Fprintf(w, "===%s ||| %s ||| %s", level, format, a)
8686
fmt.Fprintln(w)
8787
}
8888

89-
func (s MachineLogger) Fprintln(w io.Writer, format string, a ...interface{}) {
90-
s.printWithoutFormatting(w, format, a)
89+
func (s MachineLogger) Fprintln(w io.Writer, level string, format string, a ...interface{}) {
90+
s.printWithoutFormatting(w, level, format, a)
9191
}
9292

93-
func (s MachineLogger) Println(format string, a ...interface{}) {
94-
s.printWithoutFormatting(os.Stdout, format, a)
93+
func (s MachineLogger) Println(level string, format string, a ...interface{}) {
94+
s.printWithoutFormatting(os.Stdout, level, format, a)
9595
}
9696

9797
func (s MachineLogger) Name() string {

Diff for: src/arduino.cc/builder/libraries_loader.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func makeNewLibrary(libraryFolder string, debugLevel int, logger i18n.Logger) (*
153153
for _, subFolder := range subFolders {
154154
if utils.IsSCCSOrHiddenFile(subFolder) {
155155
if !utils.IsSCCSFile(subFolder) && utils.IsHiddenFile(subFolder) {
156-
logger.Fprintln(os.Stderr, constants.MSG_WARNING_SPURIOUS_FILE_IN_LIB, filepath.Base(subFolder.Name()), properties[constants.LIBRARY_NAME])
156+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_WARN, constants.MSG_WARNING_SPURIOUS_FILE_IN_LIB, filepath.Base(subFolder.Name()), properties[constants.LIBRARY_NAME])
157157
}
158158
}
159159
}
@@ -169,7 +169,7 @@ func makeNewLibrary(libraryFolder string, debugLevel int, logger i18n.Logger) (*
169169

170170
properties[constants.LIBRARY_CATEGORY] = strings.TrimSpace(properties[constants.LIBRARY_CATEGORY])
171171
if !LIBRARY_CATEGORIES[properties[constants.LIBRARY_CATEGORY]] {
172-
logger.Fprintln(os.Stderr, constants.MSG_WARNING_LIB_INVALID_CATEGORY, properties[constants.LIBRARY_CATEGORY], properties[constants.LIBRARY_NAME], constants.LIB_CATEGORY_UNCATEGORIZED)
172+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_WARN, constants.MSG_WARNING_LIB_INVALID_CATEGORY, properties[constants.LIBRARY_CATEGORY], properties[constants.LIBRARY_NAME], constants.LIB_CATEGORY_UNCATEGORIZED)
173173
properties[constants.LIBRARY_CATEGORY] = constants.LIB_CATEGORY_UNCATEGORIZED
174174
}
175175
library.Category = properties[constants.LIBRARY_CATEGORY]

Diff for: src/arduino.cc/builder/merge_sketch_with_bootloader.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (s *MergeSketchWithBootloader) Run(context map[string]interface{}) error {
7575

7676
bootloaderPath := filepath.Join(buildProperties[constants.BUILD_PROPERTIES_RUNTIME_PLATFORM_PATH], constants.FOLDER_BOOTLOADERS, bootloader)
7777
if _, err := os.Stat(bootloaderPath); err != nil {
78-
logger.Fprintln(os.Stderr, constants.MSG_BOOTLOADER_FILE_MISSING, bootloaderPath)
78+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_WARN, constants.MSG_BOOTLOADER_FILE_MISSING, bootloaderPath)
7979
return nil
8080
}
8181

Diff for: src/arduino.cc/builder/print_used_and_not_used_libraries.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ func (s *PrintUsedAndNotUsedLibraries) Run(context map[string]interface{}) error
5050

5151
for header, libResResult := range libraryResolutionResults {
5252
if !libResResult.IsLibraryFromPlatform {
53-
logger.Fprintln(os.Stderr, constants.MSG_LIBRARIES_MULTIPLE_LIBS_FOUND_FOR, header)
54-
logger.Fprintln(os.Stderr, constants.MSG_LIBRARIES_USED, libResResult.Library.Folder)
53+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_WARN, constants.MSG_LIBRARIES_MULTIPLE_LIBS_FOUND_FOR, header)
54+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_WARN, constants.MSG_LIBRARIES_USED, libResResult.Library.Folder)
5555
for _, notUsedLibrary := range libResResult.NotUsedLibraries {
56-
logger.Fprintln(os.Stderr, constants.MSG_LIBRARIES_NOT_USED, notUsedLibrary.Folder)
56+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_WARN, constants.MSG_LIBRARIES_NOT_USED, notUsedLibrary.Folder)
5757
}
5858
}
5959
}

Diff for: src/arduino.cc/builder/print_used_libraries_if_verbose.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ func (s *PrintUsedLibrariesIfVerbose) Run(context map[string]interface{}) error
5555
legacy = constants.MSG_LIB_LEGACY
5656
}
5757
if library.Version == constants.EMPTY_STRING {
58-
logger.Println(constants.MSG_USING_LIBRARY, library.Name, library.Folder, legacy)
58+
logger.Println(constants.LOG_LEVEL_INFO, constants.MSG_USING_LIBRARY, library.Name, library.Folder, legacy)
5959
} else {
60-
logger.Println(constants.MSG_USING_LIBRARY_AT_VERSION, library.Name, library.Version, library.Folder, legacy)
60+
logger.Println(constants.LOG_LEVEL_INFO, constants.MSG_USING_LIBRARY_AT_VERSION, library.Name, library.Version, library.Folder, legacy)
6161
}
6262
}
6363

Diff for: src/arduino.cc/builder/recipe_runner.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type RecipeByPrefixSuffixRunner struct {
4747
func (s *RecipeByPrefixSuffixRunner) Run(context map[string]interface{}) error {
4848
logger := context[constants.CTX_LOGGER].(i18n.Logger)
4949
if utils.DebugLevel(context) >= 10 {
50-
logger.Fprintln(os.Stderr, constants.MSG_LOOKING_FOR_RECIPES, s.Prefix, s.Suffix)
50+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, constants.MSG_LOOKING_FOR_RECIPES, s.Prefix, s.Suffix)
5151
}
5252

5353
buildProperties := utils.GetMapStringStringOrDefault(context, constants.CTX_BUILD_PROPERTIES)
@@ -58,7 +58,7 @@ func (s *RecipeByPrefixSuffixRunner) Run(context map[string]interface{}) error {
5858
properties := utils.MergeMapsOfStrings(make(map[string]string), buildProperties)
5959
for _, recipe := range recipes {
6060
if utils.DebugLevel(context) >= 10 {
61-
logger.Fprintln(os.Stderr, constants.MSG_RUNNING_RECIPE, recipe)
61+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, constants.MSG_RUNNING_RECIPE, recipe)
6262
}
6363
_, err := builder_utils.ExecRecipe(properties, recipe, false, verbose, verbose, logger)
6464
if err != nil {

Diff for: src/arduino.cc/builder/test/i18n_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
package test
3131

3232
import (
33+
"arduino.cc/builder/constants"
3334
"arduino.cc/builder/i18n"
3435
"fmt"
3536
"github.com/stretchr/testify/require"
@@ -64,8 +65,8 @@ func TestI18NSyntax(t *testing.T) {
6465
func TestI18NInheritance(t *testing.T) {
6566
var logger i18n.Logger
6667
logger = i18n.HumanLogger{}
67-
logger.Println("good {0} {1}", "morning", "vietnam!")
68+
logger.Println(constants.LOG_LEVEL_INFO, "good {0} {1}", "morning", "vietnam!")
6869

6970
logger = i18n.MachineLogger{}
70-
logger.Println("good {0} {1}", "morning", "vietnam!")
71+
logger.Println(constants.LOG_LEVEL_INFO, "good {0} {1}", "morning", "vietnam!")
7172
}

Diff for: src/arduino.cc/builder/utils/utils.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ func Errorf(context map[string]interface{}, format string, a ...interface{}) *er
296296

297297
func ErrorfWithLogger(log i18n.Logger, format string, a ...interface{}) *errors.Error {
298298
if log.Name() == "machine" {
299-
log.Fprintln(os.Stderr, format, a...)
299+
log.Fprintln(os.Stderr, constants.LOG_LEVEL_ERROR, format, a...)
300300
return errors.Errorf(constants.EMPTY_STRING)
301301
}
302302
return errors.Errorf(i18n.Format(format, a...))

Diff for: src/arduino.cc/builder/warn_about_arch_incompatible_libraries.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (s *WarnAboutArchIncompatibleLibraries) Run(context map[string]interface{})
6262
importedLibraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library)
6363
for _, importedLibrary := range importedLibraries {
6464
if !importedLibrary.SupportsArchitectures(archs) {
65-
logger.Fprintln(os.Stderr, constants.MSG_LIBRARY_INCOMPATIBLE_ARCH, importedLibrary.Name, importedLibrary.Archs, archs)
65+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_WARN, constants.MSG_LIBRARY_INCOMPATIBLE_ARCH, importedLibrary.Name, importedLibrary.Archs, archs)
6666
}
6767
}
6868

Diff for: src/arduino.cc/builder/warn_about_platform_rewrites.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (s *WarnAboutPlatformRewrites) Run(context map[string]interface{}) error {
5858
for _, platform := range platforms {
5959
if hardwareRewriteResults[platform] != nil {
6060
for _, rewrite := range hardwareRewriteResults[platform] {
61-
logger.Fprintln(os.Stderr, constants.MSG_WARNING_PLATFORM_OLD_VALUES, platform.Properties[constants.PLATFORM_NAME], rewrite.Key+"="+rewrite.OldValue, rewrite.Key+"="+rewrite.NewValue)
61+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_WARN, constants.MSG_WARNING_PLATFORM_OLD_VALUES, platform.Properties[constants.PLATFORM_NAME], rewrite.Key+"="+rewrite.OldValue, rewrite.Key+"="+rewrite.NewValue)
6262
}
6363
}
6464
}

Diff for: src/arduino.cc/builder/wipeout_build_path_if_build_options_changed.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (s *WipeoutBuildPathIfBuildOptionsChanged) Run(context map[string]interface
5353
return nil
5454
}
5555

56-
logger.Println(constants.MSG_BUILD_OPTIONS_CHANGED)
56+
logger.Println(constants.LOG_LEVEL_INFO, constants.MSG_BUILD_OPTIONS_CHANGED)
5757

5858
buildPath := context[constants.CTX_BUILD_PATH].(string)
5959
files, err := gohasissues.ReadDir(buildPath)

0 commit comments

Comments
 (0)