switch to Disabled()

This commit is contained in:
Jeff Carr 2025-02-05 06:28:51 -06:00
parent 1631c72f70
commit f793a05288
7 changed files with 12 additions and 44 deletions

12
bool.go
View File

@ -1,12 +0,0 @@
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package log
func Bool(b bool, a ...any) {
if !b {
return
}
realPrintln(a...)
}

View File

@ -5,7 +5,7 @@
package log
func Error(err error, a ...any) {
if !ERROR.Get() {
if ERROR.Disabled() {
return
}
realPrintln("Error:", err)

View File

@ -142,21 +142,13 @@ func ProcessFlags(callback func(*LogFlag)) {
}
// probably a better name than Get()
// switch to this
func (f *LogFlag) Bool() bool {
// is the output flag disabled?
// if so, don't print anything!
func (f *LogFlag) Disabled() bool {
if !f.Ok() {
return false
return true
}
return f.b
}
// returns the value of the flag
func (f *LogFlag) Get() bool {
if !f.Ok() {
return false
}
return f.b
return ! f.b
}
/*

10
info.go
View File

@ -5,20 +5,14 @@
package log
func Info(a ...any) {
if !INFO.Ok() {
return
}
if !INFO.b {
if INFO.Disabled() {
return
}
realPrintln(a...)
}
func Infof(s string, a ...any) {
if !INFO.Ok() {
return
}
if !INFO.b {
if INFO.Disabled() {
return
}
realPrintf(s, a...)

4
log.go
View File

@ -28,7 +28,7 @@ func Log(f *LogFlag, a ...any) {
realPrintln(a...)
return
}
if !f.Get() {
if f.Disabled() {
return
}
a = append([]any{f.short}, a...)
@ -36,7 +36,7 @@ func Log(f *LogFlag, a ...any) {
}
func Logf(f *LogFlag, s string, a ...any) {
if !f.Get() {
if f.Disabled() {
return
}
s = f.short + " " + s

View File

@ -5,10 +5,7 @@
package log
func Verbose(a ...any) {
if !VERBOSE.Ok() {
return
}
if !VERBOSE.b {
if VERBOSE.Disabled() {
return
}
realPrintln(a...)

View File

@ -5,10 +5,7 @@
package log
func Warn(a ...any) {
if !WARN.Ok() {
return
}
if !WARN.b {
if WARN.Disabled() {
return
}
realPrintln(a...)