2024-01-15 15:54:53 -06:00
|
|
|
// 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.
|
|
|
|
|
2023-12-28 12:35:05 -06:00
|
|
|
package log
|
|
|
|
|
2023-12-31 10:45:04 -06:00
|
|
|
/*
|
2023-12-30 20:48:24 -06:00
|
|
|
|
2023-12-31 10:45:04 -06:00
|
|
|
a simple way turn logging messages on and off. The gui config
|
|
|
|
window will let you enable & disable logging while your app is
|
|
|
|
running.
|
2023-12-31 02:49:26 -06:00
|
|
|
|
2023-12-31 10:45:04 -06:00
|
|
|
Example:
|
2023-12-30 20:48:24 -06:00
|
|
|
|
2023-12-31 10:45:04 -06:00
|
|
|
log.Log(NETWARN, "socket connection failed to 127.0.0.1:8080")
|
2023-12-30 20:48:24 -06:00
|
|
|
|
2023-12-31 10:45:04 -06:00
|
|
|
In your package, register NETWARN:
|
|
|
|
|
2024-01-09 15:50:53 -06:00
|
|
|
var NETWARN *log.LogFlag
|
|
|
|
NETWARN = log.NewFlag("NETWARN", true, "go.wit.com/log", "log", "network warnings!")
|
|
|
|
|
2023-12-31 10:45:04 -06:00
|
|
|
*/
|
2023-12-30 20:48:24 -06:00
|
|
|
|
2024-01-09 15:50:53 -06:00
|
|
|
func Log(f *LogFlag, a ...any) {
|
|
|
|
if ! f.Ok() {
|
|
|
|
// if the flag is NULL, notify the user they didn't initialize the flag
|
|
|
|
a = append([]any{"FLAG = NULL"}, a...)
|
2024-10-12 16:21:47 -05:00
|
|
|
realPrintln(a...)
|
2024-01-09 15:50:53 -06:00
|
|
|
return
|
2024-01-01 01:49:53 -06:00
|
|
|
}
|
2024-01-09 15:50:53 -06:00
|
|
|
if ! f.Get() { return }
|
|
|
|
a = append([]any{f.short}, a...)
|
2024-10-12 16:21:47 -05:00
|
|
|
realPrintln(a...)
|
2023-12-31 02:49:26 -06:00
|
|
|
}
|
|
|
|
|
2024-01-09 15:50:53 -06:00
|
|
|
func Logf(f *LogFlag, s string, a ...any) {
|
|
|
|
if ! f.Get() { return }
|
|
|
|
s = f.short + " " + s
|
2024-10-12 16:21:47 -05:00
|
|
|
realPrintf(s, a...)
|
2023-12-31 02:49:26 -06:00
|
|
|
}
|