From 0794395e6e8cf0074706fb66ae82ba7745ce1e55 Mon Sep 17 00:00:00 2001 From: Richard Wilkes Date: Fri, 22 Mar 2024 14:56:47 -0700 Subject: [PATCH] Update Go version and remove deprecated code --- .golangci.yml | 3 +- go.mod | 2 +- log/jot/adapter.go | 40 ------ log/jot/log.go | 246 ------------------------------------ log/jot/timing.go | 64 ---------- log/jot/wrapper.go | 135 -------------------- log/jotrotate/jotrotate.go | 54 -------- log/logadapter/discarder.go | 113 ----------------- log/logadapter/logger.go | 109 ---------------- log/logadapter/prefixer.go | 104 --------------- xmath/math.go | 27 ---- 11 files changed, 2 insertions(+), 895 deletions(-) delete mode 100644 log/jot/adapter.go delete mode 100644 log/jot/log.go delete mode 100644 log/jot/timing.go delete mode 100644 log/jot/wrapper.go delete mode 100644 log/jotrotate/jotrotate.go delete mode 100644 log/logadapter/discarder.go delete mode 100644 log/logadapter/logger.go delete mode 100644 log/logadapter/prefixer.go diff --git a/.golangci.yml b/.golangci.yml index 45940f6..30e009c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -16,7 +16,6 @@ linters-settings: gofumpt: extra-rules: true govet: - check-shadowing: true enable-all: true disable: - composites @@ -36,7 +35,7 @@ linters-settings: misspell: locale: US staticcheck: - go: "1.21" + go: "1.22" checks: [ "all", "-SA3000" ] unused: check-exported: false diff --git a/go.mod b/go.mod index 31342e0..f4cfca2 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/richardwilkes/toolbox -go 1.22.0 +go 1.22.1 require ( github.com/jackpal/gateway v1.0.14 diff --git a/log/jot/adapter.go b/log/jot/adapter.go deleted file mode 100644 index be12809..0000000 --- a/log/jot/adapter.go +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright ©2016-2023 by Richard A. Wilkes. All rights reserved. -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, version 2.0. If a copy of the MPL was not distributed with -// this file, You can obtain one at http://mozilla.org/MPL/2.0/. -// -// This Source Code Form is "Incompatible With Secondary Licenses", as -// defined by the Mozilla Public License, version 2.0. - -package jot - -// LoggerWriter provides a bridge between the standard log.Logger and the jot package. You can use it like this: -// -// log.New(&jot.LoggerWriter{}, "", 0) -// -// This will send all output for this logger to the jot.Error() call. -// -// You can also set the Filter function to direct the output to a particular jot logging method: -// -// log.New(&jot.LoggerWriter{Filter: jot.Info}), "", 0) -// -// Deprecated: Use slog instead. August 28, 2023 -type LoggerWriter struct { - Filter func(v ...any) -} - -// Write implements the io.Writer interface required by log.Logger. -// -// Deprecated: Use slog instead. August 28, 2023 -func (w *LoggerWriter) Write(p []byte) (n int, err error) { - if len(p) > 0 { - filter := w.Filter - if filter == nil { - filter = Error - } - filter(string(p[:len(p)-1])) - Flush() // To ensure the output is recorded. - } - return len(p), nil -} diff --git a/log/jot/log.go b/log/jot/log.go deleted file mode 100644 index ea48ee5..0000000 --- a/log/jot/log.go +++ /dev/null @@ -1,246 +0,0 @@ -// Copyright ©2016-2023 by Richard A. Wilkes. All rights reserved. -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, version 2.0. If a copy of the MPL was not distributed with -// this file, You can obtain one at http://mozilla.org/MPL/2.0/. -// -// This Source Code Form is "Incompatible With Secondary Licenses", as -// defined by the Mozilla Public License, version 2.0. - -// Package jot provides simple asynchronous logging. -package jot - -import ( - "fmt" - "io" - "os" - "strings" - "time" - - "github.com/richardwilkes/toolbox/atexit" - "github.com/richardwilkes/toolbox/xio/term" -) - -// Log levels -const ( - DEBUG Level = iota - INFO - WARN - ERROR - FATAL -) - -var logChannel = make(chan *record, 100) - -// Level holds a log level. -// -// Deprecated: Use slog instead. August 28, 2023 -type Level int - -type record struct { - when time.Time - level Level - msg string - writer io.Writer - response chan bool - setMinLevel bool -} - -func init() { - atexit.Register(Flush) - // Initialization of `out` was moved outside of the goroutine in case jot isn't actually being used (but is being - // initialized as a side-effect of bringing in some other package) to prevent races with other threads that might - // be trying to use os.Stderr. - out := term.NewANSI(os.Stderr) - go func() { - levelNames := []string{"DBG", "INF", "WRN", "ERR", "FTL"} - levelColors := []term.Color{term.Blue, 0, term.Yellow, term.Red, term.Red} - levelStyles := []term.Style{term.Bold, 0, term.Bold, term.Bold, term.Bold | term.Blink} - minLevel := DEBUG - for rec := range logChannel { - switch { - case rec.writer != nil: - out = term.NewANSI(rec.writer) - case rec.response != nil: - rec.response <- true - case rec.setMinLevel: - minLevel = rec.level - case rec.level >= minLevel: - color := levelColors[rec.level] - if color != 0 { - out.Foreground(color, levelStyles[rec.level]) - } - write(out, levelNames[rec.level]) - if color != 0 { - out.Reset() - } - timeDate := rec.when.Format(" | 2006-01-02 | 15:04:05.000 | ") - write(out, timeDate) - parts := strings.Split(rec.msg, "\n") - write(out, parts[0]) - if len(parts) > 1 { - prefix := "\n" + strings.Repeat(" ", len(levelNames[0])+len(timeDate)) - for i := 1; i < len(parts); i++ { - write(out, prefix) - write(out, parts[i]) - } - } - write(out, "\n") - } - } - }() -} - -func write(out io.Writer, text string) { - // The extra code here is just to quiet the linter about not checking for an error. - if _, err := out.Write([]byte(text)); err != nil { - return - } -} - -// SetWriter sets the io.Writer to use when writing log messages. Default is os.Stderr. -// -// Deprecated: Use slog instead. August 28, 2023 -func SetWriter(w io.Writer) { - logChannel <- &record{writer: w} -} - -// SetMinimumLevel sets the minimum log level that will be output. Default is DEBUG. -// -// Deprecated: Use slog instead. August 28, 2023 -func SetMinimumLevel(level Level) { - logChannel <- &record{ - level: level, - setMinLevel: true, - } -} - -// Debug logs a debugging message. Arguments are handled in the manner of fmt.Print. -// -// Deprecated: Use slog instead. August 28, 2023 -func Debug(v ...any) { - logChannel <- &record{ - when: time.Now(), - level: DEBUG, - msg: fmt.Sprint(v...), - } -} - -// Debugf logs a debugging message. Arguments are handled in the manner of fmt.Printf. -// -// Deprecated: Use slog instead. August 28, 2023 -func Debugf(format string, v ...any) { - logChannel <- &record{ - when: time.Now(), - level: DEBUG, - msg: fmt.Sprintf(format, v...), - } -} - -// Info logs an informational message. Arguments are handled in the manner of fmt.Print. -// -// Deprecated: Use slog instead. August 28, 2023 -func Info(v ...any) { - logChannel <- &record{ - when: time.Now(), - level: INFO, - msg: fmt.Sprint(v...), - } -} - -// Infof logs an informational message. Arguments are handled in the manner of fmt.Printf. -// -// Deprecated: Use slog instead. August 28, 2023 -func Infof(format string, v ...any) { - logChannel <- &record{ - when: time.Now(), - level: INFO, - msg: fmt.Sprintf(format, v...), - } -} - -// Warn logs a warning message. Arguments are handled in the manner of fmt.Print. -// -// Deprecated: Use slog instead. August 28, 2023 -func Warn(v ...any) { - logChannel <- &record{ - when: time.Now(), - level: WARN, - msg: fmt.Sprint(v...), - } -} - -// Warnf logs a warning message. Arguments are handled in the manner of fmt.Printf. -// -// Deprecated: Use slog instead. August 28, 2023 -func Warnf(format string, v ...any) { - logChannel <- &record{ - when: time.Now(), - level: WARN, - msg: fmt.Sprintf(format, v...), - } -} - -// Error logs an error message. Arguments are handled in the manner of fmt.Print. -// -// Deprecated: Use slog instead. August 28, 2023 -func Error(v ...any) { - logChannel <- &record{ - when: time.Now(), - level: ERROR, - msg: fmt.Sprint(v...), - } -} - -// Errorf logs an error message. Arguments are handled in the manner of fmt.Printf. -// -// Deprecated: Use slog instead. August 28, 2023 -func Errorf(format string, v ...any) { - logChannel <- &record{ - when: time.Now(), - level: ERROR, - msg: fmt.Sprintf(format, v...), - } -} - -// Fatal logs a fatal error message. Arguments other than the status are handled in the manner of fmt.Print. -// -// Deprecated: Use slog instead. August 28, 2023 -func Fatal(status int, v ...any) { - logChannel <- &record{ - when: time.Now(), - level: FATAL, - msg: fmt.Sprint(v...), - } - atexit.Exit(status) -} - -// Fatalf logs a fatal error message. Arguments other than the status are handled in the manner of fmt.Printf. -// -// Deprecated: Use slog instead. August 28, 2023 -func Fatalf(status int, format string, v ...any) { - logChannel <- &record{ - when: time.Now(), - level: FATAL, - msg: fmt.Sprintf(format, v...), - } - atexit.Exit(status) -} - -// FatalIfErr calls 'Fatal(1, err)' if 'err' is not nil. -// -// Deprecated: Use slog instead. August 28, 2023 -func FatalIfErr(err error) { - if err != nil { - Fatal(1, err) - } -} - -// Flush waits for all current log entries to be written before returning. -// -// Deprecated: Use slog instead. August 28, 2023 -func Flush() { - rec := &record{response: make(chan bool)} - logChannel <- rec - <-rec.response -} diff --git a/log/jot/timing.go b/log/jot/timing.go deleted file mode 100644 index e60339e..0000000 --- a/log/jot/timing.go +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright ©2016-2023 by Richard A. Wilkes. All rights reserved. -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, version 2.0. If a copy of the MPL was not distributed with -// this file, You can obtain one at http://mozilla.org/MPL/2.0/. -// -// This Source Code Form is "Incompatible With Secondary Licenses", as -// defined by the Mozilla Public License, version 2.0. - -package jot - -import ( - "fmt" - "time" - - "github.com/richardwilkes/toolbox/log/logadapter" -) - -type timing struct { - started time.Time - msg string -} - -func (t *timing) End() time.Duration { - elapsed := time.Since(t.started) - Infof("Finished %s | %v elapsed", t.msg, elapsed) - return elapsed -} - -func (t *timing) EndWithMsg(v ...any) time.Duration { - elapsed := time.Since(t.started) - Infof("Finished %s | %s | %v elapsed", t.msg, fmt.Sprint(v...), elapsed) - return elapsed -} - -func (t *timing) EndWithMsgf(format string, v ...any) time.Duration { - elapsed := time.Since(t.started) - Infof("Finished %s | %s | %v elapsed", t.msg, fmt.Sprintf(format, v...), elapsed) - return elapsed -} - -// Time starts timing an event and logs an informational message. Arguments are handled in the manner of fmt.Print. -// -// Deprecated: Use slog instead. August 28, 2023 -func Time(v ...any) logadapter.Timing { - msg := fmt.Sprint(v...) - Infof("Starting %s", msg) - return &timing{ - started: time.Now(), - msg: msg, - } -} - -// Timef starts timing an event and logs an informational message. Arguments are handled in the manner of fmt.Printf. -// -// Deprecated: Use slog instead. August 28, 2023 -func Timef(format string, v ...any) logadapter.Timing { - msg := fmt.Sprintf(format, v...) - Infof("Starting %s", msg) - return &timing{ - started: time.Now(), - msg: msg, - } -} diff --git a/log/jot/wrapper.go b/log/jot/wrapper.go deleted file mode 100644 index 09b755c..0000000 --- a/log/jot/wrapper.go +++ /dev/null @@ -1,135 +0,0 @@ -// Copyright ©2016-2023 by Richard A. Wilkes. All rights reserved. -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, version 2.0. If a copy of the MPL was not distributed with -// this file, You can obtain one at http://mozilla.org/MPL/2.0/. -// -// This Source Code Form is "Incompatible With Secondary Licenses", as -// defined by the Mozilla Public License, version 2.0. - -package jot - -import ( - "io" - - "github.com/richardwilkes/toolbox/log/logadapter" -) - -// Logger wraps the various jot function calls into a struct that can be passed around, typically for the sake of -// satisfying one or more logging interfaces. -// -// Deprecated: Use slog instead. August 28, 2023 -type Logger struct{} - -// SetWriter sets the io.Writer to use when writing log messages. Default is os.Stderr. -// -// Deprecated: Use slog instead. August 28, 2023 -func (lgr *Logger) SetWriter(w io.Writer) { - SetWriter(w) -} - -// SetMinimumLevel sets the minimum log level that will be output. Default is DEBUG. -// -// Deprecated: Use slog instead. August 28, 2023 -func (lgr *Logger) SetMinimumLevel(level Level) { - SetMinimumLevel(level) -} - -// Debug logs a debug message. Arguments are handled in the manner of fmt.Print. -// -// Deprecated: Use slog instead. August 28, 2023 -func (lgr *Logger) Debug(v ...any) { - Debug(v...) -} - -// Debugf logs a debug message. Arguments are handled in the manner of fmt.Printf. -// -// Deprecated: Use slog instead. August 28, 2023 -func (lgr *Logger) Debugf(format string, v ...any) { - Debugf(format, v...) -} - -// Info logs an informational message. Arguments are handled in the manner of fmt.Print. -// -// Deprecated: Use slog instead. August 28, 2023 -func (lgr *Logger) Info(v ...any) { - Info(v...) -} - -// Infof logs an informational message. Arguments are handled in the manner of fmt.Printf. -// -// Deprecated: Use slog instead. August 28, 2023 -func (lgr *Logger) Infof(format string, v ...any) { - Infof(format, v...) -} - -// Warn logs a warning message. Arguments are handled in the manner of fmt.Print. -// -// Deprecated: Use slog instead. August 28, 2023 -func (lgr *Logger) Warn(v ...any) { - Warn(v...) -} - -// Warnf logs a warning message. Arguments are handled in the manner of fmt.Printf. -// -// Deprecated: Use slog instead. August 28, 2023 -func (lgr *Logger) Warnf(format string, v ...any) { - Warnf(format, v...) -} - -// Error logs an error message. Arguments are handled in the manner of fmt.Print. -// -// Deprecated: Use slog instead. August 28, 2023 -func (lgr *Logger) Error(v ...any) { - Error(v...) -} - -// Errorf logs an error message. Arguments are handled in the manner of fmt.Printf. -// -// Deprecated: Use slog instead. August 28, 2023 -func (lgr *Logger) Errorf(format string, v ...any) { - Errorf(format, v...) -} - -// Fatal logs a fatal error message. Arguments other than the status are handled in the manner of fmt.Print. -// -// Deprecated: Use slog instead. August 28, 2023 -func (lgr *Logger) Fatal(status int, v ...any) { - Fatal(status, v...) -} - -// Fatalf logs a fatal error message. Arguments other than the status are handled in the manner of fmt.Printf. -// -// Deprecated: Use slog instead. August 28, 2023 -func (lgr *Logger) Fatalf(status int, format string, v ...any) { - Fatalf(status, format, v...) -} - -// Time starts timing an event and logs an informational message. Arguments are handled in the manner of fmt.Print. -// -// Deprecated: Use slog instead. August 28, 2023 -func (lgr *Logger) Time(v ...any) logadapter.Timing { - return Time(v...) -} - -// Timef starts timing an event and logs an informational message. Arguments are handled in the manner of fmt.Printf. -// -// Deprecated: Use slog instead. August 28, 2023 -func (lgr *Logger) Timef(format string, v ...any) logadapter.Timing { - return Timef(format, v...) -} - -// Flush waits for all current log entries to be written before returning. -// -// Deprecated: Use slog instead. August 28, 2023 -func (lgr *Logger) Flush() { - Flush() -} - -// Writer logs the data as an error after casting it to a string. -// -// Deprecated: Use slog instead. August 28, 2023 -func (lgr *Logger) Write(data []byte) (int, error) { - Error(string(data)) - return len(data), nil -} diff --git a/log/jotrotate/jotrotate.go b/log/jotrotate/jotrotate.go deleted file mode 100644 index 63465cc..0000000 --- a/log/jotrotate/jotrotate.go +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright ©2016-2023 by Richard A. Wilkes. All rights reserved. -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, version 2.0. If a copy of the MPL was not distributed with -// this file, You can obtain one at http://mozilla.org/MPL/2.0/. -// -// This Source Code Form is "Incompatible With Secondary Licenses", as -// defined by the Mozilla Public License, version 2.0. - -// Package jotrotate provides a pre-canned way to add jot logging with file -// rotation, along with command-line options for controlling it. -package jotrotate - -import ( - "io" - "os" - - "github.com/richardwilkes/toolbox/cmdline" - "github.com/richardwilkes/toolbox/log/jot" - "github.com/richardwilkes/toolbox/log/rotation" - "github.com/richardwilkes/toolbox/xio" -) - -// PathToLog holds the path to the log file that was configured on the command line when using ParseAndSetup(). -// -// Deprecated: Use rotation.PathToLog instead. August 28, 2023 -var PathToLog string - -// ParseAndSetup adds command-line options for controlling logging, parses the command line, then instantiates a rotator -// and attaches it to jot. Returns the remaining arguments that weren't used for option content. -// -// Deprecated: Use rotation.ParseAndSetupLogging instead. August 28, 2023 -func ParseAndSetup(cl *cmdline.CmdLine) []string { - logFile := rotation.DefaultPath() - var maxSize int64 = rotation.DefaultMaxSize - maxBackups := rotation.DefaultMaxBackups - logToConsole := false - cl.NewGeneralOption(&logFile).SetSingle('l').SetName("log-file").SetUsage("The file to write logs to") - cl.NewGeneralOption(&maxSize).SetName("log-file-size").SetUsage("The maximum number of bytes to write to a log file before rotating it") - cl.NewGeneralOption(&maxBackups).SetName("log-file-backups").SetUsage("The maximum number of old logs files to retain") - cl.NewGeneralOption(&logToConsole).SetSingle('C').SetName("log-to-console").SetUsage("Copy the log output to the console") - remainingArgs := cl.Parse(os.Args[1:]) - if rotator, err := rotation.New(rotation.Path(logFile), rotation.MaxSize(maxSize), rotation.MaxBackups(maxBackups)); err == nil { - if logToConsole { - jot.SetWriter(&xio.TeeWriter{Writers: []io.Writer{rotator, os.Stdout}}) - } else { - jot.SetWriter(rotator) - } - PathToLog = rotator.PathToLog() - } else { - jot.Error(err) - } - return remainingArgs -} diff --git a/log/logadapter/discarder.go b/log/logadapter/discarder.go deleted file mode 100644 index 92b6266..0000000 --- a/log/logadapter/discarder.go +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright ©2016-2023 by Richard A. Wilkes. All rights reserved. -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, version 2.0. If a copy of the MPL was not distributed with -// this file, You can obtain one at http://mozilla.org/MPL/2.0/. -// -// This Source Code Form is "Incompatible With Secondary Licenses", as -// defined by the Mozilla Public License, version 2.0. - -package logadapter - -import ( - "time" - - "github.com/richardwilkes/toolbox/atexit" -) - -// Discarder discards all data given to it. -// -// Deprecated: Use slog instead. August 28, 2023 -type Discarder struct{} - -// Debug logs a debug message. Arguments are handled in the manner of fmt.Print. -// -// Deprecated: Use slog instead. August 28, 2023 -func (d *Discarder) Debug(_ ...any) { -} - -// Debugf logs a debug message. Arguments are handled in the manner of fmt.Printf. -// -// Deprecated: Use slog instead. August 28, 2023 -func (d *Discarder) Debugf(_ string, _ ...any) { -} - -// Info logs an informational message. Arguments are handled in the manner of fmt.Print. -// -// Deprecated: Use slog instead. August 28, 2023 -func (d *Discarder) Info(_ ...any) { -} - -// Infof logs an informational message. Arguments are handled in the manner of fmt.Printf. -// -// Deprecated: Use slog instead. August 28, 2023 -func (d *Discarder) Infof(_ string, _ ...any) { -} - -// Warn logs a warning message. Arguments are handled in the manner of fmt.Print. -// -// Deprecated: Use slog instead. August 28, 2023 -func (d *Discarder) Warn(_ ...any) { -} - -// Warnf logs a warning message. Arguments are handled in the manner of fmt.Printf. -// -// Deprecated: Use slog instead. August 28, 2023 -func (d *Discarder) Warnf(_ string, _ ...any) { -} - -// Error logs an error message. Arguments are handled in the manner of fmt.Print. -// -// Deprecated: Use slog instead. August 28, 2023 -func (d *Discarder) Error(_ ...any) { -} - -// Errorf logs an error message. Arguments are handled in the manner of fmt.Printf. -// -// Deprecated: Use slog instead. August 28, 2023 -func (d *Discarder) Errorf(_ string, _ ...any) { -} - -// Fatal logs a fatal error message. Arguments are handled in the manner of fmt.Print. -// -// Deprecated: Use slog instead. August 28, 2023 -func (d *Discarder) Fatal(status int, _ ...any) { - atexit.Exit(status) -} - -// Fatalf logs a fatal error message. Arguments are handled in the manner of fmt.Printf. -// -// Deprecated: Use slog instead. August 28, 2023 -func (d *Discarder) Fatalf(status int, _ string, _ ...any) { - atexit.Exit(status) -} - -type discarderTiming struct { - started time.Time -} - -func (d *discarderTiming) End() time.Duration { - return time.Since(d.started) -} - -func (d *discarderTiming) EndWithMsg(_ ...any) time.Duration { - return time.Since(d.started) -} - -func (d *discarderTiming) EndWithMsgf(_ string, _ ...any) time.Duration { - return time.Since(d.started) -} - -// Time starts timing an event and logs an informational message. Arguments are handled in the manner of fmt.Print. -// -// Deprecated: Use slog instead. August 28, 2023 -func (d *Discarder) Time(_ ...any) Timing { - return &discarderTiming{started: time.Now()} -} - -// Timef starts timing an event and logs an informational message. Arguments are handled in the manner of fmt.Printf. -// -// Deprecated: Use slog instead. August 28, 2023 -func (d *Discarder) Timef(_ string, _ ...any) Timing { - return &discarderTiming{started: time.Now()} -} diff --git a/log/logadapter/logger.go b/log/logadapter/logger.go deleted file mode 100644 index 07f7347..0000000 --- a/log/logadapter/logger.go +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright ©2016-2023 by Richard A. Wilkes. All rights reserved. -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, version 2.0. If a copy of the MPL was not distributed with -// this file, You can obtain one at http://mozilla.org/MPL/2.0/. -// -// This Source Code Form is "Incompatible With Secondary Licenses", as -// defined by the Mozilla Public License, version 2.0. - -// Package logadapter defines an API to use for logging, which actual logging implementations can implement directly or -// provide an adapter to use. -package logadapter - -import "time" - -// DebugLogger defines an API to use for logging debugging messages, which actual logging implementations can implement -// directly or provide an adapter to use. -// -// Deprecated: Use slog instead. August 28, 2023 -type DebugLogger interface { - // Debug logs a debugging message. Arguments are handled in the manner of fmt.Print. - Debug(v ...any) - // Debugf logs a debugging message. Arguments are handled in the manner of fmt.Printf. - Debugf(format string, v ...any) -} - -// InfoLogger defines an API to use for logging informational messages, which actual logging implementations can -// implement directly or provide an adapter to use. -// -// Deprecated: Use slog instead. August 28, 2023 -type InfoLogger interface { - // Info logs an informational message. Arguments are handled in the manner of fmt.Print. - Info(v ...any) - // Infof logs an informational message. Arguments are handled in the manner of fmt.Print. - Infof(format string, v ...any) -} - -// WarnLogger defines an API to use for logging warning messages, which actual logging implementations can implement -// directly or provide an adapter to use. -// -// Deprecated: Use slog instead. August 28, 2023 -type WarnLogger interface { - // Warn logs a warning message. Arguments are handled in the manner of fmt.Print. - Warn(v ...any) - // Warnf logs a warning message. Arguments are handled in the manner of fmt.Printf. - Warnf(format string, v ...any) -} - -// ErrorLogger defines an API to use for logging error messages, which actual logging implementations can implement -// directly or provide an adapter to use. -// -// Deprecated: Use slog instead. August 28, 2023 -type ErrorLogger interface { - // Error logs an error message. Arguments are handled in the manner of fmt.Print. - Error(v ...any) - // Errorf logs an error message. Arguments are handled in the manner of fmt.Printf. - Errorf(format string, v ...any) -} - -// FatalLogger defines an API to use for logging fatal error messages, which actual logging implementations can -// implement directly or provide an adapter to use. -// -// Deprecated: Use slog instead. August 28, 2023 -type FatalLogger interface { - // Fatal logs a fatal error message. Arguments other than the status are handled in the manner of fmt.Print. - Fatal(status int, v ...any) - // Fatalf logs a fatal error message. Arguments other than the status are handled in the manner of fmt.Printf. - Fatalf(status int, format string, v ...any) -} - -// Timing is used to record the duration between two events. One of End(), EndWithMsg(), or EndWithMsgf() should be -// called when the event has finished. -// -// Deprecated: Use slog instead. August 28, 2023 -type Timing interface { - // End finishes timing an event and logs an informational message. - End() time.Duration - // EndWithMsg finishes timing an event and logs an informational message. Arguments are handled in the manner of - // fmt.Print. - EndWithMsg(v ...any) time.Duration - // EndWithMsgf finishes timing an event and logs an informational message. Arguments are handled in the manner of - // fmt.Printf. - EndWithMsgf(format string, v ...any) time.Duration -} - -// TimingLogger defines an API to use for logging timed data, which actual logging implementations can implement -// directly or provide an adapter to use. -// -// Deprecated: Use slog instead. August 28, 2023 -type TimingLogger interface { - // Time starts timing an event and logs an informational message. Arguments are handled in the manner of fmt.Print. - Time(v ...any) Timing - // Timef starts timing an event and logs an informational message. Arguments are handled in the manner of - // fmt.Printf. - Timef(format string, v ...any) Timing -} - -// Logger defines an API to use for logging, which actual logging implementations can implement directly or provide an -// adapter to use. -// -// Deprecated: Use slog instead. August 28, 2023 -type Logger interface { - DebugLogger - InfoLogger - WarnLogger - ErrorLogger - FatalLogger - TimingLogger -} diff --git a/log/logadapter/prefixer.go b/log/logadapter/prefixer.go deleted file mode 100644 index cd878b7..0000000 --- a/log/logadapter/prefixer.go +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright ©2016-2023 by Richard A. Wilkes. All rights reserved. -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, version 2.0. If a copy of the MPL was not distributed with -// this file, You can obtain one at http://mozilla.org/MPL/2.0/. -// -// This Source Code Form is "Incompatible With Secondary Licenses", as -// defined by the Mozilla Public License, version 2.0. - -package logadapter - -import "fmt" - -// Prefixer adds a prefix to another logger's output. -// -// Deprecated: Use slog instead. August 28, 2023 -type Prefixer struct { - Logger Logger - Prefix string -} - -// Debug logs a debug message. Arguments are handled in the manner of fmt.Print. -// -// Deprecated: Use slog instead. August 28, 2023 -func (p *Prefixer) Debug(v ...any) { - p.Logger.Debugf("%s%s", p.Prefix, fmt.Sprint(v...)) -} - -// Debugf logs a debug message. Arguments are handled in the manner of fmt.Printf. -// -// Deprecated: Use slog instead. August 28, 2023 -func (p *Prefixer) Debugf(format string, v ...any) { - p.Logger.Debugf("%s%s", p.Prefix, fmt.Sprintf(format, v...)) -} - -// Info logs an informational message. Arguments are handled in the manner of fmt.Print. -// -// Deprecated: Use slog instead. August 28, 2023 -func (p *Prefixer) Info(v ...any) { - p.Logger.Infof("%s%s", p.Prefix, fmt.Sprint(v...)) -} - -// Infof logs an informational message. Arguments are handled in the manner of fmt.Printf. -// -// Deprecated: Use slog instead. August 28, 2023 -func (p *Prefixer) Infof(format string, v ...any) { - p.Logger.Infof("%s%s", p.Prefix, fmt.Sprintf(format, v...)) -} - -// Warn logs a warning message. Arguments are handled in the manner of fmt.Print. -// -// Deprecated: Use slog instead. August 28, 2023 -func (p *Prefixer) Warn(v ...any) { - p.Logger.Warnf("%s%s", p.Prefix, fmt.Sprint(v...)) -} - -// Warnf logs a warning message. Arguments are handled in the manner of fmt.Printf. -// -// Deprecated: Use slog instead. August 28, 2023 -func (p *Prefixer) Warnf(format string, v ...any) { - p.Logger.Warnf("%s%s", p.Prefix, fmt.Sprintf(format, v...)) -} - -// Error logs an error message. Arguments are handled in the manner of fmt.Print. -// -// Deprecated: Use slog instead. August 28, 2023 -func (p *Prefixer) Error(v ...any) { - p.Logger.Errorf("%s%s", p.Prefix, fmt.Sprint(v...)) -} - -// Errorf logs an error message. Arguments are handled in the manner of fmt.Printf. -// -// Deprecated: Use slog instead. August 28, 2023 -func (p *Prefixer) Errorf(format string, v ...any) { - p.Logger.Errorf("%s%s", p.Prefix, fmt.Sprintf(format, v...)) -} - -// Fatal logs a fatal error message. Arguments are handled in the manner of fmt.Print. -// -// Deprecated: Use slog instead. August 28, 2023 -func (p *Prefixer) Fatal(status int, v ...any) { - p.Logger.Fatalf(status, "%s%s", p.Prefix, fmt.Sprint(v...)) -} - -// Fatalf logs a fatal error message. Arguments are handled in the manner of fmt.Printf. -// -// Deprecated: Use slog instead. August 28, 2023 -func (p *Prefixer) Fatalf(status int, format string, v ...any) { - p.Logger.Fatalf(status, "%s%s", p.Prefix, fmt.Sprintf(format, v...)) -} - -// Time starts timing an event and logs an informational message. Arguments are handled in the manner of fmt.Print. -// -// Deprecated: Use slog instead. August 28, 2023 -func (p *Prefixer) Time(v ...any) Timing { - return p.Logger.Timef("%s%s", p.Prefix, fmt.Sprint(v...)) -} - -// Timef starts timing an event and logs an informational message. Arguments are handled in the manner of fmt.Printf. -// -// Deprecated: Use slog instead. August 28, 2023 -func (p *Prefixer) Timef(format string, v ...any) Timing { - return p.Logger.Timef("%s%s", p.Prefix, fmt.Sprintf(format, v...)) -} diff --git a/xmath/math.go b/xmath/math.go index 7267a58..c70c5da 100644 --- a/xmath/math.go +++ b/xmath/math.go @@ -470,20 +470,6 @@ func Logb[T constraints.Float](x T) T { return T(math.Logb(float64(x))) } -// Max returns the larger of x or y. -// -// Special cases are: -// -// Max(x, +Inf) = Max(+Inf, x) = +Inf -// Max(x, NaN) = Max(NaN, x) = NaN -// Max(+0, ±0) = Max(±0, +0) = +0 -// Max(-0, -0) = -0 -// -// Deprecated: Use the Go 1.21+ built-in max() instead. August 8, 2023 -func Max[T Numeric](a, b T) T { - return max(a, b) -} - // MaxValue returns the maximum value for the type. func MaxValue[T Numeric]() T { var t T @@ -521,19 +507,6 @@ func MaxValue[T Numeric]() T { return t } -// Min returns the smaller of x or y. -// -// Special cases are: -// -// Min(x, -Inf) = Min(-Inf, x) = -Inf -// Min(x, NaN) = Min(NaN, x) = NaN -// Min(-0, ±0) = Min(±0, -0) = -0 -// -// Deprecated: Use the Go 1.21+ built-in min() instead. August 8, 2023 -func Min[T Numeric](a, b T) T { - return min(a, b) -} - // MinValue returns the minimum value for the type. func MinValue[T Numeric]() T { var t T