MCPcopy
hub / github.com/safing/portmaster / log

Function log

base/log/input.go:16–80  ·  view source on GitHub ↗
(level Severity, msg string, tracer *ContextTracer)

Source from the content-addressed store, hash-verified

14)
15
16func log(level Severity, msg string, tracer *ContextTracer) {
17 if !started.IsSet() {
18 // a bit resource intense, but keeps logs before logging started.
19 // TODO: create option to disable logging
20 go func() {
21 <-startedSignal
22 log(level, msg, tracer)
23 }()
24 return
25 }
26
27 // Check log level.
28 if uint32(level) < atomic.LoadUint32(logLevel) {
29 return
30 }
31
32 // get time
33 now := time.Now()
34
35 // get file and line
36 _, file, line, ok := runtime.Caller(2)
37 if !ok {
38 file = ""
39 line = 0
40 } else {
41 if len(file) > 3 {
42 file = file[:len(file)-3]
43 } else {
44 file = ""
45 }
46 }
47
48 // create log object
49 log := &logLine{
50 msg: msg,
51 tracer: tracer,
52 level: level,
53 timestamp: now,
54 file: file,
55 line: line,
56 }
57
58 // send log to processing
59 select {
60 case logBuffer <- log:
61 default:
62 forceEmptyingLoop:
63 // force empty buffer until we can send to it
64 for {
65 select {
66 case forceEmptyingOfBuffer <- struct{}{}:
67 case logBuffer <- log:
68 break forceEmptyingLoop
69 }
70 }
71 }
72
73 // wake up writer if necessary

Callers 15

TraceFunction · 0.85
TracefFunction · 0.85
DebugFunction · 0.85
DebugfFunction · 0.85
InfoFunction · 0.85
InfofFunction · 0.85
WarningFunction · 0.85
WarningfFunction · 0.85
ErrorFunction · 0.85
ErrorfFunction · 0.85
CriticalFunction · 0.85
CriticalfFunction · 0.85

Calls 1

IsSetMethod · 0.45

Tested by 1

TestLoggingFunction · 0.68