diff options
| author | Jeff Carr <[email protected]> | 2024-11-07 01:23:43 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-11-07 01:23:43 -0600 |
| commit | ef61eb494b42a7bc226de1edc114579ce530abdd (patch) | |
| tree | 0bd23b52a8aae23806d8cdc9896936c39cd07728 /flags.go | |
| parent | 2b11a4e334f465aef868d6c1bf3f1a7c9dfd5c27 (diff) | |
try allowing switching to writing to httpv0.22.2
Diffstat (limited to 'flags.go')
| -rw-r--r-- | flags.go | 83 |
1 files changed, 49 insertions, 34 deletions
@@ -25,19 +25,18 @@ package log */ - - -import ( +import ( + "net/http" "sync" ) -var INFO *LogFlag // toggles log.Info() -var VERBOSE *LogFlag // toggles log.Verbose() -var SPEW *LogFlag // toggles log.Spew() +var INFO *LogFlag // toggles log.Info() +var VERBOSE *LogFlag // toggles log.Verbose() +var SPEW *LogFlag // toggles log.Spew() -var WARN *LogFlag // toggles log.Warn() (true by default) -var ERROR *LogFlag // toggles log.Warn() (true by default) -var PRINTLN *LogFlag // toggles log.Println() (true by default) +var WARN *LogFlag // toggles log.Warn() (true by default) +var ERROR *LogFlag // toggles log.Warn() (true by default) +var PRINTLN *LogFlag // toggles log.Println() (true by default) var always *LogFlag var allon bool = false @@ -46,18 +45,18 @@ var allon bool = false var flagsMutex sync.Mutex type LogFlag struct { - b bool - orig bool // used as the Default value. set at the time of Registration() - name string + b bool + orig bool // used as the Default value. set at the time of Registration() + name string // TODO: figure out what package is sending the Registration - subsystem string // probably should just be forced to be the package name - short string // string actually printed on each line - desc string + subsystem string // probably should just be forced to be the package name + short string // string actually printed on each line + desc string } var flags []*LogFlag var daemonMode bool - +var httpMode http.ResponseWriter func init() { full := "go.wit.com/log" @@ -75,16 +74,18 @@ func init() { INFO = NewFlag("INFO", true, full, short, "Enable log.Info()") SPEW = NewFlag("SPEW", false, full, short, "Enable log.Spew()") - WARN = NewFlag("WARN", true, full, short, "Enable log.Warn()") + WARN = NewFlag("WARN", true, full, short, "Enable log.Warn()") - ERROR = NewFlag("ERROR", true, full, short, "Enable log.Error()") - PRINTLN = NewFlag("PRINTLN", true, full, short, "Enable log.Println()") - VERBOSE = NewFlag("VERBOSE", false, full, short, "Enable log.Verbose()") + ERROR = NewFlag("ERROR", true, full, short, "Enable log.Error()") + PRINTLN = NewFlag("PRINTLN", true, full, short, "Enable log.Println()") + VERBOSE = NewFlag("VERBOSE", false, full, short, "Enable log.Verbose()") } // restores flag to it's default value func (f *LogFlag) SetDefault() { - if ! f.Ok() {return} + if !f.Ok() { + return + } f.b = f.orig } @@ -99,7 +100,9 @@ func SetDefaults() { // simply protects against panic() by making sure it exists. func (f *LogFlag) Ok() bool { - if f == nil {return false} + if f == nil { + return false + } return true } @@ -121,7 +124,7 @@ func ShowFlags() []*LogFlag { flagsMutex.Lock() defer flagsMutex.Unlock() for _, f := range flags { - Log(always, "ShowFlags() ", "(" + f.subsystem + ")", f.name, "=", f.b, ":", f.desc) + Log(always, "ShowFlags() ", "("+f.subsystem+")", f.name, "=", f.b, ":", f.desc) } return flags @@ -141,13 +144,17 @@ func ProcessFlags(callback func(*LogFlag)) { // probably a better name than Get() // switch to this func (f *LogFlag) Bool() bool { - if ! f.Ok() {return false} + if !f.Ok() { + return false + } return f.b } // returns the value of the flag func (f *LogFlag) Get() bool { - if ! f.Ok() {return false} + if !f.Ok() { + return false + } return f.b } @@ -160,25 +167,33 @@ func (f *LogFlag) Set(b bool) { // returns the name of the flag func (f *LogFlag) GetName() string { - if ! f.Ok() {return ""} + if !f.Ok() { + return "" + } return f.name } // returns the subsystem of the flag func (f *LogFlag) GetSubsystem() string { - if ! f.Ok() {return ""} + if !f.Ok() { + return "" + } return f.subsystem } // returns the description of the flag func (f *LogFlag) GetDesc() string { - if ! f.Ok() {return ""} + if !f.Ok() { + return "" + } return f.desc } // returns the description of the flag func (f *LogFlag) GetDefault() bool { - if ! f.Ok() {return false} + if !f.Ok() { + return false + } return f.orig } @@ -202,17 +217,17 @@ func NewFlag(name string, b bool, full, short, desc string) *LogFlag { f.subsystem = full f.name = name f.desc = desc - flags = append(flags,f) + flags = append(flags, f) return f } func (f *LogFlag) SetBool(b bool) { /* - if ! f.Ok() {return} - flagsMutex.Lock() - defer flagsMutex.Unlock() + if ! f.Ok() {return} + flagsMutex.Lock() + defer flagsMutex.Unlock() */ - Info("Set() ", "(" + f.subsystem + ")", f.name, "=", f.b, ":", f.desc) + Info("Set() ", "("+f.subsystem+")", f.name, "=", f.b, ":", f.desc) f.b = b Info("Set() f.b is now", f.b) } |
