Skip to content

Commit

Permalink
Introducing log levels. ALL messages are now printed on stdout, with …
Browse files Browse the repository at this point in the history
…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]>
  • Loading branch information
Federico Fissore committed Dec 10, 2015
1 parent 2f78246 commit 4be87e5
Show file tree
Hide file tree
Showing 17 changed files with 41 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (s *AddBuildBoardPropertyIfMissing) Run(context map[string]interface{}) err
for _, board := range platform.Boards {
if board.Properties[constants.BUILD_PROPERTIES_BUILD_BOARD] == constants.EMPTY_STRING {
board.Properties[constants.BUILD_PROPERTIES_BUILD_BOARD] = strings.ToUpper(platform.PlatformId + "_" + board.BoardId)
logger.Fprintln(os.Stderr, constants.MSG_MISSING_BUILD_BOARD, aPackage.PackageId, platform.PlatformId, board.BoardId, board.Properties[constants.BUILD_PROPERTIES_BUILD_BOARD])
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])
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/arduino.cc/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,13 @@ func printProgressIfProgressEnabledAndMachineLogger(progressEnabled bool, contex

log := utils.Logger(context)
if log.Name() == "machine" {
log.Println(constants.MSG_PROGRESS, strconv.FormatFloat(float64(progress), 'f', 2, 32))
log.Println(constants.LOG_LEVEL_INFO, constants.MSG_PROGRESS, strconv.FormatFloat(float64(progress), 'f', 2, 32))
}
}

func PrintRingNameIfDebug(context map[string]interface{}, command types.Command) {
if utils.DebugLevel(context) >= 10 {
utils.Logger(context).Fprintln(os.Stderr, constants.MSG_RUNNING_COMMAND, strconv.FormatInt(time.Now().Unix(), 10), reflect.Indirect(reflect.ValueOf(command)).Type().Name())
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())
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/arduino.cc/builder/builder_utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func compileFileWithRecipe(sourcePath string, source string, buildPath string, b
return "", utils.WrapError(err)
}
} else if verbose {
logger.Println(constants.MSG_USING_PREVIOUS_COMPILED_FILE, properties[constants.BUILD_PROPERTIES_OBJECT_FILE])
logger.Println(constants.LOG_LEVEL_INFO, constants.MSG_USING_PREVIOUS_COMPILED_FILE, properties[constants.BUILD_PROPERTIES_OBJECT_FILE])
}

