-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: upgrade go version to go1.19 (#46)
* chore: upgrade go version to go1.19 * chore: upgrade github actions
- Loading branch information
1 parent
38ded5d
commit fbbc97b
Showing
6 changed files
with
82 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
//go:build !go1.16 | ||
// +build !go1.16 | ||
|
||
package easytcp | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
) | ||
|
||
var _ Logger = &DefaultLogger{} | ||
|
||
// Log is the instance of Logger interface. | ||
var Log Logger = newMuteLogger() | ||
|
||
// Logger is the generic interface for log recording. | ||
type Logger interface { | ||
Errorf(format string, args ...interface{}) | ||
Tracef(format string, args ...interface{}) | ||
} | ||
|
||
func newLogger() *DefaultLogger { | ||
return &DefaultLogger{ | ||
rawLogger: log.New(os.Stdout, "easytcp ", log.Ldate|log.Ltime|log.Lmicroseconds|log.Lmsgprefix), | ||
} | ||
} | ||
|
||
func newMuteLogger() *DefaultLogger { | ||
return &DefaultLogger{ | ||
rawLogger: log.New(ioutil.Discard, "easytcp", log.LstdFlags), | ||
} | ||
} | ||
|
||
// DefaultLogger is the default logger instance for this package. | ||
// DefaultLogger uses the built-in log.Logger. | ||
type DefaultLogger struct { | ||
rawLogger *log.Logger | ||
} | ||
|
||
// Errorf implements Logger Errorf method. | ||
func (d *DefaultLogger) Errorf(format string, args ...interface{}) { | ||
d.rawLogger.Printf("[ERROR] %s", fmt.Sprintf(format, args...)) | ||
} | ||
|
||
// Tracef implements Logger Tracef method. | ||
func (d *DefaultLogger) Tracef(format string, args ...interface{}) { | ||
d.rawLogger.Printf("[TRACE] %s", fmt.Sprintf(format, args...)) | ||
} | ||
|
||
// SetLogger sets the package logger. | ||
func SetLogger(lg Logger) { | ||
Log = lg | ||
} |
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