Skip to content

Commit 8eafa02

Browse files
committed
log: remove global log functions
Removes global functions from the log package. These functions were wrappers around log.Dev.<func> and were previously deprecated. Also replaces and remaining uses with log.Dev.<func> Epic: CRDB-53410 Resolves: CRDB-53943 Release note: None
1 parent 755c186 commit 8eafa02

14 files changed

+44
-579
lines changed

pkg/util/log/channels_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func TestRepro81025(t *testing.T) {
170170
// log line.
171171
wg.Add(1)
172172
go func() {
173-
Fatalf(context.Background(), "uh oh")
173+
Dev.Fatalf(context.Background(), "uh oh")
174174
wg.Done()
175175
}()
176176

pkg/util/log/clog.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ func (l *loggerT) outputLogEntry(entry logEntry) {
438438
func DumpStacks(ctx context.Context, reason redact.RedactableString) {
439439
allStacks := allstacks.Get()
440440
// TODO(knz): This should really be a "debug" level, not "info".
441-
Shoutf(ctx, severity.INFO, "%s. stack traces:\n%s", reason, allStacks)
441+
Dev.Shoutf(ctx, severity.INFO, "%s. stack traces:\n%s", reason, allStacks)
442442
}
443443

444444
func setActive() {

pkg/util/log/clog_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func TestInfo(t *testing.T) {
130130
defer ScopeWithoutShowLogs(t).Close(t)
131131

132132
defer capture()()
133-
Info(context.Background(), "test")
133+
Dev.Info(context.Background(), "test")
134134
if !contains("I", t) {
135135
t.Errorf("Info has wrong character: %q", contents())
136136
}
@@ -146,7 +146,7 @@ func TestUnstructuredEntryEmbedsErrorHints(t *testing.T) {
146146

147147
defer capture()()
148148
err := errors.WithHint(errors.New("hello"), "world")
149-
Infof(context.Background(), "hello %v", err)
149+
Dev.Infof(context.Background(), "hello %v", err)
150150
t.Logf("log contents:\n%s", contents())
151151
if !contains("HINT: "+startRedactable+"world"+endRedactable, t) {
152152
t.Error("hint failed")
@@ -190,7 +190,7 @@ func TestError(t *testing.T) {
190190

191191
defer capture()()
192192

193-
Error(context.Background(), "test")
193+
Dev.Error(context.Background(), "test")
194194
if !contains("E", t) {
195195
t.Errorf("Error has wrong character: %q", contents())
196196
}
@@ -208,7 +208,7 @@ func TestWarning(t *testing.T) {
208208

209209
defer capture()()
210210

211-
Warning(context.Background(), "test")
211+
Dev.Warning(context.Background(), "test")
212212
if !contains("W", t) {
213213
t.Errorf("Warning has wrong character: %q", contents())
214214
}
@@ -326,7 +326,7 @@ func TestListLogFiles(t *testing.T) {
326326
defer leaktest.AfterTest(t)()
327327
defer ScopeWithoutShowLogs(t).Close(t)
328328

329-
Info(context.Background(), "x")
329+
Dev.Info(context.Background(), "x")
330330

331331
fileName := getDebugLogFileName(t)
332332

@@ -358,7 +358,7 @@ func TestFilePermissions(t *testing.T) {
358358
defer func(p os.FileMode) { fs.filePermissions = p }(fs.filePermissions)
359359
fs.filePermissions = fileMode
360360

361-
Info(context.Background(), "x")
361+
Dev.Info(context.Background(), "x")
362362

363363
fileName := fs.getFileName(t)
364364

@@ -413,7 +413,7 @@ func TestGetLogReader(t *testing.T) {
413413
strings.TrimSpace(strings.ReplaceAll(DescribeAppliedConfig(), "\n", "\n ")))
414414

415415
// Force creation of a file on the default sink.
416-
Info(context.Background(), "x")
416+
Dev.Info(context.Background(), "x")
417417
fileName := getDebugLogFileName(t)
418418
infoName := filepath.Base(fileName)
419419

@@ -523,20 +523,20 @@ func TestRollover(t *testing.T) {
523523
defer func(previous int64) { debugFileSink.logFileMaxSize = previous }(debugFileSink.logFileMaxSize)
524524
debugFileSink.logFileMaxSize = 2048
525525

526-
Info(context.Background(), "x") // Be sure we have a file.
526+
Dev.Info(context.Background(), "x") // Be sure we have a file.
527527
if err != nil {
528528
t.Fatalf("info has initial error: %v", err)
529529
}
530530
fname0 := debugFileSink.getFileName(t)
531-
Infof(context.Background(), "%s", strings.Repeat("x", int(debugFileSink.logFileMaxSize))) // force a rollover
531+
Dev.Infof(context.Background(), "%s", strings.Repeat("x", int(debugFileSink.logFileMaxSize))) // force a rollover
532532
if err != nil {
533533
t.Fatalf("info has error after big write: %v", err)
534534
}
535535

536536
// Make sure the next log file gets a file name with a different
537537
// time stamp.
538538

539-
Info(context.Background(), "x") // create a new file
539+
Dev.Info(context.Background(), "x") // create a new file
540540
if err != nil {
541541
t.Fatalf("error after rotation: %v", err)
542542
}
@@ -573,7 +573,7 @@ func TestFatalStacktraceStderr(t *testing.T) {
573573
defer capture()()
574574

575575
traceback = level
576-
Fatalf(context.Background(), "cinap")
576+
Dev.Fatalf(context.Background(), "cinap")
577577
cont := contents()
578578
if !strings.Contains(cont, " cinap") {
579579
t.Fatalf("panic output does not contain cinap:\n%s", cont)
@@ -623,7 +623,7 @@ func TestFd2Capture(t *testing.T) {
623623
}
624624
defer cleanupFn()
625625

626-
Infof(context.Background(), "test")
626+
Dev.Infof(context.Background(), "test")
627627

628628
const stderrText = "hello stderr"
629629
fmt.Fprint(os.Stderr, stderrText)
@@ -649,8 +649,8 @@ func TestFileSeverityFilter(t *testing.T) {
649649
}
650650
}
651651

652-
Infof(context.Background(), "test1")
653-
Errorf(context.Background(), "test2")
652+
Dev.Infof(context.Background(), "test1")
653+
Dev.Errorf(context.Background(), "test2")
654654

655655
FlushFiles()
656656

@@ -766,7 +766,7 @@ func TestLogEntryPropagation(t *testing.T) {
766766
// failure to write on stderr is graceful and the message gets
767767
// printed on the file output (and can be picked up by the contains
768768
// function). If it is not, the test runner will stop abruptly.
769-
Error(context.Background(), specialMessage)
769+
Dev.Error(context.Background(), specialMessage)
770770

771771
if !contains(specialMessage, t) {
772772
t.Fatalf("expected special message in file, got:\n%s", contents())

pkg/util/log/event_log.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func RegisterEventLogWriter(
5353
if buildutil.CrdbTestBuild {
5454
panic("Structured event writer registry not set, cannot register writer")
5555
}
56-
Errorf(ctx, "Structured event writer registry not set, cannot register writer for serverId: %v", serverId.GetServerIdentificationPayload())
56+
Dev.Errorf(ctx, "Structured event writer registry not set, cannot register writer for serverId: %v", serverId.GetServerIdentificationPayload())
5757
return
5858
}
5959

@@ -67,7 +67,7 @@ func RemoveEventLogWriter(serverId serverident.ServerIdentifier) {
6767
if buildutil.CrdbTestBuild {
6868
panic("Structured event writer registry not set, cannot remove writer")
6969
}
70-
Errorf(context.Background(), "Structured event writer registry not set, cannot remove writer for serverId: %v", serverId.GetServerIdentificationPayload())
70+
Dev.Errorf(context.Background(), "Structured event writer registry not set, cannot remove writer for serverId: %v", serverId.GetServerIdentificationPayload())
7171
return
7272
}
7373

@@ -116,7 +116,7 @@ func EventLog(
116116
if buildutil.CrdbTestBuild {
117117
panic(fmt.Sprintf("couldn't find a registered writer for serverId: %+v", id.GetServerIdentificationPayload()))
118118
}
119-
VWarningf(context.Background(), 2, "couldn't find a registered writer for serverId: %+v", id.GetServerIdentificationPayload())
119+
Dev.VWarningf(context.Background(), 2, "couldn't find a registered writer for serverId: %+v", id.GetServerIdentificationPayload())
120120
}
121121
options := defaultSEventOptions
122122
for _, opt := range o {

pkg/util/log/file_log_gc_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestGC(t *testing.T) {
3333
t.Fatal("no file sink")
3434
}
3535

36-
testLogGC(t, fs, Info)
36+
testLogGC(t, fs, Dev.Info)
3737
}
3838

3939
func TestSecondaryGC(t *testing.T) {
@@ -189,7 +189,7 @@ func succeedsSoon(t *testing.T, fn func() error) {
189189
wait = time.Second
190190
}
191191
if timeutil.Since(tBegin) > 3*time.Second {
192-
InfofDepth(context.Background(), 2, "SucceedsSoon: %+v", lastErr)
192+
Dev.InfofDepth(context.Background(), 2, "SucceedsSoon: %+v", lastErr)
193193
}
194194
time.Sleep(wait)
195195
}

pkg/util/log/formats_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func TestFormatRedaction(t *testing.T) {
6565
require.NoError(t, err)
6666
defer cleanupFn()
6767

68-
Infof(ctx, "safe2 %s", "secret3")
68+
Dev.Infof(ctx, "safe2 %s", "secret3")
6969
FlushFiles()
7070

7171
contents, err := os.ReadFile(getDebugLogFileName(t))

pkg/util/log/gen/main.go

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -342,64 +342,6 @@ func (logger{{.Name}}) {{with $sev}}{{.Name}}{{end}}fDepth(ctx context.Context,
342342
logfDepth(ctx, depth+1, severity.{{with $sev}}{{.NAME}}{{end}}, channel.{{.NAME}}, format, args...)
343343
}
344344
345-
{{if .NAME|eq "DEV"}}
346-
// {{with $sev}}{{.Name}}{{end}}f logs to the {{.NAME}} channel with severity {{with $sev}}{{.NAME}}{{end}},
347-
// if logging has been enabled for the source file where the call is
348-
// performed at the provided verbosity level, via the vmodule setting.
349-
// It extracts log tags from the context and logs them along with the given
350-
// message. Arguments are handled in the manner of fmt.Printf.
351-
//
352-
{{.Comment -}}
353-
//
354-
{{with $sev}}{{.Comment}}{{end -}}
355-
//
356-
// Deprecated: use log.Dev.{{with $sev}}{{.Name}}{{end}}f instead
357-
func {{with $sev}}{{.Name}}{{end}}f(ctx context.Context, format string, args ...interface{}) {
358-
logfDepth(ctx, 1, severity.{{with $sev}}{{.NAME}}{{end}}, channel.{{.NAME}}, format, args...)
359-
}
360-
361-
// V{{with $sev}}{{.Name}}{{end}}f logs to the {{.NAME}} channel with severity {{with $sev}}{{.NAME}}{{end}}.
362-
// It extracts log tags from the context and logs them along with the given
363-
// message. Arguments are handled in the manner of fmt.Printf.
364-
//
365-
{{.Comment -}}
366-
//
367-
{{with $sev}}{{.Comment}}{{end -}}
368-
//
369-
// Deprecated: use log.Dev.V{{with $sev}}{{.Name}}{{end}}f instead
370-
func V{{with $sev}}{{.Name}}{{end}}f(ctx context.Context, level Level, format string, args ...interface{}) {
371-
if VDepth(level, 1) {
372-
logfDepth(ctx, 1, severity.{{with $sev}}{{.NAME}}{{end}}, channel.{{.NAME}}, format, args...)
373-
}
374-
}
375-
376-
// {{with $sev}}{{.Name}}{{end}} logs to the {{.NAME}} channel with severity {{with $sev}}{{.NAME}}{{end}}.
377-
// It extracts log tags from the context and logs them along with the given
378-
// message.
379-
//
380-
{{.Comment -}}
381-
//
382-
{{with $sev}}{{.Comment}}{{end -}}
383-
//
384-
// Deprecated: use log.Dev.{{with $sev}}{{.Name}}{{end}} instead
385-
func {{with $sev}}{{.Name}}{{end}}(ctx context.Context, msg string) {
386-
logfDepth(ctx, 1, severity.{{with $sev}}{{.NAME}}{{end}}, channel.{{.NAME}}, msg)
387-
}
388-
389-
// {{with $sev}}{{.Name}}{{end}}fDepth logs to the {{.NAME}} channel with severity {{with $sev}}{{.NAME}}{{end}},
390-
// offsetting the caller's stack frame by 'depth'.
391-
// It extracts log tags from the context and logs them along with the given
392-
// message. Arguments are handled in the manner of fmt.Printf.
393-
//
394-
{{.Comment -}}
395-
//
396-
{{with $sev}}{{.Comment}}{{end -}}
397-
//
398-
// Deprecated: use log.Dev.{{with $sev}}{{.Name}}{{end}}fDepth instead
399-
func {{with $sev}}{{.Name}}{{end}}fDepth(ctx context.Context, depth int, format string, args ...interface{}) {
400-
logfDepth(ctx, depth+1, severity.{{with $sev}}{{.NAME}}{{end}}, channel.{{.NAME}}, format, args...)
401-
}
402-
{{end}}{{- /* end channel name = DEV */ -}}
403345
404346
{{end}}{{end}}{{end}}{{- /* end range severities */ -}}
405347
@@ -443,30 +385,6 @@ func (logger{{.Name}}) VEventfDepth(ctx context.Context, depth int, level Level,
443385
vEventf(ctx, false /* isErr */, 1+depth, level, channel.{{.NAME}}, format, args...)
444386
}
445387
446-
{{if .NAME|eq "DEV"}}
447-
448-
// Shout logs to channel {{.NAME}}, and also to the real stderr if logging
449-
// is currently redirected to a file.
450-
//
451-
{{.Comment -}}
452-
//
453-
// Deprecated: use log.Dev.Shout instead
454-
func Shout(ctx context.Context, sev Severity, msg string) {
455-
shoutfDepth(ctx, 1, sev, channel.{{.NAME}}, msg)
456-
}
457-
458-
// Shoutf logs to channel {{.NAME}}, and also to the real stderr if
459-
// logging is currently redirected to a file. Arguments are handled in
460-
// the manner of fmt.Printf.
461-
//
462-
{{.Comment -}}
463-
//
464-
// Deprecated: use log.Dev.Shoutf instead
465-
func Shoutf(ctx context.Context, sev Severity, format string, args ...interface{}) {
466-
shoutfDepth(ctx, 1, sev, channel.{{.NAME}}, format, args...)
467-
}
468-
469-
{{end}}{{- /* end channel name = DEV */ -}}
470388
471389
{{end}}{{- /* end range channels */ -}}
472390
`,

pkg/util/log/intercept.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ import (
2929
// When multiple interceptors are configured, each of them
3030
// are served each log entry.
3131
func InterceptWith(ctx context.Context, fn Interceptor) func() {
32-
InfofDepth(ctx, 1, "starting log interception")
32+
Dev.InfofDepth(ctx, 1, "starting log interception")
3333
logging.interceptor.add(fn)
3434
return func() {
3535
logging.interceptor.del(fn)
36-
InfofDepth(ctx, 1, "stopping log interception")
36+
Dev.InfofDepth(ctx, 1, "stopping log interception")
3737
}
3838
}
3939

pkg/util/log/intercept_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestManyInterceptors(t *testing.T) {
3737
ctxgroup.GroupWorkers(context.Background(), 100, func(ctx context.Context, worker int) error {
3838
defer addInterceptor(t, &devnull{})()
3939
for i := 0; i < 10; i++ {
40-
Infof(ctx, "hello worker %d: %d", worker, i)
40+
Dev.Infof(ctx, "hello worker %d: %d", worker, i)
4141
}
4242
return nil
4343
}))
@@ -83,7 +83,7 @@ func (c *captureInterceptor) verifyCaptures(t *testing.T) {
8383
}
8484

8585
func infoWithCapture(msg string, interceptors ...*captureInterceptor) {
86-
InfofDepth(context.Background(), 1, "%s", msg)
86+
Dev.InfofDepth(context.Background(), 1, "%s", msg)
8787
file, line, _ := caller.Lookup(1)
8888
expectedRe := regexp.MustCompile(fmt.Sprintf(`.*"file":"%s","line":%d.*%s`, file, line, msg))
8989

pkg/util/log/log.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616

1717
func init() {
1818
// Inject logging functions into the errors package.
19-
errors.SetWarningFn(Warningf)
19+
errors.SetWarningFn(Dev.Warningf)
2020
// Inject logging functions into the syncutil package.
2121
syncutil.LogExpensiveLogEnabled = untypedExpensiveLogEnabled
2222
syncutil.LogVEventfDepth = untypedVEventfDepth

0 commit comments

Comments
 (0)