generated from okp4/template-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): add log_level option for customizable logging
- Loading branch information
Showing
5 changed files
with
91 additions
and
13 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,49 @@ | ||
package logger | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"strings" | ||
|
||
"github.com/sourcegraph/conc/iter" | ||
"github.com/teambenny/goetl/logger" | ||
|
||
"cosmossdk.io/log" | ||
) | ||
|
||
type etlLogger struct { | ||
logger log.Logger | ||
} | ||
|
||
func NewETLLogger(l log.Logger) logger.ETLNotifier { | ||
return &etlLogger{ | ||
logger: l, | ||
} | ||
} | ||
|
||
func InstallETLLogger(l log.Logger) { | ||
logger.Notifier = NewETLLogger(l) | ||
logger.SetOutput(io.Discard) | ||
} | ||
|
||
// ETLNotifier is an interface for receiving log events from goetl. | ||
func (l *etlLogger) ETLNotify(lvl int, _ []byte, v ...interface{}) { | ||
s := func() string { | ||
return strings.Join(iter.Map(v, func(it *interface{}) string { | ||
return fmt.Sprint(*it) | ||
}), " ") | ||
} | ||
|
||
switch lvl { | ||
case logger.LevelDebug: | ||
l.logger.Debug(s()) | ||
case logger.LevelInfo: | ||
l.logger.Info(s()) | ||
case logger.LevelError: | ||
l.logger.Error(s()) | ||
case logger.LevelStatus: | ||
l.logger.Info(s()) | ||
case logger.LevelSilent: | ||
// shh | ||
} | ||
} |