-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix tail library logs to use our own log format (#579)
* fix tail library logs to use our own log format * PR Feedbacks
- Loading branch information
1 parent
b8d5868
commit 2561a70
Showing
2 changed files
with
78 additions
and
0 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,74 @@ | ||
package util | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/go-kit/kit/log" | ||
"github.com/go-kit/kit/log/level" | ||
) | ||
|
||
type LogAdapater struct { | ||
log.Logger | ||
} | ||
|
||
func NewLogAdapater(l log.Logger) LogAdapater { | ||
return LogAdapater{ | ||
Logger: l, | ||
} | ||
} | ||
|
||
// Fatal implements tail.logger | ||
func (l LogAdapater) Fatal(v ...interface{}) { | ||
level.Error(l).Log("msg", fmt.Sprint(v...)) | ||
os.Exit(1) | ||
} | ||
|
||
// Fatalf implements tail.logger | ||
func (l LogAdapater) Fatalf(format string, v ...interface{}) { | ||
level.Error(l).Log("msg", fmt.Sprintf(strings.TrimSuffix(format, "\n"), v...)) | ||
os.Exit(1) | ||
} | ||
|
||
// Fatalln implements tail.logger | ||
func (l LogAdapater) Fatalln(v ...interface{}) { | ||
level.Error(l).Log("msg", fmt.Sprint(v...)) | ||
os.Exit(1) | ||
} | ||
|
||
// Panic implements tail.logger | ||
func (l LogAdapater) Panic(v ...interface{}) { | ||
s := fmt.Sprint(v...) | ||
level.Error(l).Log("msg", s) | ||
panic(s) | ||
} | ||
|
||
// Panicf implements tail.logger | ||
func (l LogAdapater) Panicf(format string, v ...interface{}) { | ||
s := fmt.Sprintf(strings.TrimSuffix(format, "\n"), v...) | ||
level.Error(l).Log("msg", s) | ||
panic(s) | ||
} | ||
|
||
// Panicln implements tail.logger | ||
func (l LogAdapater) Panicln(v ...interface{}) { | ||
s := fmt.Sprint(v...) | ||
level.Error(l).Log("msg", s) | ||
panic(s) | ||
} | ||
|
||
// Print implements tail.logger | ||
func (l LogAdapater) Print(v ...interface{}) { | ||
level.Info(l).Log("msg", fmt.Sprint(v...)) | ||
} | ||
|
||
// Printf implements tail.logger | ||
func (l LogAdapater) Printf(format string, v ...interface{}) { | ||
level.Info(l).Log("msg", fmt.Sprintf(strings.TrimSuffix(format, "\n"), v...)) | ||
} | ||
|
||
// Println implements tail.logger | ||
func (l LogAdapater) Println(v ...interface{}) { | ||
level.Info(l).Log("msg", fmt.Sprint(v...)) | ||
} |