Merge pull request 'feat: add configurable logging level for jobs' (#299) from xenrox/runner:job-logging-level into main

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/299
Reviewed-by: earl-warren <earl-warren@noreply.code.forgejo.org>
This commit is contained in:
earl-warren 2024-11-03 07:45:07 +00:00
commit b76cd576ef
5 changed files with 27 additions and 1 deletions

View file

@ -1,5 +1,9 @@
# Release Notes
## 4.1.0
* [Add job_level logging option to config](https://code.forgejo.org/forgejo/runner/pulls/299) to make the logging level of jobs configurable. Change default from "trace" to "info".
## 4.0.1
* Do not panic when [the number of arguments of a function evaluated in an expression is incorect](https://code.forgejo.org/forgejo/act/pulls/59/files).

View file

@ -232,6 +232,15 @@ func (r *Runner) run(ctx context.Context, task *runnerv1.Task, reporter *report.
Inputs: inputs,
}
if r.cfg.Log.JobLevel != "" {
level, err := log.ParseLevel(r.cfg.Log.JobLevel)
if err != nil {
return err
}
runnerConfig.JobLoggerLevel = &level
}
rr, err := runner.New(runnerConfig)
if err != nil {
return err

View file

@ -6,6 +6,8 @@
log:
# The level of logging, can be trace, debug, info, warn, error, fatal
level: info
# The level of logging for jobs, can be trace, debug, info, earn, error, fatal
job_level: info
runner:
# Where to store the registration result.

View file

@ -16,7 +16,8 @@ import (
// Log represents the configuration for logging.
type Log struct {
Level string `yaml:"level"` // Level indicates the logging level.
Level string `yaml:"level"` // Level indicates the logging level.
JobLevel string `yaml:"job_level"` // JobLevel indicates the job logging level.
}
// Runner represents the configuration for the runner.
@ -113,6 +114,9 @@ func LoadDefault(file string) (*Config, error) {
if cfg.Log.Level == "" {
cfg.Log.Level = "info"
}
if cfg.Log.JobLevel == "" {
cfg.Log.JobLevel = "info"
}
if cfg.Runner.File == "" {
cfg.Runner.File = ".runner"
}

View file

@ -35,3 +35,10 @@ func TestConfigTune(t *testing.T) {
assert.EqualValues(t, 2*time.Second, c.Runner.FetchInterval)
})
}
func TestDefaultSettings(t *testing.T) {
config, err := LoadDefault("")
assert.NoError(t, err)
assert.EqualValues(t, config.Log.JobLevel, "info")
}