Skip to content

Commit

Permalink
Merge pull request #7 from helmwave/strings-replacer
Browse files Browse the repository at this point in the history
Use strings.Replacer
  • Loading branch information
r3nic1e authored Aug 4, 2022
2 parents b749d16 + f79dd0b commit 46997d6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
repos:
- repo: https://github.com/dnephin/pre-commit-golang
rev: v0.4.0
hooks:
- id: go-fmt
- id: golangci-lint
- id: go-mod-tidy
18 changes: 11 additions & 7 deletions func.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ const (

// Format building log message.
func (f *Config) Format(entry *logrus.Entry) ([]byte, error) {
output := f.LogFormat
if output == "" {
output = defaultLogFormat
format := f.LogFormat
if format == "" {
format = defaultLogFormat
}

timestampFormat := f.TimestampFormat
Expand All @@ -45,10 +45,14 @@ func (f *Config) Format(entry *logrus.Entry) ([]byte, error) {
fieldPattern = start + logFieldColor + fieldPattern + end
}

output = strings.Replace(output, "%time%", entry.Time.Format(timestampFormat), 1)
output = strings.Replace(output, "%msg%", m, 1)
output = strings.Replace(output, "%lvl%", l, 1)
output = strings.Replace(output, "%emoji%", emoji, 1)
replacer := strings.NewReplacer(
"%time%", entry.Time.Format(timestampFormat),
"%msg%", m,
"%lvl%", l,
"%emoji%", emoji,
)

output := replacer.Replace(format)

for k, val := range entry.Data {
switch val := val.(type) {
Expand Down

0 comments on commit 46997d6

Please sign in to comment.