aboutsummaryrefslogtreecommitdiff
path: root/setup
diff options
context:
space:
mode:
authorDavid Schneider <dsbrng25b@gmail.com>2023-02-24 08:56:53 +0100
committerGitHub <noreply@github.com>2023-02-24 08:56:53 +0100
commite6aa0955ff4113114ff8f30073582cc4ecc454fa (patch)
tree54346c6f5ad09a82f13515f0c64edac512de62a9 /setup
parentd34277a6c0d366631721b47a1b003739ce0ad538 (diff)
Unify logging by using logrus for jetstream logs (#2976)
I guess tests for the logging is rather unusual so I omitted tests for this change. * [x] I have added Go unit tests or [Complement integration tests](https://github.com/matrix-org/complement) for this PR _or_ I have justified why this PR doesn't need tests * [x] Pull request includes a [sign off below using a legally identifiable name](https://matrix-org.github.io/dendrite/development/contributing#sign-off) _or_ I have already signed off privately Signed-off-by: `David Schneider <dsbrng25b@gmail.com>` --------- Signed-off-by: David Schneider <dsbrng25b@gmail.com>
Diffstat (limited to 'setup')
-rw-r--r--setup/jetstream/log.go42
-rw-r--r--setup/jetstream/nats.go7
2 files changed, 46 insertions, 3 deletions
diff --git a/setup/jetstream/log.go b/setup/jetstream/log.go
new file mode 100644
index 00000000..880f7120
--- /dev/null
+++ b/setup/jetstream/log.go
@@ -0,0 +1,42 @@
+package jetstream
+
+import (
+ "github.com/nats-io/nats-server/v2/server"
+ "github.com/sirupsen/logrus"
+)
+
+var _ server.Logger = &LogAdapter{}
+
+type LogAdapter struct {
+ entry *logrus.Entry
+}
+
+func NewLogAdapter() *LogAdapter {
+ return &LogAdapter{
+ entry: logrus.StandardLogger().WithField("component", "jetstream"),
+ }
+}
+
+func (l *LogAdapter) Noticef(format string, v ...interface{}) {
+ l.entry.Infof(format, v...)
+}
+
+func (l *LogAdapter) Warnf(format string, v ...interface{}) {
+ l.entry.Warnf(format, v...)
+}
+
+func (l *LogAdapter) Fatalf(format string, v ...interface{}) {
+ l.entry.Fatalf(format, v...)
+}
+
+func (l *LogAdapter) Errorf(format string, v ...interface{}) {
+ l.entry.Errorf(format, v...)
+}
+
+func (l *LogAdapter) Debugf(format string, v ...interface{}) {
+ l.entry.Debugf(format, v...)
+}
+
+func (l *LogAdapter) Tracef(format string, v ...interface{}) {
+ l.entry.Tracef(format, v...)
+}
diff --git a/setup/jetstream/nats.go b/setup/jetstream/nats.go
index af4eb294..01fec9ad 100644
--- a/setup/jetstream/nats.go
+++ b/setup/jetstream/nats.go
@@ -40,7 +40,7 @@ func (s *NATSInstance) Prepare(process *process.ProcessContext, cfg *config.JetS
}
if s.Server == nil {
var err error
- s.Server, err = natsserver.NewServer(&natsserver.Options{
+ opts := &natsserver.Options{
ServerName: "monolith",
DontListen: true,
JetStream: true,
@@ -49,11 +49,12 @@ func (s *NATSInstance) Prepare(process *process.ProcessContext, cfg *config.JetS
MaxPayload: 16 * 1024 * 1024,
NoSigs: true,
NoLog: cfg.NoLog,
- })
+ }
+ s.Server, err = natsserver.NewServer(opts)
if err != nil {
panic(err)
}
- s.ConfigureLogger()
+ s.SetLogger(NewLogAdapter(), opts.Debug, opts.Trace)
go func() {
process.ComponentStarted()
s.Start()