Skip to content

Commit

Permalink
Feat: option to silence verbose air logging using main_only in conf…
Browse files Browse the repository at this point in the history
…ig (#367)

* feat: silence air logging using main_only in config

* docs: update air_example with main_only usage
  • Loading branch information
hmerritt authored Jan 13, 2023
1 parent fafccf2 commit 26c752a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
2 changes: 2 additions & 0 deletions air_example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ args_bin = ["hello", "world"]
[log]
# Show log time
time = false
# Only show main log (silences watcher, build, runner)
main_only = false

[color]
# Customize each part's color. If no color found, use the raw app log.
Expand Down
6 changes: 4 additions & 2 deletions runner/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ func (c *cfgBuild) RegexCompiled() ([]*regexp.Regexp, error) {
}

type cfgLog struct {
AddTime bool `toml:"time"`
AddTime bool `toml:"time"`
MainOnly bool `toml:"main_only"`
}

type cfgColor struct {
Expand Down Expand Up @@ -223,7 +224,8 @@ func defaultConfig() Config {
build.Cmd = "go build -o ./tmp/main.exe ."
}
log := cfgLog{
AddTime: false,
AddTime: false,
MainOnly: false,
}
color := cfgColor{
Main: "magenta",
Expand Down
24 changes: 15 additions & 9 deletions runner/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,27 @@ func (e *Engine) mainDebug(format string, v ...interface{}) {
}

func (e *Engine) buildLog(format string, v ...interface{}) {
e.logWithLock(func() {
e.logger.build()(format, v...)
})
if e.debugMode || !e.config.Log.MainOnly {
e.logWithLock(func() {
e.logger.build()(format, v...)
})
}
}

func (e *Engine) runnerLog(format string, v ...interface{}) {
e.logWithLock(func() {
e.logger.runner()(format, v...)
})
if e.debugMode || !e.config.Log.MainOnly {
e.logWithLock(func() {
e.logger.runner()(format, v...)
})
}
}

func (e *Engine) watcherLog(format string, v ...interface{}) {
e.logWithLock(func() {
e.logger.watcher()(format, v...)
})
if e.debugMode || !e.config.Log.MainOnly {
e.logWithLock(func() {
e.logger.watcher()(format, v...)
})
}
}

func (e *Engine) watcherDebug(format string, v ...interface{}) {
Expand Down

0 comments on commit 26c752a

Please sign in to comment.