-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Logging interface to Autometrics (#80)
- Loading branch information
Showing
11 changed files
with
159 additions
and
12 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
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
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
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
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,63 @@ | ||
package log // import "github.com/autometrics-dev/autometrics-go/pkg/autometrics/log" | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
) | ||
|
||
// Logger is an interface to implement to be able to inject a logger to Autometrics. | ||
// The interface follows the interface of slog.Logger | ||
type Logger interface { | ||
Debug(msg string, args ...any) | ||
DebugContext(ctx context.Context, msg string, args ...any) | ||
Info(msg string, args ...any) | ||
InfoContext(ctx context.Context, msg string, args ...any) | ||
Warn(msg string, args ...any) | ||
WarnContext(ctx context.Context, msg string, args ...any) | ||
Error(msg string, args ...any) | ||
ErrorContext(ctx context.Context, msg string, args ...any) | ||
} | ||
|
||
// NoOpLogger is the default logger for Autometrics. It does nothing. | ||
type NoOpLogger struct{} | ||
|
||
var _ Logger = NoOpLogger{} | ||
|
||
func (_ NoOpLogger) Debug(msg string, args ...any) {} | ||
func (_ NoOpLogger) DebugContext(ctx context.Context, msg string, args ...any) {} | ||
func (_ NoOpLogger) Info(msg string, args ...any) {} | ||
func (_ NoOpLogger) InfoContext(ctx context.Context, msg string, args ...any) {} | ||
func (_ NoOpLogger) Warn(msg string, args ...any) {} | ||
func (_ NoOpLogger) WarnContext(ctx context.Context, msg string, args ...any) {} | ||
func (_ NoOpLogger) Error(msg string, args ...any) {} | ||
func (_ NoOpLogger) ErrorContext(ctx context.Context, msg string, args ...any) {} | ||
|
||
// PrintLogger is a simple logger implementation that simply prints the events to stdout | ||
type PrintLogger struct{} | ||
|
||
var _ Logger = PrintLogger{} | ||
|
||
func (_ PrintLogger) Debug(msg string, args ...any) { | ||
fmt.Printf("Autometrics - Debug: %v", fmt.Sprintf(msg, args...)) | ||
} | ||
func (_ PrintLogger) DebugContext(ctx context.Context, msg string, args ...any) { | ||
fmt.Printf("Autometrics - Debug: %v", fmt.Sprintf(msg, args...)) | ||
} | ||
func (_ PrintLogger) Info(msg string, args ...any) { | ||
fmt.Printf("Autometrics - Info: %v", fmt.Sprintf(msg, args...)) | ||
} | ||
func (_ PrintLogger) InfoContext(ctx context.Context, msg string, args ...any) { | ||
fmt.Printf("Autometrics - Info: %v", fmt.Sprintf(msg, args...)) | ||
} | ||
func (_ PrintLogger) Warn(msg string, args ...any) { | ||
fmt.Printf("Autometrics - Warn: %v", fmt.Sprintf(msg, args...)) | ||
} | ||
func (_ PrintLogger) WarnContext(ctx context.Context, msg string, args ...any) { | ||
fmt.Printf("Autometrics - Warn: %v", fmt.Sprintf(msg, args...)) | ||
} | ||
func (_ PrintLogger) Error(msg string, args ...any) { | ||
fmt.Printf("Autometrics - Error: %v", fmt.Sprintf(msg, args...)) | ||
} | ||
func (_ PrintLogger) ErrorContext(ctx context.Context, msg string, args ...any) { | ||
fmt.Printf("Autometrics - Error: %v", fmt.Sprintf(msg, args...)) | ||
} |
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