Skip to content

Commit

Permalink
Improve log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
pouya-eghbali committed Apr 8, 2024
1 parent 3611fa3 commit f2bed6d
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 10 deletions.
3 changes: 2 additions & 1 deletion internal/cmd/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ var brokerCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
log.Start(config.App.System.Log)
log.Logger.
With("Mode", "Broker").
With("Version", constants.Version).
With("Protocol", constants.ProtocolVersion).
Info("Running Unchained | Broker")
Info("Running Unchained")

err := config.Load(configPath, secretsPath)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ var consumerCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
log.Start(config.App.System.Log)
log.Logger.
With("Mode", "Consumer").
With("Version", constants.Version).
With("Protocol", constants.ProtocolVersion).
Info("Running Unchained | Consumer")
Info("Running Unchained")

err := config.Load(configPath, secretsPath)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ var workerCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
log.Start(config.App.System.Log)
log.Logger.
With("Mode", "Worker").
With("Version", constants.Version).
With("Protocol", constants.ProtocolVersion).
Info("Running Unchained | Worker")
Info("Running Unchained ")

err := config.Load(configPath, secretsPath)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion internal/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ func WithUniswapEvents(
}

func (s *Scheduler) AddTask(duration time.Duration, task Task) {
log.Logger.With("duration", duration).Info("Register a new task")
log.Logger.
With("duration", duration).
Info("New UniSwap task scheduled.")

_, err := s.scheduler.NewJob(
gocron.DurationJob(duration),
Expand Down
4 changes: 2 additions & 2 deletions internal/transport/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func Consume(handler handler.Handler) {
case opcodes.Feedback:
log.Logger.
With("Feedback", string(payload[1:])).
Warn("Broker")
Info("Broker")

case opcodes.KoskChallenge:
challenge := handler.Challenge(payload[1:])
Expand All @@ -41,7 +41,7 @@ func Consume(handler handler.Handler) {
default:
log.Logger.
With("Code", payload[0]).
Info("Unknown call code")
Error("Unknown call code")
}
}
}()
Expand Down
4 changes: 3 additions & 1 deletion internal/transport/client/conn/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ var mu = new(sync.Mutex)
func Start() {
var err error

log.Logger.With("URL", fmt.Sprintf("%s/%s", config.App.Network.BrokerURI, constants.ProtocolVersion)).Info("Connecting to broker")
log.Logger.
With("URL", fmt.Sprintf("%s/%s", config.App.Network.BrokerURI, constants.ProtocolVersion)).
Info("Connecting to the broker")

conn, _, err = websocket.DefaultDialer.Dial(
fmt.Sprintf("%s/%s", config.App.Network.BrokerURI, constants.ProtocolVersion), nil,
Expand Down
4 changes: 3 additions & 1 deletion internal/transport/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ func New(options ...func()) {
option()
}

log.Logger.With("Bind", fmt.Sprintf("http://%s", config.App.Network.Bind)).Info("Server is starting")
log.Logger.
With("Bind", fmt.Sprintf("http://%s", config.App.Network.Bind)).
Info("Starting a HTTP server")

server := &http.Server{
Addr: config.App.Network.Bind,
Expand Down
4 changes: 2 additions & 2 deletions internal/transport/server/websocket/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var upgrader = websocket.Upgrader{}

func WithWebsocket() func() {
return func() {
log.Logger.Info("Websocket is activated")
log.Logger.Info("Starting a websocket server")

versionedRoot := fmt.Sprintf("/%s", constants.ProtocolVersion)
http.HandleFunc(versionedRoot, multiplexer)
Expand All @@ -27,7 +27,7 @@ func WithWebsocket() func() {
func multiplexer(w http.ResponseWriter, r *http.Request) {
conn, err := upgrader.Upgrade(w, r, nil)
if err != nil {
log.Logger.Error("Can't upgrade connection: %v", err)
log.Logger.Error("Can't upgrade the HTTP connection: %v", err)
return
}

Expand Down

0 comments on commit f2bed6d

Please sign in to comment.