From 3a4509bbf6186d33d44e017d3802b0df388108e4 Mon Sep 17 00:00:00 2001 From: Kyle Date: Tue, 22 Sep 2015 22:44:01 -0700 Subject: [PATCH] More docs, global SetLevel. --- logging/log.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/logging/log.go b/logging/log.go index 41606e4..cadd898 100644 --- a/logging/log.go +++ b/logging/log.go @@ -9,6 +9,19 @@ // can be suppressed with Suppress, and re-enabled with Enable. There // are prefixed versions of these as well. // +// Packages (e.g. those meant to be imported by programs) using the +// loggers here should observe a few etiquette guides: +// +// 1. A package should never suppress or enable other loggers except +// via an exported function that should be called by the end user. +// +// 2. A package should never call the global `SetLevel`; this is +// reserved for the end user. +// +// 3. Packages should use consistent, sane domains: preferably, +// related packages should use an unsurprising common prefix in their +// domains. +// // This package was adapted from the CFSSL logging code. package logging @@ -30,6 +43,16 @@ var logConfig = struct { lock: new(sync.Mutex), } +// SetLevel sets the logging level for all loggers. +func SetLevel(level Level) { + logConfig.lock.Lock() + defer logConfig.lock.Unlock() + + for _, l := range logConfig.registered { + l.SetLevel(level) + } +} + // DefaultLevel defaults to the notice level of logging. const DefaultLevel = LevelNotice