Commit 6a8a4af566

6a8a4af566b4d25a56595bed918939871c10d570

parent: 00c3caa649

Unsigned

Wraient <wraient.911@gmail.com> · 2024-10-21 15:59 UTC

Add: Clear log files

Layout: unified · split

internal/curd.go +12
@@ -23,6 +23,18 @@ func GetTokenFromFile(filePath string) (string, error) {
2323 return token, nil
2424}
2525
26// ClearLogFile removes all contents from the specified log file
27func ClearLogFile(logFile string) error {
28 // Open the file with truncate flag to clear its contents
29 file, err := os.OpenFile(logFile, os.O_WRONLY|os.O_TRUNC, 0666)
30 if err != nil {
31 return fmt.Errorf("failed to open log file: %w", err)
32 }
33 defer file.Close()
34
35 return nil
36}
37
2638// LogData logs the input data into a specified log file with the format [LOG] time lineNumber: logData
2739func Log(data interface{}, logFile string) error {
2840 // Open or create the log file