Skip to content

Commit 2dee1c3

Browse files
committed
Create a new logger to display message tags and human format
Signed-off-by: Matteo Suppo <[email protected]>
1 parent bc2c38f commit 2dee1c3

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ This tool generates function prototypes and gathers library paths, providing `gc
3333

3434
* `-core-api-version`: Optional, defaults to "10600". The version of the Arduino IDE which is using this tool.
3535

36-
* `-logger`: Optional, can be "human" or "machine". Defaults to "human". If "machine", messages emitted will be in a format which the Arduino IDE understands and that it uses for I18N.
36+
* `-logger`: Optional, can be "human", "humantags" or "machine". Defaults to "human". If "humantags" the messages are qualified with a prefix that indicates their level (info, debug, error). If "machine", messages emitted will be in a format which the Arduino IDE understands and that it uses for I18N.
3737

3838
* `-version`: if specified, prints version and exits.
3939

src/arduino.cc/arduino-builder/main.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ const FLAG_WARNINGS_MORE = "more"
7474
const FLAG_WARNINGS_ALL = "all"
7575
const FLAG_LOGGER = "logger"
7676
const FLAG_LOGGER_HUMAN = "human"
77+
const FLAG_LOGGER_HUMANTAGS = "humantags"
7778
const FLAG_LOGGER_MACHINE = "machine"
7879
const FLAG_VERSION = "version"
7980
const FLAG_VID_PID = "vid-pid"
@@ -152,7 +153,7 @@ func init() {
152153
quietFlag = flag.Bool(FLAG_QUIET, false, "if 'true' doesn't print any warnings or progress or whatever")
153154
debugLevelFlag = flag.Int(FLAG_DEBUG_LEVEL, builder.DEFAULT_DEBUG_LEVEL, "Turns on debugging messages. The higher, the chattier")
154155
warningsLevelFlag = flag.String(FLAG_WARNINGS, "", "Sets warnings level. Available values are '"+FLAG_WARNINGS_NONE+"', '"+FLAG_WARNINGS_DEFAULT+"', '"+FLAG_WARNINGS_MORE+"' and '"+FLAG_WARNINGS_ALL+"'")
155-
loggerFlag = flag.String(FLAG_LOGGER, FLAG_LOGGER_HUMAN, "Sets type of logger. Available values are '"+FLAG_LOGGER_HUMAN+"', '"+FLAG_LOGGER_MACHINE+"'")
156+
loggerFlag = flag.String(FLAG_LOGGER, FLAG_LOGGER_HUMAN, "Sets type of logger. Available values are '"+FLAG_LOGGER_HUMAN+"', '"+FLAG_LOGGER_HUMANTAGS+"', '"+FLAG_LOGGER_MACHINE+"'")
156157
versionFlag = flag.Bool(FLAG_VERSION, false, "prints version and exits")
157158
vidPidFlag = flag.String(FLAG_VID_PID, "", "specify to use vid/pid specific build properties, as defined in boards.txt")
158159
}
@@ -299,6 +300,8 @@ func main() {
299300
ctx.SetLogger(i18n.NoopLogger{})
300301
} else if *loggerFlag == FLAG_LOGGER_MACHINE {
301302
ctx.SetLogger(i18n.MachineLogger{})
303+
} else if *loggerFlag == FLAG_LOGGER_HUMANTAGS {
304+
ctx.SetLogger(i18n.HumanTagsLogger{})
302305
} else {
303306
ctx.SetLogger(i18n.HumanLogger{})
304307
}

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

+15
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,21 @@ func (s NoopLogger) Name() string {
5858
return "noop"
5959
}
6060

61+
type HumanTagsLogger struct{}
62+
63+
func (s HumanTagsLogger) Fprintln(w io.Writer, level string, format string, a ...interface{}) {
64+
format = "[" + level + "] " + format
65+
fmt.Fprintln(w, Format(format, a...))
66+
}
67+
68+
func (s HumanTagsLogger) Println(level string, format string, a ...interface{}) {
69+
s.Fprintln(os.Stdout, level, format, a...)
70+
}
71+
72+
func (s HumanTagsLogger) Name() string {
73+
return "humantags"
74+
}
75+
6176
type HumanLogger struct{}
6277

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

0 commit comments

Comments
 (0)