Improve client logging.
This commit is contained in:
@@ -19,8 +19,10 @@ var (
|
||||
|
||||
// Application is a lifecycle controlling structure for application.
|
||||
type Application struct {
|
||||
fyneApp fyne.App
|
||||
services []Service
|
||||
fyneApp fyne.App
|
||||
baseLogger *slog.Logger
|
||||
appLogger *slog.Logger
|
||||
services []Service
|
||||
}
|
||||
|
||||
// New creates new instance of lifecycle controlling structure.
|
||||
@@ -39,7 +41,7 @@ func (a *Application) configure() error {
|
||||
continue
|
||||
}
|
||||
|
||||
slog.Debug("Launching configuration procedure for service", "service", service.Name())
|
||||
a.appLogger.Debug("Launching configuration procedure for service", "service", service.Name())
|
||||
|
||||
if err := service.Configure(); err != nil {
|
||||
return fmt.Errorf("configure service '%s': %w", service.Name(), err)
|
||||
@@ -52,7 +54,7 @@ func (a *Application) configure() error {
|
||||
continue
|
||||
}
|
||||
|
||||
slog.Debug("Launching configuration procedure for service", "service", service.Name())
|
||||
a.appLogger.Debug("Launching configuration procedure for service", "service", service.Name())
|
||||
|
||||
if err := service.Configure(); err != nil {
|
||||
return fmt.Errorf("configure service '%s': %w", service.Name(), err)
|
||||
@@ -69,7 +71,7 @@ func (a *Application) connectDependencies() error {
|
||||
continue
|
||||
}
|
||||
|
||||
slog.Debug("Connecting dependencies for service.", "service", service.Name())
|
||||
a.appLogger.Debug("Connecting dependencies for service.", "service", service.Name())
|
||||
|
||||
if err := service.ConnectDependencies(); err != nil {
|
||||
return fmt.Errorf("connect dependencies for service '%s': %w", service.Name(), err)
|
||||
@@ -82,7 +84,7 @@ func (a *Application) connectDependencies() error {
|
||||
continue
|
||||
}
|
||||
|
||||
slog.Debug("Connecting dependencies for service.", "service", service.Name())
|
||||
a.appLogger.Debug("Connecting dependencies for service.", "service", service.Name())
|
||||
|
||||
if err := service.ConnectDependencies(); err != nil {
|
||||
return fmt.Errorf("connect dependencies for service '%s': %w", service.Name(), err)
|
||||
@@ -104,6 +106,8 @@ func (a *Application) ContextWithTimeout(timeout time.Duration) context.Context
|
||||
}
|
||||
|
||||
func (a *Application) initialize() {
|
||||
a.initializeLogger()
|
||||
|
||||
a.services = make([]Service, 0)
|
||||
|
||||
a.initializeFyne()
|
||||
@@ -119,7 +123,7 @@ func (a *Application) launchStartupTasks() error {
|
||||
continue
|
||||
}
|
||||
|
||||
slog.Debug("Launching startup tasks for service.", "service", service.Name())
|
||||
a.appLogger.Debug("Launching startup tasks for service.", "service", service.Name())
|
||||
|
||||
if err := service.LaunchStartupTasks(); err != nil {
|
||||
return fmt.Errorf("launch startup tasks for core/%s: %w", service.Name(), err)
|
||||
@@ -131,7 +135,7 @@ func (a *Application) launchStartupTasks() error {
|
||||
continue
|
||||
}
|
||||
|
||||
slog.Debug("Launching startup tasks for service.", "service", service.Name())
|
||||
a.appLogger.Debug("Launching startup tasks for service.", "service", service.Name())
|
||||
|
||||
if err := service.LaunchStartupTasks(); err != nil {
|
||||
return fmt.Errorf("launch startup tasks for core/%s: %w", service.Name(), err)
|
||||
@@ -161,7 +165,7 @@ func (a *Application) launchStartupTasks() error {
|
||||
|
||||
// Shutdown stops application
|
||||
func (a *Application) Shutdown() error {
|
||||
slog.Info("Stopping pztrn's Bunker...")
|
||||
a.appLogger.Info("Stopping pztrn's Bunker...")
|
||||
|
||||
// Сначала тушим фичи.
|
||||
for _, service := range a.services {
|
||||
@@ -169,7 +173,7 @@ func (a *Application) Shutdown() error {
|
||||
continue
|
||||
}
|
||||
|
||||
slog.Debug("Shutting down service.", "service", service.Name())
|
||||
a.appLogger.Debug("Shutting down service.", "service", service.Name())
|
||||
|
||||
if err := service.Shutdown(); err != nil {
|
||||
return fmt.Errorf("shutting down service '%s': %w", service.Name(), err)
|
||||
@@ -182,7 +186,7 @@ func (a *Application) Shutdown() error {
|
||||
continue
|
||||
}
|
||||
|
||||
slog.Debug("Shutting down service.", "service", service.Name())
|
||||
a.appLogger.Debug("Shutting down service.", "service", service.Name())
|
||||
|
||||
if err := service.Shutdown(); err != nil {
|
||||
return fmt.Errorf("shutting down service '%s': %w", service.Name(), err)
|
||||
|
20
client/internal/application/logger.go
Normal file
20
client/internal/application/logger.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"os"
|
||||
)
|
||||
|
||||
func (a *Application) initializeLogger() {
|
||||
a.baseLogger = slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
|
||||
AddSource: true,
|
||||
Level: slog.LevelDebug,
|
||||
}))
|
||||
|
||||
a.appLogger = a.baseLogger.With("module", "application")
|
||||
}
|
||||
|
||||
// NewLogger creates new sub-instance of base logger and adds some additional data to it for persistent output.
|
||||
func (a *Application) NewLogger(withs ...interface{}) *slog.Logger {
|
||||
return a.baseLogger.With(withs...)
|
||||
}
|
Reference in New Issue
Block a user