mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-06 07:54:22 +00:00
Add logger to server
This commit is contained in:
@@ -3,6 +3,7 @@ package app
|
|||||||
import (
|
import (
|
||||||
"novamd/internal/auth"
|
"novamd/internal/auth"
|
||||||
"novamd/internal/db"
|
"novamd/internal/db"
|
||||||
|
"novamd/internal/logging"
|
||||||
"novamd/internal/storage"
|
"novamd/internal/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -11,6 +12,7 @@ type Options struct {
|
|||||||
Config *Config
|
Config *Config
|
||||||
Database db.Database
|
Database db.Database
|
||||||
Storage storage.Manager
|
Storage storage.Manager
|
||||||
|
Logger logging.Logger
|
||||||
JWTManager auth.JWTManager
|
JWTManager auth.JWTManager
|
||||||
SessionManager auth.SessionManager
|
SessionManager auth.SessionManager
|
||||||
CookieService auth.CookieManager
|
CookieService auth.CookieManager
|
||||||
@@ -33,6 +35,12 @@ func DefaultOptions(cfg *Config) (*Options, error) {
|
|||||||
// Initialize storage
|
// Initialize storage
|
||||||
storageManager := storage.NewService(cfg.WorkDir)
|
storageManager := storage.NewService(cfg.WorkDir)
|
||||||
|
|
||||||
|
// Initialize logger
|
||||||
|
logger, err := logging.New(cfg.LogDir, cfg.LogLevel, cfg.ConsoleOutput)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize auth services
|
// Initialize auth services
|
||||||
jwtManager, sessionService, cookieService, err := initAuth(cfg, database)
|
jwtManager, sessionService, cookieService, err := initAuth(cfg, database)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -48,6 +56,7 @@ func DefaultOptions(cfg *Config) (*Options, error) {
|
|||||||
Config: cfg,
|
Config: cfg,
|
||||||
Database: database,
|
Database: database,
|
||||||
Storage: storageManager,
|
Storage: storageManager,
|
||||||
|
Logger: logger,
|
||||||
JWTManager: jwtManager,
|
JWTManager: jwtManager,
|
||||||
SessionManager: sessionService,
|
SessionManager: sessionService,
|
||||||
CookieService: cookieService,
|
CookieService: cookieService,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
type Server struct {
|
type Server struct {
|
||||||
router *chi.Mux
|
router *chi.Mux
|
||||||
options *Options
|
options *Options
|
||||||
|
logger *slog.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewServer creates a new server instance with the given options
|
// NewServer creates a new server instance with the given options
|
||||||
@@ -18,6 +19,7 @@ func NewServer(options *Options) *Server {
|
|||||||
return &Server{
|
return &Server{
|
||||||
router: setupRouter(*options),
|
router: setupRouter(*options),
|
||||||
options: options,
|
options: options,
|
||||||
|
logger: options.Logger.App(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,7 +27,7 @@ func NewServer(options *Options) *Server {
|
|||||||
func (s *Server) Start() error {
|
func (s *Server) Start() error {
|
||||||
// Start server
|
// Start server
|
||||||
addr := ":" + s.options.Config.Port
|
addr := ":" + s.options.Config.Port
|
||||||
log.Printf("Server starting on port %s", s.options.Config.Port)
|
s.logger.Info("Starting server", "address", addr)
|
||||||
return http.ListenAndServe(addr, s.router)
|
return http.ListenAndServe(addr, s.router)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user