Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion broker/channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/meshery/meshkit/broker"
"github.com/meshery/meshkit/logger"
"github.com/meshery/meshkit/utils"
"github.com/sirupsen/logrus"
)

type ChannelBrokerHandler struct {
Expand All @@ -35,7 +36,7 @@ func NewChannelBrokerHandler(optsSetters ...OptionsSetter) *ChannelBrokerHandler
var err error
log, err = logger.New("channel-broker", logger.Options{
Format: logger.TerminalLogFormat,
LogLevel: 4, // Info level
LogLevel: int(logrus.InfoLevel),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While using logrus.InfoLevel is a great improvement over the magic number 4, it introduces a direct dependency on the logrus package here. This couples the broker package to the implementation details of the logger package.

A better long-term solution would be for the logger package to expose its own log level constants (e.g., logger.InfoLevel). This would allow consumer packages to depend only on the logger abstraction, not its underlying logrus implementation, and would remove the need to import logrus in this file.

Since changing the logger package is likely outside the scope of this PR, the current change is a good step forward. You might consider creating a follow-up technical debt ticket to address this.

})
if err != nil {
// Fallback to a simple logger if creation fails
Expand Down
5 changes: 3 additions & 2 deletions broker/nats/nats.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/meshery/meshkit/broker"
"github.com/meshery/meshkit/logger"
nats "github.com/nats-io/nats.go"
"github.com/sirupsen/logrus"
)

var (
Expand Down Expand Up @@ -98,7 +99,7 @@ func New(opts Options) (broker.Handler, error) {
var lerr error
lg, lerr = logger.New("nats-handler", logger.Options{
Format: logger.TerminalLogFormat,
LogLevel: 4, // Info
LogLevel: int(logrus.InfoLevel),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the other file in this PR, using logrus.InfoLevel here is a good improvement for readability. However, it creates a dependency on logrus just for a constant.

To improve encapsulation, the logger package could define and expose its own log level constants. This would mean consumer packages like this one wouldn't need to import logrus directly, making the logger a more complete abstraction. This could be a good candidate for a future refactoring task.

})
if lerr != nil {
// fallback to nil; we'll use std log where necessary
Expand Down Expand Up @@ -277,4 +278,4 @@ func (in *Nats) IsEmpty() bool {
return true
}
return in.nc == nil && in.wg == nil && in.ctx == nil && in.cancel == nil
}
}