-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add support for optional mappers, per level * lint: suppress false-positive dup detection * add example of mapper with colors
- Loading branch information
Showing
6 changed files
with
149 additions
and
7 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 |
---|---|---|
|
@@ -2,4 +2,4 @@ module github.com/go-pkgz/lgr | |
|
||
require github.com/stretchr/testify v1.5.1 | ||
|
||
go 1.14 | ||
go 1.15 |
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,26 @@ | ||
package lgr | ||
|
||
// Mapper defines optional functions to change elements of the logged message for each part, based on levels. | ||
// Only some mapFunc can be defined, by default does nothing. Can be used to alter the output, for example making some | ||
// part of the output colorful. | ||
type Mapper struct { | ||
ErrorFunc mapFunc | ||
WarnFunc mapFunc | ||
InfoFunc mapFunc | ||
DebugFunc mapFunc | ||
|
||
CallerFunc mapFunc | ||
TimeFunc mapFunc | ||
} | ||
|
||
type mapFunc func(string) string | ||
|
||
// nopMapper is a default, doing nothing | ||
var nopMapper = Mapper{ | ||
ErrorFunc: func(s string) string { return s }, | ||
WarnFunc: func(s string) string { return s }, | ||
InfoFunc: func(s string) string { return s }, | ||
DebugFunc: func(s string) string { return s }, | ||
CallerFunc: func(s string) string { return s }, | ||
TimeFunc: func(s string) string { return s }, | ||
} |
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