summaryrefslogtreecommitdiff
path: root/flags.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-01-04 15:22:08 -0600
committerJeff Carr <[email protected]>2024-01-04 15:22:08 -0600
commit29db278b6aaa209c5b2f8b6a0dbbc4b726a4323e (patch)
tree08f5d410c504cc6a01d615669c72a5369979b80d /flags.go
parent9b46482ad0da5e4b965debdb815ebcd89a666d89 (diff)
SetDefaults()
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'flags.go')
-rw-r--r--flags.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/flags.go b/flags.go
index 45d57bd..e885e24 100644
--- a/flags.go
+++ b/flags.go
@@ -20,6 +20,7 @@ var flagsMutex sync.Mutex
type LogFlag struct {
B bool
+ Default bool // set at the time of Registration()
Name string
Subsystem string
Desc string
@@ -74,6 +75,14 @@ func SetAll(b bool) {
}
}
+// set all the flags
+func SetDefaults() {
+ flagsMutex.Lock()
+ defer flagsMutex.Unlock()
+ for _, f := range flags {
+ f.B = f.Default
+ }
+}
// this bypasses all checks and _always_ logs the info to STDOUT
// is this a bad idea? Probably not....
@@ -103,10 +112,12 @@ func ProcessFlags(callback func(*LogFlag)) {
// register a variable name from a subsystem
// inspired by Alex Flint
+// set the Default value at the time of registration
func (f *LogFlag) Register() {
flagsMutex.Lock()
defer flagsMutex.Unlock()
Info("log.Register() ", f)
+ f.Default = f.B
flags = append(flags,f)
}