-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add wrapper around olric logger * Remove remaining print
- Loading branch information
1 parent
3e5792b
commit 19b8abc
Showing
4 changed files
with
39 additions
and
3 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
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 | ||
} |
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