diff --git a/server/cmd/server/main.go b/server/cmd/server/main.go index cd7dc2c..5846abe 100644 --- a/server/cmd/server/main.go +++ b/server/cmd/server/main.go @@ -26,7 +26,7 @@ func main() { // Setup logging logging.Setup(cfg.LogLevel) - logging.Debug("Configuration loaded", "config", logging.Redact(cfg)) + logging.Debug("Configuration loaded", "config", cfg.Redact()) // Initialize and start server options, err := app.DefaultOptions(cfg) diff --git a/server/internal/app/config.go b/server/internal/app/config.go index 0b70a82..f80057c 100644 --- a/server/internal/app/config.go +++ b/server/internal/app/config.go @@ -19,10 +19,10 @@ type Config struct { RootURL string Domain string CORSOrigins []string - AdminEmail string `log:"redact"` - AdminPassword string `log:"redact"` - EncryptionKey string `log:"redact"` - JWTSigningKey string `log:"redact"` + AdminEmail string + AdminPassword string + EncryptionKey string + JWTSigningKey string RateLimitRequests int RateLimitWindow time.Duration IsDevelopment bool @@ -56,6 +56,16 @@ func (c *Config) validate() error { return nil } +// Redact redacts sensitive fields from a Config instance +func (c *Config) Redact() *Config { + redacted := *c + redacted.AdminPassword = "[REDACTED]" + redacted.AdminEmail = "[REDACTED]" + redacted.EncryptionKey = "[REDACTED]" + redacted.JWTSigningKey = "[REDACTED]" + return &redacted +} + // LoadConfig creates a new Config instance with values from environment variables func LoadConfig() (*Config, error) { config := DefaultConfig() diff --git a/server/internal/auth/jwt.go b/server/internal/auth/jwt.go index 8953440..2b976fe 100644 --- a/server/internal/auth/jwt.go +++ b/server/internal/auth/jwt.go @@ -52,8 +52,6 @@ type jwtService struct { // NewJWTService creates a new JWT service with the provided configuration // Returns an error if the signing key is missing func NewJWTService(config JWTConfig) (JWTManager, error) { - log := getJWTLogger() - if config.SigningKey == "" { return nil, fmt.Errorf("signing key is required") } @@ -66,10 +64,6 @@ func NewJWTService(config JWTConfig) (JWTManager, error) { config.RefreshTokenExpiry = 7 * 24 * time.Hour } - log.Info("initialized JWT service", - "accessExpiry", config.AccessTokenExpiry, - "refreshExpiry", config.RefreshTokenExpiry) - return &jwtService{config: config}, nil } diff --git a/server/internal/db/db.go b/server/internal/db/db.go index 6a23bff..739dc34 100644 --- a/server/internal/db/db.go +++ b/server/internal/db/db.go @@ -122,7 +122,6 @@ func Init(dbPath string, secretsService secrets.Service) (Database, error) { if err := db.Ping(); err != nil { return nil, fmt.Errorf("failed to ping database: %w", err) } - log.Debug("database ping successful") // Enable foreign keys for this connection if _, err := db.Exec("PRAGMA foreign_keys = ON"); err != nil { diff --git a/server/internal/logging/logger.go b/server/internal/logging/logger.go index 7e23261..e05ea32 100644 --- a/server/internal/logging/logger.go +++ b/server/internal/logging/logger.go @@ -4,7 +4,6 @@ package logging import ( "log/slog" "os" - "reflect" ) // Logger represents the interface for logging operations @@ -61,27 +60,6 @@ func ParseLogLevel(level string) LogLevel { } } -// Redact redacts sensitive fields from a struct based on the `log` struct tag -// if the tag is set to "redact" the field value is replaced with "[REDACTED]" -func Redact(v any) map[string]any { - result := make(map[string]any) - val := reflect.ValueOf(v) - typ := val.Type() - - for i := 0; i < val.NumField(); i++ { - field := typ.Field(i) - if tag := field.Tag.Get("log"); tag != "" { - switch tag { - case "redact": - result[field.Name] = "[REDACTED]" - default: - result[field.Name] = val.Field(i).Interface() - } - } - } - return result -} - // Implementation of Logger interface methods func (l *logger) Debug(msg string, args ...any) { l.logger.Debug(msg, args...) diff --git a/server/internal/secrets/secrets.go b/server/internal/secrets/secrets.go index b28304e..6d9d15a 100644 --- a/server/internal/secrets/secrets.go +++ b/server/internal/secrets/secrets.go @@ -64,7 +64,6 @@ func decodeAndValidateKey(key string) ([]byte, error) { // NewService creates a new Encryptor instance with the provided base64-encoded key func NewService(key string) (Service, error) { - log := getLogger() keyBytes, err := decodeAndValidateKey(key) if err != nil { return nil, err @@ -80,7 +79,6 @@ func NewService(key string) (Service, error) { return nil, fmt.Errorf("failed to create GCM: %w", err) } - log.Info("encryption service created") return &encryptor{gcm: gcm}, nil } diff --git a/server/internal/storage/service.go b/server/internal/storage/service.go index 507381c..07e6b1e 100644 --- a/server/internal/storage/service.go +++ b/server/internal/storage/service.go @@ -27,9 +27,6 @@ type Options struct { // NewService creates a new Storage instance with the default options and the given rootDir root directory. func NewService(rootDir string) *Service { - getLogger().Debug("creating new storage service", - "rootDir", rootDir, - "options", "default") return NewServiceWithOptions(rootDir, Options{ Fs: &osFS{}, NewGitClient: git.New, @@ -38,10 +35,6 @@ func NewService(rootDir string) *Service { // NewServiceWithOptions creates a new Storage instance with the given options and the given rootDir root directory. func NewServiceWithOptions(rootDir string, options Options) *Service { - log := getLogger() - log.Debug("creating new storage service with custom options", - "rootDir", rootDir) - if options.Fs == nil { options.Fs = &osFS{} }