MCPcopy
hub / github.com/grafana/k6 / Logf

Method Logf

internal/js/modules/k6/browser/log/logger.go:75–112  ·  view source on GitHub ↗

Logf logs a message.

(level logrus.Level, category string, msg string, args ...any)

Source from the content-addressed store, hash-verified

73
74// Logf logs a message.
75func (l *Logger) Logf(level logrus.Level, category string, msg string, args ...any) {
76 if l == nil {
77 return
78 }
79 // don't log if the current log level isn't in the required level.
80 if l.GetLevel() < level {
81 return
82 }
83 l.mu.Lock()
84 defer l.mu.Unlock()
85
86 now := time.Now().UnixNano() / 1000000
87 elapsed := now - l.lastLogCall
88 if now == elapsed {
89 elapsed = 0
90 }
91 defer func() {
92 l.lastLogCall = now
93 }()
94
95 if l.categoryFilter != nil && !l.categoryFilter.MatchString(category) {
96 return
97 }
98 fields := logrus.Fields{
99 "source": "browser",
100 "category": category,
101 "elapsed": fmt.Sprintf("%d ms", elapsed),
102 }
103 if l.iterID != "" && l.GetLevel() > logrus.InfoLevel {
104 fields["iteration_id"] = l.iterID
105 }
106 entry := l.WithFields(fields)
107 if l.GetLevel() < level {
108 entry.Printf(msg, args...)
109 return
110 }
111 entry.Logf(level, msg, args...)
112}
113
114// SetLevel sets the logger level from a level string.
115// Accepted values:

Callers 15

TracefMethod · 0.95
DebugfMethod · 0.95
ErrorfMethod · 0.95
InfofMethod · 0.95
WarnfMethod · 0.95
getTestRandFunction · 0.80
getTestTracerFunction · 0.80
TestExecutionStateVUIDsFunction · 0.80

Calls 2

UnlockMethod · 0.80
LockMethod · 0.45

Tested by 15

getTestRandFunction · 0.64
getTestTracerFunction · 0.64
TestExecutionStateVUIDsFunction · 0.64
addHandlerMethod · 0.64
TestCustomHeadersFunction · 0.64
TestCookiesFunction · 0.64
TestCookiesDefaultJarFunction · 0.64