Commit 6a8a4af566
Unsigned
Layout: unified · split
internal/curd.go +12
| @@ -23,6 +23,18 @@ func GetTokenFromFile(filePath string) (string, error) { | |||
| 23 | return token, nil | 23 | return token, nil |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | // ClearLogFile removes all contents from the specified log file | ||
| 27 | func 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 | |||
| 26 | // LogData logs the input data into a specified log file with the format [LOG] time lineNumber: logData | 38 | // LogData logs the input data into a specified log file with the format [LOG] time lineNumber: logData |
| 27 | func Log(data interface{}, logFile string) error { | 39 | func Log(data interface{}, logFile string) error { |
| 28 | // Open or create the log file | 40 | // Open or create the log file |