From fd3525448726654c6c5d402c178964b911ff1325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Wed, 1 Sep 2021 23:30:09 +0200 Subject: [PATCH] simplified logging. --- internal/websocket/manager.go | 66 +++++++++++++---------------------- neko.go | 51 +++++++++------------------ 2 files changed, 40 insertions(+), 77 deletions(-) diff --git a/internal/websocket/manager.go b/internal/websocket/manager.go index 222a52a6..421ab31f 100644 --- a/internal/websocket/manager.go +++ b/internal/websocket/manager.go @@ -45,63 +45,45 @@ type WebSocketManagerCtx struct { func (manager *WebSocketManagerCtx) Start() { manager.sessions.OnCreated(func(session types.Session) { - logger := manager.logger.With().Str("session_id", session.ID()).Logger() - - if err := manager.handler.SessionCreated(session); err != nil { - logger.Warn().Err(err).Msg("session created with an error") - } else { - logger.Debug().Msg("session created") - } + err := manager.handler.SessionCreated(session) + manager.logger.Err(err). + Str("session_id", session.ID()). + Msg("session created") }) manager.sessions.OnDeleted(func(session types.Session) { - logger := manager.logger.With().Str("session_id", session.ID()).Logger() - - if err := manager.handler.SessionDeleted(session); err != nil { - logger.Warn().Err(err).Msg("session deleted with an error") - } else { - logger.Debug().Msg("session deleted") - } + err := manager.handler.SessionDeleted(session) + manager.logger.Err(err). + Str("session_id", session.ID()). + Msg("session deleted") }) manager.sessions.OnConnected(func(session types.Session) { - logger := manager.logger.With().Str("session_id", session.ID()).Logger() - - if err := manager.handler.SessionConnected(session); err != nil { - logger.Warn().Err(err).Msg("session connected with an error") - } else { - logger.Debug().Msg("session connected") - } + err := manager.handler.SessionConnected(session) + manager.logger.Err(err). + Str("session_id", session.ID()). + Msg("session connected") }) manager.sessions.OnDisconnected(func(session types.Session) { - logger := manager.logger.With().Str("session_id", session.ID()).Logger() - - if err := manager.handler.SessionDisconnected(session); err != nil { - logger.Warn().Err(err).Msg("session disconnected with an error") - } else { - logger.Debug().Msg("session disconnected") - } + err := manager.handler.SessionDisconnected(session) + manager.logger.Err(err). + Str("session_id", session.ID()). + Msg("session disconnected") }) manager.sessions.OnProfileChanged(func(session types.Session) { - logger := manager.logger.With().Str("session_id", session.ID()).Logger() - - if err := manager.handler.SessionProfileChanged(session); err != nil { - logger.Warn().Err(err).Msg("session profile changed with an error") - } else { - logger.Debug().Interface("profile", session.Profile()).Msg("session profile changed") - } + err := manager.handler.SessionProfileChanged(session) + manager.logger.Err(err). + Str("session_id", session.ID()). + Msg("session profile changed") }) manager.sessions.OnStateChanged(func(session types.Session) { - logger := manager.logger.With().Str("session_id", session.ID()).Logger() - - if err := manager.handler.SessionStateChanged(session); err != nil { - logger.Warn().Err(err).Msg("session state changed with an error") - } else { - logger.Debug().Interface("state", session.State()).Msg("session state changed") - } + err := manager.handler.SessionStateChanged(session) + manager.logger.Err(err). + Str("session_id", session.ID()). + Msg("session state changed") }) manager.sessions.OnHostChanged(func(session types.Session) { diff --git a/neko.go b/neko.go index 4448dfe4..4328ba04 100644 --- a/neko.go +++ b/neko.go @@ -195,47 +195,28 @@ func (neko *Neko) Start() { } func (neko *Neko) Shutdown() { - if err := neko.memberManager.Disconnect(); err != nil { - neko.logger.Err(err).Msg("member manager disconnect with an error") - } else { - neko.logger.Debug().Msg("member manager disconnect") - } + var err error - if err := neko.desktopManager.Shutdown(); err != nil { - neko.logger.Err(err).Msg("desktop manager shutdown with an error") - } else { - neko.logger.Debug().Msg("desktop manager shutdown") - } + err = neko.memberManager.Disconnect() + neko.logger.Err(err).Msg("member manager disconnect") - if err := neko.captureManager.Shutdown(); err != nil { - neko.logger.Err(err).Msg("capture manager shutdown with an error") - } else { - neko.logger.Debug().Msg("capture manager shutdown") - } + err = neko.desktopManager.Shutdown() + neko.logger.Err(err).Msg("desktop manager shutdown") - if err := neko.webRTCManager.Shutdown(); err != nil { - neko.logger.Err(err).Msg("webrtc manager shutdown with an error") - } else { - neko.logger.Debug().Msg("webrtc manager shutdown") - } + err = neko.captureManager.Shutdown() + neko.logger.Err(err).Msg("capture manager shutdown") - if err := neko.webSocketManager.Shutdown(); err != nil { - neko.logger.Err(err).Msg("websocket manager shutdown with an error") - } else { - neko.logger.Debug().Msg("websocket manager shutdown") - } + err = neko.webRTCManager.Shutdown() + neko.logger.Err(err).Msg("webrtc manager shutdown") - if err := modules.Shutdown(); err != nil { - neko.logger.Err(err).Msg("modules shutdown with an error") - } else { - neko.logger.Debug().Msg("modules shutdown") - } + err = neko.webSocketManager.Shutdown() + neko.logger.Err(err).Msg("websocket manager shutdown") - if err := neko.httpManager.Shutdown(); err != nil { - neko.logger.Err(err).Msg("http manager shutdown with an error") - } else { - neko.logger.Debug().Msg("http manager shutdown") - } + err = modules.Shutdown() + neko.logger.Err(err).Msg("modules shutdown") + + err = neko.httpManager.Shutdown() + neko.logger.Err(err).Msg("http manager shutdown") } func (neko *Neko) ServeCommand(cmd *cobra.Command, args []string) {