summaryrefslogtreecommitdiffstats
path: root/bridge/matrix/zerolog_abstraction.go
diff options
context:
space:
mode:
authormsglm <msglm@techchud.xyz>2023-10-27 07:08:25 -0500
committermsglm <msglm@techchud.xyz>2023-10-27 07:08:25 -0500
commit032a7e0c1188d3507b8d9a9571f2446a43cf775b (patch)
tree2bd38c01bc7761a6195e426082ce7191ebc765a1 /bridge/matrix/zerolog_abstraction.go
parent56e7bd01ca09ad52b0c4f48f146a20a4f1b78696 (diff)
downloadmatterbridge-msglm-1.26.0+0.1.0.tar.gz
matterbridge-msglm-1.26.0+0.1.0.tar.bz2
matterbridge-msglm-1.26.0+0.1.0.zip
apply https://github.com/42wim/matterbridge/pull/1864v1.26.0+0.1.0
Diffstat (limited to 'bridge/matrix/zerolog_abstraction.go')
-rw-r--r--bridge/matrix/zerolog_abstraction.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/bridge/matrix/zerolog_abstraction.go b/bridge/matrix/zerolog_abstraction.go
new file mode 100644
index 00000000..3d74a4e0
--- /dev/null
+++ b/bridge/matrix/zerolog_abstraction.go
@@ -0,0 +1,43 @@
+package bmatrix
+
+import (
+ "errors"
+
+ "github.com/sirupsen/logrus"
+
+ "github.com/rs/zerolog"
+)
+
+var levels_zerolog2logrus = map[zerolog.Level]logrus.Level{
+ zerolog.DebugLevel: logrus.DebugLevel,
+ zerolog.InfoLevel: logrus.InfoLevel,
+ zerolog.WarnLevel: logrus.WarnLevel,
+ zerolog.FatalLevel: logrus.FatalLevel,
+ zerolog.PanicLevel: logrus.PanicLevel,
+ zerolog.ErrorLevel: logrus.ErrorLevel,
+ zerolog.TraceLevel: logrus.TraceLevel,
+}
+
+// an abstraction for zerolog so we can pipe its output to logrus.Entry, that is used in matterbridge
+type zerologWrapper struct {
+ inner *logrus.Entry
+}
+
+func (w zerologWrapper) Write(p []byte) (n int, err error) {
+ return w.inner.Logger.Writer().Write(p)
+}
+
+func (w zerologWrapper) WriteLevel(level zerolog.Level, p []byte) (n int, err error) {
+ if logrus_level, present := levels_zerolog2logrus[level]; present {
+ return w.inner.Logger.WriterLevel(logrus_level).Write(p)
+ }
+ // drop the message if we haven't a matching level
+ return 0, errors.New("Unsupported logging level")
+}
+
+func NewZerologWrapper(entry *logrus.Entry) zerolog.Logger {
+ wrapper := zerologWrapper{inner: entry}
+ log := zerolog.New(wrapper)
+
+ return log
+}