summaryrefslogtreecommitdiff
path: root/log.go
blob: 0f6de14d7446664c80edaae22806dd22326aed78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// 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

/*

a simple way turn logging messages on and off. The gui config
window will let you enable & disable logging while your app is
running.

Example:

	log.Log(NETWARN, "socket connection failed to 127.0.0.1:8080")

In your package, register NETWARN:

	var NETWARN *log.LogFlag
	NETWARN = log.NewFlag("NETWARN", true, "go.wit.com/log", "log", "network warnings!")

*/

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. Normal error output. please ignore for now"}, a...)
		realPrintln(a...)
		return
	}
	if f.Disabled() {
		return
	}
	a = append([]any{f.short}, a...)
	realPrintln(a...)
}

func Logf(f *LogFlag, s string, a ...any) {
	if f.Disabled() {
		return
	}
	s = f.short + " " + s
	realPrintf(s, a...)
}