Add configuration option to disable access logging

Access logging is great.  Access logging you can turn off is even
better.  This change adds a configuration option for that.

Signed-off-by: Noah Treuhaft <noah.treuhaft@docker.com>
This commit is contained in:
Noah Treuhaft 2016-09-13 17:23:27 -07:00
parent 17fb0bb6b3
commit 4034ff65f0
4 changed files with 28 additions and 2 deletions

View file

@ -22,6 +22,12 @@ type Configuration struct {
// Log supports setting various parameters related to the logging // Log supports setting various parameters related to the logging
// subsystem. // subsystem.
Log struct { Log struct {
// AccessLog configures access logging.
AccessLog struct {
// Disabled disables access logging.
Disabled bool `yaml:"disabled,omitempty"`
} `yaml:"accesslog,omitempty"`
// Level is the granularity at which registry operations are logged. // Level is the granularity at which registry operations are logged.
Level Loglevel `yaml:"level"` Level Loglevel `yaml:"level"`

View file

@ -19,6 +19,9 @@ func Test(t *testing.T) { TestingT(t) }
var configStruct = Configuration{ var configStruct = Configuration{
Version: "0.1", Version: "0.1",
Log: struct { Log: struct {
AccessLog struct {
Disabled bool `yaml:"disabled,omitempty"`
} `yaml:"accesslog,omitempty"`
Level Loglevel `yaml:"level"` Level Loglevel `yaml:"level"`
Formatter string `yaml:"formatter,omitempty"` Formatter string `yaml:"formatter,omitempty"`
Fields map[string]interface{} `yaml:"fields,omitempty"` Fields map[string]interface{} `yaml:"fields,omitempty"`

View file

@ -55,6 +55,8 @@ information about each option that appears later in this page.
version: 0.1 version: 0.1
log: log:
accesslog:
disabled: true
level: debug level: debug
formatter: text formatter: text
fields: fields:
@ -280,6 +282,8 @@ system outputs everything to stdout. You can adjust the granularity and format
with this configuration section. with this configuration section.
log: log:
accesslog:
disabled: true
level: debug level: debug
formatter: text formatter: text
fields: fields:
@ -318,7 +322,7 @@ with this configuration section.
<code>logstash</code>. The default is <code>text</code>. <code>logstash</code>. The default is <code>text</code>.
</td> </td>
</tr> </tr>
<tr> <tr>
<td> <td>
<code>fields</code> <code>fields</code>
</td> </td>
@ -330,8 +334,19 @@ with this configuration section.
the context. This is useful for identifying log messages source after the context. This is useful for identifying log messages source after
being mixed in other systems. being mixed in other systems.
</td> </td>
</tr>
</table> </table>
### accesslog
accesslog:
disabled: true
Within `log`, `accesslog` configures the behavior of the access logging
system. By default, the access logging system outputs to stdout in
[Combined Log Format](https://httpd.apache.org/docs/2.4/logs.html#combined).
Access logging can be disabled by setting the boolean flag `disabled` to `true`.
## hooks ## hooks
hooks: hooks:

View file

@ -91,7 +91,9 @@ func NewRegistry(ctx context.Context, config *configuration.Configuration) (*Reg
handler = alive("/", handler) handler = alive("/", handler)
handler = health.Handler(handler) handler = health.Handler(handler)
handler = panicHandler(handler) handler = panicHandler(handler)
handler = gorhandlers.CombinedLoggingHandler(os.Stdout, handler) if !config.Log.AccessLog.Disabled {
handler = gorhandlers.CombinedLoggingHandler(os.Stdout, handler)
}
server := &http.Server{ server := &http.Server{
Handler: handler, Handler: handler,