-
Notifications
You must be signed in to change notification settings - Fork 1
/
SkipFunctions.go
108 lines (98 loc) · 3.58 KB
/
SkipFunctions.go
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package ulog
import (
"sort"
"github.com/dunv/uhelpers"
)
var origSkipFunctions = []string{
"github.com/dunv/ulog.LogIfError",
"github.com/dunv/ulog.TraceIfError",
"github.com/dunv/ulog.DebugIfError",
"github.com/dunv/ulog.InfoIfError",
"github.com/dunv/ulog.WarnIfError",
"github.com/dunv/ulog.FatalIfError",
"github.com/dunv/ulog.PanicIfError",
"github.com/dunv/ulog.LogIfErrorSecondArg",
"github.com/dunv/ulog.FatalIfErrorSecondArg",
"github.com/dunv/ulog.PanicIfErrorSecondArg",
"github.com/dunv/ulog.LogIfErrorToInfo",
"github.com/dunv/ulog.LogIfErrorToInfoSecondArg",
"github.com/dunv/ulog.Trace",
"github.com/dunv/ulog.Tracef",
"github.com/dunv/ulog.Debug",
"github.com/dunv/ulog.Debugf",
"github.com/dunv/ulog.Info",
"github.com/dunv/ulog.Infof",
"github.com/dunv/ulog.Warn",
"github.com/dunv/ulog.Warnf",
"github.com/dunv/ulog.Error",
"github.com/dunv/ulog.Errorf",
"github.com/dunv/ulog.Panic",
"github.com/dunv/ulog.Panicf",
"github.com/dunv/ulog.Fatal",
"github.com/dunv/ulog.Fatalf",
"github.com/dunv/ulog.LogWithLevel",
"github.com/dunv/ulog.LogWithLevelf",
"github.com/dunv/ulog.ULog.Trace",
"github.com/dunv/ulog.ULog.Tracef",
"github.com/dunv/ulog.ULog.Debug",
"github.com/dunv/ulog.ULog.Debugf",
"github.com/dunv/ulog.ULog.Info",
"github.com/dunv/ulog.ULog.Infof",
"github.com/dunv/ulog.ULog.Warn",
"github.com/dunv/ulog.ULog.Warnf",
"github.com/dunv/ulog.ULog.Error",
"github.com/dunv/ulog.ULog.Errorf",
"github.com/dunv/ulog.ULog.Panic",
"github.com/dunv/ulog.ULog.Panicf",
"github.com/dunv/ulog.ULog.Fatal",
"github.com/dunv/ulog.ULog.Fatalf",
"github.com/dunv/ulog.ULog.LogWithLevel",
"github.com/dunv/ulog.ULog.LogWithLevelf",
"github.com/dunv/ulog.LogTaggedStruct",
"github.com/dunv/ulog.logTaggedStructWithMaskingAndWarning",
"github.com/dunv/ulog.LogEnvStruct",
}
var skipFunctions = []string{}
func init() {
ResetSkipFunctions()
}
func ResetSkipFunctions() {
skipFunctions = make([]string, len(origSkipFunctions))
copy(skipFunctions, origSkipFunctions)
}
// Get currently configured skipFunctions
func SkipFunctions() []string {
return skipFunctions
}
// // Make expected output (which is only for info, not for debugging) more readable
// Add skipFunctions. These functions will be skipped, when trying to determine the origin of a log-line.
// This way helper functions which are in use for multiple different origins can be omitted.
// For example
// ulog.AddSkipFunctions(
// "github.com/dunv/uhttp.RenderError",
// "github.com/dunv/uhttp/helpers.RenderError",
// "github.com/dunv/uhttp.RenderErrorWithStatusCode",
// "github.com/dunv/uhttp/helpers.RenderErrorWithStatusCode",
// "github.com/dunv/uhttp.RenderMessage",
// "github.com/dunv/uhttp/helpers.RenderMessage",
// "github.com/dunv/uhttp.RenderMessageWithStatusCode",
// "github.com/dunv/uhttp/helpers.RenderMessageWithStatusCode",
// "github.com/dunv/uhttp.renderMessageWithStatusCode",
// "github.com/dunv/uhttp/helpers.renderMessageWithStatusCode",
// "github.com/dunv/uhttp/helpers.renderErrorWithStatusCode",
// "github.com/dunv/uhttp.renderErrorWithStatusCode",
// )
func AddSkipFunctions(_skipFunctions ...string) {
sort.Strings(skipFunctions)
skipFunctionsToBeAdded := []string{}
for index, desiredSkipFunction := range _skipFunctions {
if desiredSkipFunction != "main.main" {
if !uhelpers.SliceContainsItem(skipFunctions, desiredSkipFunction) {
skipFunctionsToBeAdded = append(skipFunctionsToBeAdded, _skipFunctions[index])
}
} else {
Error("cannot add main.main as skip function")
}
}
skipFunctions = append(skipFunctions, skipFunctionsToBeAdded...)
}