Bladeren bron

Update logger

Dmitriy Gnatenko 1 dag geleden
bovenliggende
commit
feab62f230
3 gewijzigde bestanden met toevoegingen van 13 en 37 verwijderingen
  1. 3 6
      logger/logger.go
  2. 10 30
      logger/logger_config.go
  3. 0 1
      logger/readme.md

+ 3 - 6
logger/logger.go

@@ -34,8 +34,7 @@ func Init(c Config) error {
 
 		if c.stdoutLogEnabled {
 			logger.stdoutLogger = slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
-				AddSource: c.stdoutLogAddSource,
-				Level:     c.stdoutLogLevel,
+				Level: c.stdoutLogLevel,
 			}))
 		}
 
@@ -46,8 +45,7 @@ func Init(c Config) error {
 			}
 
 			logger.fileLogger = slog.New(slog.NewJSONHandler(logger.logFile, &slog.HandlerOptions{
-				AddSource: c.fileLogAddSource,
-				Level:     c.fileLogLevel,
+				Level: c.fileLogLevel,
 			}))
 		}
 
@@ -64,8 +62,7 @@ func Init(c Config) error {
 			}
 
 			logger.emailLogger = slog.New(slog.NewJSONHandler(ew, &slog.HandlerOptions{
-				AddSource: c.emailLogAddSource,
-				Level:     c.emailLogLevel,
+				Level: c.emailLogLevel,
 			}))
 		}
 	})

+ 10 - 30
logger/logger_config.go

@@ -8,23 +8,20 @@ type SMTPClient interface {
 
 type Config struct {
 	// stdout config
-	stdoutLogEnabled   bool
-	stdoutLogLevel     slog.Level // INFO by default
-	stdoutLogAddSource bool
+	stdoutLogEnabled bool
+	stdoutLogLevel   slog.Level // INFO by default
 
 	// file config
-	fileLogEnabled   bool
-	fileLogLevel     slog.Level // INFO by default
-	fileLogAddSource bool
-	filepath         string
+	fileLogEnabled bool
+	fileLogLevel   slog.Level // INFO by default
+	filepath       string
 
 	// email config
-	emailLogEnabled   bool
-	emailLogLevel     slog.Level // INFO by default
-	emailLogAddSource bool
-	smtpClient        SMTPClient
-	emailRecipient    string
-	emailSubject      string
+	emailLogEnabled bool
+	emailLogLevel   slog.Level // INFO by default
+	smtpClient      SMTPClient
+	emailRecipient  string
+	emailSubject    string
 }
 
 type ConfigOption func(*Config)
@@ -60,11 +57,6 @@ func WithStdoutLogLevel(level string) ConfigOption {
 		}
 	}
 }
-func WithStdoutLogAddSource(add bool) ConfigOption {
-	return func(s *Config) {
-		s.stdoutLogAddSource = add
-	}
-}
 
 // file
 
@@ -83,12 +75,6 @@ func WithFileLogLevel(level string) ConfigOption {
 	}
 }
 
-func WithFileLogAddSource(add bool) ConfigOption {
-	return func(s *Config) {
-		s.fileLogAddSource = add
-	}
-}
-
 func WithFilepath(path string) ConfigOption {
 	return func(s *Config) {
 		s.filepath = path
@@ -112,12 +98,6 @@ func WithEmailLogLevel(level string) ConfigOption {
 	}
 }
 
-func WithEmailLogAddSource(add bool) ConfigOption {
-	return func(s *Config) {
-		s.emailLogAddSource = add
-	}
-}
-
 func WithEmailRecipient(email string) ConfigOption {
 	return func(s *Config) {
 		s.emailRecipient = email

+ 0 - 1
logger/readme.md

@@ -7,7 +7,6 @@ err := logger.Init(logger.NewConfig(
     logger.WithStdoutLogLevel("WARN"),
     logger.WithFileLogEnabled(true),
     logger.WithFileLogLevel("ERROR"),
-    logger.WithFileLogAddSource(true),
     logger.WithFilepath("./errors.log"),
 ))