refactor: trim down the logger interface (#559)

pull/560/head
Craig Pastro 2023-07-07 14:52:01 -07:00 committed by GitHub
parent 06ff963c97
commit 9ba828de25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 15 deletions

View File

@ -22,11 +22,11 @@ const (
func TestMain(m *testing.M) {
if runtime.GOOS == "windows" {
log.Fatal("this test is not supported on Windows")
log.Fatalf("this test is not supported on Windows")
}
dir, err := os.Getwd()
if err != nil {
log.Fatal(err)
log.Fatalf("%v", err)
}
args := []string{
"build",

9
log.go
View File

@ -8,10 +8,7 @@ var log Logger = &stdLogger{}
// Logger is standard logger interface
type Logger interface {
Fatal(v ...interface{})
Fatalf(format string, v ...interface{})
Print(v ...interface{})
Println(v ...interface{})
Printf(format string, v ...interface{})
}
@ -23,10 +20,7 @@ func SetLogger(l Logger) {
// stdLogger is a default logger that outputs to a stdlib's log.std logger.
type stdLogger struct{}
func (*stdLogger) Fatal(v ...interface{}) { std.Fatal(v...) }
func (*stdLogger) Fatalf(format string, v ...interface{}) { std.Fatalf(format, v...) }
func (*stdLogger) Print(v ...interface{}) { std.Print(v...) }
func (*stdLogger) Println(v ...interface{}) { std.Println(v...) }
func (*stdLogger) Printf(format string, v ...interface{}) { std.Printf(format, v...) }
// NopLogger returns a logger that discards all logged output.
@ -38,8 +32,5 @@ type nopLogger struct{}
var _ Logger = (*nopLogger)(nil)
func (*nopLogger) Fatal(v ...interface{}) {}
func (*nopLogger) Fatalf(format string, v ...interface{}) {}
func (*nopLogger) Print(v ...interface{}) {}
func (*nopLogger) Println(v ...interface{}) {}
func (*nopLogger) Printf(format string, v ...interface{}) {}

View File

@ -26,8 +26,8 @@ func StatusContext(ctx context.Context, db *sql.DB, dir string, opts ...OptionsF
return fmt.Errorf("failed to collect migrations: %w", err)
}
if option.noVersioning {
log.Println(" Applied At Migration")
log.Println(" =======================================")
log.Printf(" Applied At Migration\n")
log.Printf(" =======================================\n")
for _, current := range migrations {
log.Printf(" %-24s -- %v\n", "no versioning", filepath.Base(current.Source))
}
@ -39,8 +39,8 @@ func StatusContext(ctx context.Context, db *sql.DB, dir string, opts ...OptionsF
return fmt.Errorf("failed to ensure DB version: %w", err)
}
log.Println(" Applied At Migration")
log.Println(" =======================================")
log.Printf(" Applied At Migration\n")
log.Printf(" =======================================\n")
for _, migration := range migrations {
if err := printMigrationStatus(ctx, db, migration.Version, filepath.Base(migration.Source)); err != nil {
return fmt.Errorf("failed to print status: %w", err)