Skip to content

Commit

Permalink
quick fix for logging logs
Browse files Browse the repository at this point in the history
  • Loading branch information
NorseGaud committed Sep 17, 2024
1 parent c4b7ab1 commit 1865cc5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.0
0.3.1
6 changes: 3 additions & 3 deletions internal/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ func New() *slog.Logger {
return slog.New(handler)
}

func UpdateLoggerToFile(logger *slog.Logger, filePath string, suffix string) (*slog.Logger, error) {
func UpdateLoggerToFile(logger *slog.Logger, filePath string, suffix string) (*slog.Logger, string, error) {
fileLocation := filePath + "anklet" + suffix + ".log"
file, err := os.OpenFile(fileLocation, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return nil, err
return nil, "", err
}

options := &slog.HandlerOptions{Level: slog.LevelInfo}
Expand All @@ -57,7 +57,7 @@ func UpdateLoggerToFile(logger *slog.Logger, filePath string, suffix string) (*s
}

newLogger := slog.New(handler)
return newLogger, nil
return newLogger, fileLocation, nil
}

// Handle adds contextual attributes to the Record before calling the underlying
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ func main() {
parentCtx = context.WithValue(parentCtx, config.ContextKey("suffix"), suffix)

if loadedConfig.Log.FileDir != "" {
logger.InfoContext(parentCtx, "updating logger to file", slog.String("fileDir", loadedConfig.Log.FileDir))
logger, err = logging.UpdateLoggerToFile(logger, loadedConfig.Log.FileDir, suffix)
logger, fileLocation, err := logging.UpdateLoggerToFile(logger, loadedConfig.Log.FileDir, suffix)
if err != nil {
logger.ErrorContext(parentCtx, "error updating logger to file", "error", err)
}
logger.InfoContext(parentCtx, "writing logs to file", slog.String("fileLocation", fileLocation))
logger.InfoContext(parentCtx, "loaded config", slog.Any("config", loadedConfig))
}

Expand Down

0 comments on commit 1865cc5

Please sign in to comment.