This repository has been archived by the owner on Feb 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Logger framework and trade.go example (#88)
Logger Interface with basic implementation and first conversion
- Loading branch information
1 parent
25db011
commit 7366a03
Showing
3 changed files
with
114 additions
and
56 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,35 @@ | ||
package logger | ||
|
||
import "log" | ||
|
||
// basicLogger is a standard logger | ||
type basicLogger struct { | ||
} | ||
|
||
// Info impl | ||
func (l *basicLogger) Info(msg string) { | ||
log.Println(msg) | ||
} | ||
|
||
// Infof impl | ||
func (l *basicLogger) Infof(msg string, args ...interface{}) { | ||
log.Printf(msg, args...) | ||
} | ||
|
||
// Error impl | ||
func (l *basicLogger) Error(msg string) { | ||
log.Print(msg) | ||
} | ||
|
||
// Efforf impl | ||
func (l *basicLogger) Errorf(msg string, args ...interface{}) { | ||
log.Printf(msg, args...) | ||
} | ||
|
||
// ensure it implements Logger | ||
var _ Logger = &basicLogger{} | ||
|
||
// MakeBasicLogger is the factory method | ||
func MakeBasicLogger() Logger { | ||
return &basicLogger{} | ||
} |
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,25 @@ | ||
package logger | ||
|
||
import "os" | ||
|
||
// Logger is the base logger interface | ||
type Logger interface { | ||
// basic messages, appends a newline (\n) after each entry | ||
Info(msg string) | ||
|
||
// basic messages, can be custom formatted, similar to fmt.Printf. User needs to add a \n if they want a newline after the log entry | ||
Infof(msg string, args ...interface{}) | ||
|
||
// error messages, indicates to the logger that these messages can be handled differently (different color, special format, email alerts, etc.). The type of logger will determine what to do with these messages. The logger should NOT panic on these messages. Appends a newline (\n) after each entry. | ||
Error(msg string) | ||
|
||
// error messages, indicates to the logger that these messages can be handled differently (different color, special format, email alerts, etc.). The type of logger will determine what to do with these messages. The logger should NOT panic on these messages. User needs to add a \n if they want a newline after the log entry. | ||
Errorf(msg string, args ...interface{}) | ||
} | ||
|
||
// Fatal is a convenience method that can be used with any Logger to log a fatal error | ||
func Fatal(l Logger, e error) { | ||
l.Info("") | ||
l.Errorf("%s", e) | ||
os.Exit(1) | ||
} |