return properties[constants.BUILD_PROPERTIES_OBJECT_FILE], nil
Expand Down
4 changes: 4 additions & 0 deletions src/arduino.cc/builder/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ const LIBRARY_PROPERTIES = "library.properties"
const LIBRARY_SENTENCE = "sentence"
const LIBRARY_URL = "url"
const LIBRARY_VERSION = "version"
const LOG_LEVEL_DEBUG = "debug"
const LOG_LEVEL_ERROR = "error"
const LOG_LEVEL_INFO = "info"
const LOG_LEVEL_WARN = "warn"
const MSG_ARCH_FOLDER_NOT_SUPPORTED = "'arch' folder is no longer supported! See http://goo.gl/gfFJzU for more information"
const MSG_BOARD_UNKNOWN = "Board {0} (platform {1}, package {2}) is unknown"
const MSG_BOOTLOADER_FILE_MISSING = "Bootloader file specified but missing: {0}"
Expand Down
4 changes: 2 additions & 2 deletions src/arduino.cc/builder/ctags_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func removeDefinedProtypes(tags []*types.CTag, context map[string]interface{}) {
for _, tag := range tags {
if definedPrototypes[tag.Prototype] {
if utils.DebugLevel(context) >= 10 {
utils.Logger(context).Fprintln(os.Stderr, constants.MSG_SKIPPING_TAG_ALREADY_DEFINED, tag.FunctionName)
utils.Logger(context).Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, constants.MSG_SKIPPING_TAG_ALREADY_DEFINED, tag.FunctionName)
}
tag.SkipMe = true
}
Expand All @@ -144,7 +144,7 @@ func skipTagsWhere(tags []*types.CTag, skipFunc skipFuncType, context map[string
if !tag.SkipMe {
skip := skipFunc(tag)
if skip && utils.DebugLevel(context) >= 10 {
utils.Logger(context).Fprintln(os.Stderr, constants.MSG_SKIPPING_TAG_WITH_REASON, tag.FunctionName, runtime.FuncForPC(reflect.ValueOf(skipFunc).Pointer()).Name())
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())
}
tag.SkipMe = skip
}
Expand Down
2 changes: 1 addition & 1 deletion src/arduino.cc/builder/generate_buildpath_if_missing.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (s *GenerateBuildPathIfMissing) Run(context map[string]interface{}) error {

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

context[constants.CTX_BUILD_PATH] = buildPath
Expand Down
26 changes: 13 additions & 13 deletions src/arduino.cc/builder/i18n/i18n.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,29 @@ import (
var PLACEHOLDER = regexp.MustCompile("{(\\d)}")

type Logger interface {
Fprintln(w io.Writer, format string, a ...interface{})
Println(format string, a ...interface{})
Fprintln(w io.Writer, level string, format string, a ...interface{})
Println(level string, format string, a ...interface{})
Name() string
}

type NoopLogger struct{}

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

func (s NoopLogger) Println(format string, a ...interface{}) {}
func (s NoopLogger) Println(level string, format string, a ...interface{}) {}

func (s NoopLogger) Name() string {
return "noop"
}

type HumanLogger struct{}

func (s HumanLogger) Fprintln(w io.Writer, format string, a ...interface{}) {
func (s HumanLogger) Fprintln(w io.Writer, level string, format string, a ...interface{}) {
fmt.Fprintln(w, Format(format, a...))
}

func (s HumanLogger) Println(format string, a ...interface{}) {
s.Fprintln(os.Stdout, Format(format, a...))
func (s HumanLogger) Println(level string, format string, a ...interface{}) {
s.Fprintln(os.Stdout, level, Format(format, a...))
}

func (s HumanLogger) Name() string {
Expand All @@ -74,24 +74,24 @@ func (s HumanLogger) Name() string {

type MachineLogger struct{}

func (s MachineLogger) printWithoutFormatting(w io.Writer, format string, a []interface{}) {
func (s MachineLogger) printWithoutFormatting(w io.Writer, level string, format string, a []interface{}) {
a = append([]interface{}(nil), a...)
for idx, value := range a {
typeof := reflect.Indirect(reflect.ValueOf(value)).Kind()
if typeof == reflect.String {
a[idx] = url.QueryEscape(value.(string))
}
}
fmt.Fprintf(w, "===%s ||| %s", format, a)
fmt.Fprintf(w, "===%s ||| %s ||| %s", level, format, a)
fmt.Fprintln(w)
}

func (s MachineLogger) Fprintln(w io.Writer, format string, a ...interface{}) {
s.printWithoutFormatting(w, format, a)
func (s MachineLogger) Fprintln(w io.Writer, level string, format string, a ...interface{}) {
s.printWithoutFormatting(w, level, format, a)
}

func (s MachineLogger) Println(format string, a ...interface{}) {
s.printWithoutFormatting(os.Stdout, format, a)
func (s MachineLogger) Println(level string, format string, a ...interface{}) {
s.printWithoutFormatting(os.Stdout, level, format, a)
}

func (s MachineLogger) Name() string {
Expand Down
4 changes: 2 additions & 2 deletions src/arduino.cc/builder/libraries_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func makeNewLibrary(libraryFolder string, debugLevel int, logger i18n.Logger) (*
for _, subFolder := range subFolders {
if utils.IsSCCSOrHiddenFile(subFolder) {
if !utils.IsSCCSFile(subFolder) && utils.IsHiddenFile(subFolder) {
logger.Fprintln(os.Stderr, constants.MSG_WARNING_SPURIOUS_FILE_IN_LIB, filepath.Base(subFolder.Name()), properties[constants.LIBRARY_NAME])
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_WARN, constants.MSG_WARNING_SPURIOUS_FILE_IN_LIB, filepath.Base(subFolder.Name()), properties[constants.LIBRARY_NAME])
}
}
}
Expand All @@ -169,7 +169,7 @@ func makeNewLibrary(libraryFolder string, debugLevel int, logger i18n.Logger) (*

properties[constants.LIBRARY_CATEGORY] = strings.TrimSpace(properties[constants.LIBRARY_CATEGORY])
if !LIBRARY_CATEGORIES[properties[constants.LIBRARY_CATEGORY]] {
logger.Fprintln(os.Stderr, constants.MSG_WARNING_LIB_INVALID_CATEGORY, properties[constants.LIBRARY_CATEGORY], properties[constants.LIBRARY_NAME], constants.LIB_CATEGORY_UNCATEGORIZED)
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)
properties[constants.LIBRARY_CATEGORY] = constants.LIB_CATEGORY_UNCATEGORIZED
}
library.Category = properties[constants.LIBRARY_CATEGORY]
Expand Down
2 changes: 1 addition & 1 deletion src/arduino.cc/builder/merge_sketch_with_bootloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (s *MergeSketchWithBootloader) Run(context map[string]interface{}) error {

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

Expand Down
6 changes: 3 additions & 3 deletions src/arduino.cc/builder/print_used_and_not_used_libraries.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ func (s *PrintUsedAndNotUsedLibraries) Run(context map[string]interface{}) error

for header, libResResult := range libraryResolutionResults {
if !libResResult.IsLibraryFromPlatform {
logger.Fprintln(os.Stderr, constants.MSG_LIBRARIES_MULTIPLE_LIBS_FOUND_FOR, header)
logger.Fprintln(os.Stderr, constants.MSG_LIBRARIES_USED, libResResult.Library.Folder)
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_WARN, constants.MSG_LIBRARIES_MULTIPLE_LIBS_FOUND_FOR, header)
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_WARN, constants.MSG_LIBRARIES_USED, libResResult.Library.Folder)
for _, notUsedLibrary := range libResResult.NotUsedLibraries {
logger.Fprintln(os.Stderr, constants.MSG_LIBRARIES_NOT_USED, notUsedLibrary.Folder)
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_WARN, constants.MSG_LIBRARIES_NOT_USED, notUsedLibrary.Folder)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/arduino.cc/builder/print_used_libraries_if_verbose.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ func (s *PrintUsedLibrariesIfVerbose) Run(context map[string]interface{}) error
legacy = constants.MSG_LIB_LEGACY
}
if library.Version == constants.EMPTY_STRING {
logger.Println(constants.MSG_USING_LIBRARY, library.Name, library.Folder, legacy)
logger.Println(constants.LOG_LEVEL_INFO, constants.MSG_USING_LIBRARY, library.Name, library.Folder, legacy)
} else {
logger.Println(constants.MSG_USING_LIBRARY_AT_VERSION, library.Name, library.Version, library.Folder, legacy)
logger.Println(constants.LOG_LEVEL_INFO, constants.MSG_USING_LIBRARY_AT_VERSION, library.Name, library.Version, library.Folder, legacy)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/arduino.cc/builder/recipe_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type RecipeByPrefixSuffixRunner struct {
func (s *RecipeByPrefixSuffixRunner) Run(context map[string]interface{}) error {
logger := context[constants.CTX_LOGGER].(i18n.Logger)
if utils.DebugLevel(context) >= 10 {
logger.Fprintln(os.Stderr, constants.MSG_LOOKING_FOR_RECIPES, s.Prefix, s.Suffix)
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, constants.MSG_LOOKING_FOR_RECIPES, s.Prefix, s.Suffix)
}

buildProperties := utils.GetMapStringStringOrDefault(context, constants.CTX_BUILD_PROPERTIES)
Expand All @@ -58,7 +58,7 @@ func (s *RecipeByPrefixSuffixRunner) Run(context map[string]interface{}) error {
properties := utils.MergeMapsOfStrings(make(map[string]string), buildProperties)
for _, recipe := range recipes {
if utils.DebugLevel(context) >= 10 {
logger.Fprintln(os.Stderr, constants.MSG_RUNNING_RECIPE, recipe)
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_DEBUG, constants.MSG_RUNNING_RECIPE, recipe)
}
_, err := builder_utils.ExecRecipe(properties, recipe, false, verbose, verbose, logger)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions src/arduino.cc/builder/test/i18n_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
package test

import (
"arduino.cc/builder/constants"
"arduino.cc/builder/i18n"
"fmt"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -64,8 +65,8 @@ func TestI18NSyntax(t *testing.T) {
func TestI18NInheritance(t *testing.T) {
var logger i18n.Logger
logger = i18n.HumanLogger{}
logger.Println("good {0} {1}", "morning", "vietnam!")
logger.Println(constants.LOG_LEVEL_INFO, "good {0} {1}", "morning", "vietnam!")

logger = i18n.MachineLogger{}
logger.Println("good {0} {1}", "morning", "vietnam!")
logger.Println(constants.LOG_LEVEL_INFO, "good {0} {1}", "morning", "vietnam!")
}
2 changes: 1 addition & 1 deletion src/arduino.cc/builder/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func Errorf(context map[string]interface{}, format string, a ...interface{}) *er

func ErrorfWithLogger(log i18n.Logger, format string, a ...interface{}) *errors.Error {
if log.Name() == "machine" {
log.Fprintln(os.Stderr, format, a...)
log.Fprintln(os.Stderr, constants.LOG_LEVEL_ERROR, format, a...)
return errors.Errorf(constants.EMPTY_STRING)
}
return errors.Errorf(i18n.Format(format, a...))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (s *WarnAboutArchIncompatibleLibraries) Run(context map[string]interface{})
importedLibraries := context[constants.CTX_IMPORTED_LIBRARIES].([]*types.Library)
for _, importedLibrary := range importedLibraries {
if !importedLibrary.SupportsArchitectures(archs) {
logger.Fprintln(os.Stderr, constants.MSG_LIBRARY_INCOMPATIBLE_ARCH, importedLibrary.Name, importedLibrary.Archs, archs)
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_WARN, constants.MSG_LIBRARY_INCOMPATIBLE_ARCH, importedLibrary.Name, importedLibrary.Archs, archs)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/arduino.cc/builder/warn_about_platform_rewrites.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (s *WarnAboutPlatformRewrites) Run(context map[string]interface{}) error {
for _, platform := range platforms {
if hardwareRewriteResults[platform] != nil {
for _, rewrite := range hardwareRewriteResults[platform] {
logger.Fprintln(os.Stderr, constants.MSG_WARNING_PLATFORM_OLD_VALUES, platform.Properties[constants.PLATFORM_NAME], rewrite.Key+"="+rewrite.OldValue, rewrite.Key+"="+rewrite.NewValue)
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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (s *WipeoutBuildPathIfBuildOptionsChanged) Run(context map[string]interface
return nil
}

logger.Println(constants.MSG_BUILD_OPTIONS_CHANGED)
logger.Println(constants.LOG_LEVEL_INFO, constants.MSG_BUILD_OPTIONS_CHANGED)

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

0 comments on commit 4be87e5

Please sign in to comment.