Skip to content

Commit

Permalink
better logging
Browse files Browse the repository at this point in the history
  • Loading branch information
FZambia committed Nov 14, 2024
1 parent 98fd4d6 commit b92e163
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
8 changes: 4 additions & 4 deletions internal/app/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ func configureEngines(node *centrifuge.Node, cfgContainer *config.Container) (en
default:
return modes, fmt.Errorf("unknown engine type: %s", cfg.Engine.Type)
}
if err != nil {
return modes, fmt.Errorf("error creating engine: %v", err)
}
event := log.Info().Str("engine_type", cfg.Engine.Type)
if modes.engineMode != "" {
event.Str("engine_mode", modes.engineMode)
}
event.Msg("engine is enabled")
event.Msg("initializing redis engine")
if err != nil {
return modes, fmt.Errorf("error creating redis engine: %v", err)
}
} else {
log.Info().Msgf("both broker and presence manager enabled, skip engine initialization")
}
Expand Down
17 changes: 13 additions & 4 deletions internal/app/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,22 @@ func Run(cmd *cobra.Command, configFile string) {
log.Info().Msgf(strings.ToLower(s), i...)
}))

log.Info().
entry := log.Info().
Str("version", build.Version).
Str("runtime", runtime.Version()).
Int("pid", os.Getpid()).
Str("broker", cfg.Broker.Type).
Str("presence_manager", cfg.PresenceManager.Type).
Int("gomaxprocs", runtime.GOMAXPROCS(0)).Msg("starting Centrifugo")
Int("gomaxprocs", runtime.GOMAXPROCS(0))

if cfg.Broker.Enabled {
entry = entry.Str("broker", cfg.Broker.Type)
}
if cfg.PresenceManager.Enabled {
entry = entry.Str("presence_manager", cfg.PresenceManager.Type)
}
if !cfg.Broker.Enabled || !cfg.PresenceManager.Enabled {
entry = entry.Str("engine", cfg.Engine.Type)
}
entry.Msg("starting Centrifugo")

err = cfg.Validate()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/confighelpers/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ func getRedisShardConfigs(redisConf configtypes.Redis) ([]centrifuge.RedisShardC
func CentrifugeRedisShards(n *centrifuge.Node, redisConf configtypes.Redis) ([]*centrifuge.RedisShard, string, error) {
redisShardConfigs, mode, err := getRedisShardConfigs(redisConf)
if err != nil {
return nil, "", err
return nil, mode, err
}
redisShards := make([]*centrifuge.RedisShard, 0, len(redisShardConfigs))

for _, shardConf := range redisShardConfigs {
redisShard, err := centrifuge.NewRedisShard(n, shardConf)
if err != nil {
return nil, "", err
return nil, mode, err
}
redisShards = append(redisShards, redisShard)
}
Expand Down

0 comments on commit b92e163

Please sign in to comment.