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

src/arduino.cc/builder/add_build_board_property_if_missing.go

Lines changed: 1 addition & 1 deletion
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
}

src/arduino.cc/builder/builder.go

Lines changed: 2 additions & 2 deletions
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

src/arduino.cc/builder/builder_utils/utils.go

Lines changed: 1 addition & 1 deletion
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

src/arduino.cc/builder/constants/constants.go

Lines changed: 4 additions & 0 deletions
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}"

src/arduino.cc/builder/ctags_parser.go

Lines changed: 2 additions & 2 deletions
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
}

src/arduino.cc/builder/generate_buildpath_if_missing.go

Lines changed: 1 addition & 1 deletion
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

src/arduino.cc/builder/i18n/i18n.go

Lines changed: 13 additions & 13 deletions
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 {

src/arduino.cc/builder/libraries_loader.go

Lines changed: 2 additions & 2 deletions
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]

src/arduino.cc/builder/merge_sketch_with_bootloader.go

Lines changed: 1 addition & 1 deletion
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

src/arduino.cc/builder/print_used_and_not_used_libraries.go

Lines changed: 3 additions & 3 deletions
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
}

0 commit comments

Comments
 (0)