simplified logging.

This commit is contained in:
Miroslav Šedivý 2021-09-01 23:30:09 +02:00
parent 5130d94bbc
commit fd35254487
2 changed files with 40 additions and 77 deletions

View File

@ -45,63 +45,45 @@ type WebSocketManagerCtx struct {
func (manager *WebSocketManagerCtx) Start() { func (manager *WebSocketManagerCtx) Start() {
manager.sessions.OnCreated(func(session types.Session) { manager.sessions.OnCreated(func(session types.Session) {
logger := manager.logger.With().Str("session_id", session.ID()).Logger() err := manager.handler.SessionCreated(session)
manager.logger.Err(err).
if err := manager.handler.SessionCreated(session); err != nil { Str("session_id", session.ID()).
logger.Warn().Err(err).Msg("session created with an error") Msg("session created")
} else {
logger.Debug().Msg("session created")
}
}) })
manager.sessions.OnDeleted(func(session types.Session) { manager.sessions.OnDeleted(func(session types.Session) {
logger := manager.logger.With().Str("session_id", session.ID()).Logger() err := manager.handler.SessionDeleted(session)
manager.logger.Err(err).
if err := manager.handler.SessionDeleted(session); err != nil { Str("session_id", session.ID()).
logger.Warn().Err(err).Msg("session deleted with an error") Msg("session deleted")
} else {
logger.Debug().Msg("session deleted")
}
}) })
manager.sessions.OnConnected(func(session types.Session) { manager.sessions.OnConnected(func(session types.Session) {
logger := manager.logger.With().Str("session_id", session.ID()).Logger() err := manager.handler.SessionConnected(session)
manager.logger.Err(err).
if err := manager.handler.SessionConnected(session); err != nil { Str("session_id", session.ID()).
logger.Warn().Err(err).Msg("session connected with an error") Msg("session connected")
} else {
logger.Debug().Msg("session connected")
}
}) })
manager.sessions.OnDisconnected(func(session types.Session) { manager.sessions.OnDisconnected(func(session types.Session) {
logger := manager.logger.With().Str("session_id", session.ID()).Logger() err := manager.handler.SessionDisconnected(session)
manager.logger.Err(err).
if err := manager.handler.SessionDisconnected(session); err != nil { Str("session_id", session.ID()).
logger.Warn().Err(err).Msg("session disconnected with an error") Msg("session disconnected")
} else {
logger.Debug().Msg("session disconnected")
}
}) })
manager.sessions.OnProfileChanged(func(session types.Session) { manager.sessions.OnProfileChanged(func(session types.Session) {
logger := manager.logger.With().Str("session_id", session.ID()).Logger() err := manager.handler.SessionProfileChanged(session)
manager.logger.Err(err).
if err := manager.handler.SessionProfileChanged(session); err != nil { Str("session_id", session.ID()).
logger.Warn().Err(err).Msg("session profile changed with an error") Msg("session profile changed")
} else {
logger.Debug().Interface("profile", session.Profile()).Msg("session profile changed")
}
}) })
manager.sessions.OnStateChanged(func(session types.Session) { manager.sessions.OnStateChanged(func(session types.Session) {
logger := manager.logger.With().Str("session_id", session.ID()).Logger() err := manager.handler.SessionStateChanged(session)
manager.logger.Err(err).
if err := manager.handler.SessionStateChanged(session); err != nil { Str("session_id", session.ID()).
logger.Warn().Err(err).Msg("session state changed with an error") Msg("session state changed")
} else {
logger.Debug().Interface("state", session.State()).Msg("session state changed")
}
}) })
manager.sessions.OnHostChanged(func(session types.Session) { manager.sessions.OnHostChanged(func(session types.Session) {

51
neko.go
View File

@ -195,47 +195,28 @@ func (neko *Neko) Start() {
} }
func (neko *Neko) Shutdown() { func (neko *Neko) Shutdown() {
if err := neko.memberManager.Disconnect(); err != nil { var err error
neko.logger.Err(err).Msg("member manager disconnect with an error")
} else {
neko.logger.Debug().Msg("member manager disconnect")
}
if err := neko.desktopManager.Shutdown(); err != nil { err = neko.memberManager.Disconnect()
neko.logger.Err(err).Msg("desktop manager shutdown with an error") neko.logger.Err(err).Msg("member manager disconnect")
} else {
neko.logger.Debug().Msg("desktop manager shutdown")
}
if err := neko.captureManager.Shutdown(); err != nil { err = neko.desktopManager.Shutdown()
neko.logger.Err(err).Msg("capture manager shutdown with an error") neko.logger.Err(err).Msg("desktop manager shutdown")
} else {
neko.logger.Debug().Msg("capture manager shutdown")
}
if err := neko.webRTCManager.Shutdown(); err != nil { err = neko.captureManager.Shutdown()
neko.logger.Err(err).Msg("webrtc manager shutdown with an error") neko.logger.Err(err).Msg("capture manager shutdown")
} else {
neko.logger.Debug().Msg("webrtc manager shutdown")
}
if err := neko.webSocketManager.Shutdown(); err != nil { err = neko.webRTCManager.Shutdown()
neko.logger.Err(err).Msg("websocket manager shutdown with an error") neko.logger.Err(err).Msg("webrtc manager shutdown")
} else {
neko.logger.Debug().Msg("websocket manager shutdown")
}
if err := modules.Shutdown(); err != nil { err = neko.webSocketManager.Shutdown()
neko.logger.Err(err).Msg("modules shutdown with an error") neko.logger.Err(err).Msg("websocket manager shutdown")
} else {
neko.logger.Debug().Msg("modules shutdown")
}
if err := neko.httpManager.Shutdown(); err != nil { err = modules.Shutdown()
neko.logger.Err(err).Msg("http manager shutdown with an error") neko.logger.Err(err).Msg("modules shutdown")
} else {
neko.logger.Debug().Msg("http manager shutdown") err = neko.httpManager.Shutdown()
} neko.logger.Err(err).Msg("http manager shutdown")
} }
func (neko *Neko) ServeCommand(cmd *cobra.Command, args []string) { func (neko *Neko) ServeCommand(cmd *cobra.Command, args []string) {