Skip to content

Commit

Permalink
Add wrapper around olric log (#289)
Browse files Browse the repository at this point in the history
* Add wrapper around olric logger

* Remove remaining print
  • Loading branch information
seunghyupoh3517 authored and slayer321 committed Sep 5, 2022
1 parent ddc4fda commit 2e863d5
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions pkg/distcache/olric-logwriter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package distcache

import (
"bytes"

"github.com/fluxninja/aperture/pkg/log"
)

// OlricLogWriter is wrapper around aperture Logger that parse the message before writing to olricConfig.LogOutput.
type OlricLogWriter struct {
Logger log.Logger
}

// Write writes the message and logs in aperture Logger format.
func (ol *OlricLogWriter) Write(message []byte) (int, error) {
message = bytes.TrimSpace(message)
if len(message) < 2 {
ol.Logger.Info().Msg(string(message))
} else {
switch message[1] {
case 'I':
ol.Logger.Info().Msg(string(message[7:]))
case 'W':
ol.Logger.Warn().Msg(string(message[7:]))
case 'E':
ol.Logger.Error().Msg(string(message[8:]))
case 'D':
ol.Logger.Debug().Msg(string(message[8:]))
default:
ol.Logger.Info().Msg(string(message))
}
}
return len(message), nil
}

0 comments on commit 2e863d5

Please sign in to comment.