Skip to content

Commit 0052d78

Browse files
Allow log.xxx.default to set logging settings for the default logger only (#11292)
* Allow log.xxx.default to set logging settings for the default logger only Signed-off-by: Andrew Thornton <[email protected]> * Update modules/setting/log.go * as per @silverwind add some documentation Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: techknowlogick <[email protected]>
1 parent 1d54479 commit 0052d78

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

docs/content/doc/advanced/logging-documentation.en-us.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ Calls to `log.Info`, `log.Debug`, `log.Error` etc. from the `code.gitea.io/gitea
4848
You can configure the outputs of this logger by setting the `MODE`
4949
value in the `[log]` section of the configuration.
5050

51-
Each output sublogger is configured in a separate `[log.sublogger]`
52-
section, but there are certain default values. These will not be inherited from the `[log]` section:
51+
Each output sublogger is configured in a separate `[log.sublogger.default]`
52+
which inherits from the sublogger `[log.sublogger]` section and from the
53+
generic `[log]` section, but there are certain default values. These will
54+
not be inherited from the `[log]` section:
5355

5456
* `FLAGS` is `stdflags` (Equal to
5557
`date,time,medfile,shortfuncname,levelinitial`)
@@ -70,6 +72,9 @@ section which you can configure the outputs of by setting the `MACARON`
7072
value in the `[log]` section of the configuration. `MACARON` defaults
7173
to `file` if unset.
7274

75+
Please note, the macaron logger will log at `INFO` level, setting the
76+
`LEVEL` of this logger to `WARN` or above will result in no macaron logs.
77+
7378
Each output sublogger for this logger is configured in
7479
`[log.sublogger.macaron]` sections. There are certain default values
7580
which will not be inherited from the `[log]` or relevant
@@ -98,6 +103,9 @@ Router logs the same data as the Macaron log but has slightly different
98103
coloring. It logs at the `Info` level by default, but this can be
99104
changed if desired by setting the `ROUTER_LOG_LEVEL` value.
100105

106+
Please note, setting the `LEVEL` of this logger to a level above
107+
`ROUTER_LOG_LEVEL` will result in no router logs.
108+
101109
Each output sublogger for this logger is configured in
102110
`[log.sublogger.router]` sections. There are certain default values
103111
which will not be inherited from the `[log]` or relevant
@@ -136,6 +144,9 @@ which will not be inherited from the `[log]` or relevant
136144
If desired the format of the Access logger can be changed by changing
137145
the value of the `ACCESS_LOG_TEMPLATE`.
138146

147+
Please note, the access logger will log at `INFO` level, setting the
148+
`LEVEL` of this logger to `WARN` or above will result in no access logs.
149+
139150
NB: You can redirect the access logger to send its events to the Gitea
140151
log using the value: `ACCESS = ,`
141152

modules/setting/log.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,12 @@ func newLogService() {
261261
continue
262262
}
263263

264-
sec, err := Cfg.GetSection("log." + name)
264+
sec, err := Cfg.GetSection("log." + name + ".default")
265265
if err != nil {
266-
sec, _ = Cfg.NewSection("log." + name)
266+
sec, err = Cfg.GetSection("log." + name)
267+
if err != nil {
268+
sec, _ = Cfg.NewSection("log." + name)
269+
}
267270
}
268271

269272
provider, config, levelName := generateLogConfig(sec, name, options)

0 commit comments

Comments
 (0)