-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: move migration logger to logger package
- Loading branch information
Showing
2 changed files
with
32 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2024 Canonical. | ||
|
||
package logger | ||
|
||
import ( | ||
"fmt" | ||
|
||
"go.uber.org/zap" | ||
) | ||
|
||
// MigrationLogger provides a logger for use with DB migrations. | ||
type MigrationLogger struct { | ||
Logger *zap.Logger | ||
IsVerbose bool | ||
} | ||
|
||
// Printf implements the Printf function of the migrate.Logger interface. | ||
func (l MigrationLogger) Printf(format string, v ...interface{}) { | ||
line := fmt.Sprintf(format, v...) | ||
// Remove unneeded new lines since the zap logger adds them. | ||
if line[len(line)-1] == '\n' { | ||
line = line[:len(line)-1] | ||
} | ||
l.Logger.Info(line) | ||
} | ||
|
||
// Verbose implements the Verbose function of the migrate.Logger interface. | ||
func (l MigrationLogger) Verbose() bool { | ||
return l.IsVerbose | ||
} |