Ariver
2026-06-03 30654f76c4ee9c6f9320148e50ad16068b103914
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package logger
 
import (
    "fmt"
    "os"
    "path/filepath"
    "sync"
    "time"
    "voicesnap/internal/paths"
)
 
var (
    mu      sync.Mutex
    logFile *os.File
)
 
// Init initializes the file logger in the persistent app data directory.
func Init() {
    dir := paths.AppSupportDir()
    if err := os.MkdirAll(dir, 0755); err != nil {
        fmt.Fprintf(os.Stderr, "failed to create log dir: %v\n", err)
        return
    }
    path := filepath.Join(dir, "app.log")
 
    f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
    if err != nil {
        fmt.Fprintf(os.Stderr, "failed to open log file: %v\n", err)
        return
    }
    logFile = f
}
 
func write(level, format string, args ...interface{}) {
    msg := fmt.Sprintf(format, args...)
    ts := time.Now().Format("2006-01-02 15:04:05")
    line := fmt.Sprintf("[%s] %s %s\n", ts, level, msg)
 
    mu.Lock()
    defer mu.Unlock()
 
    if logFile != nil {
        logFile.WriteString(line)
    }
    fmt.Fprint(os.Stderr, line)
}
 
// Info logs an informational message.
func Info(format string, args ...interface{}) {
    write("INFO", format, args...)
}
 
// Error logs an error message.
func Error(format string, args ...interface{}) {
    write("ERROR", format, args...)
}
 
// Close closes the log file.
func Close() {
    mu.Lock()
    defer mu.Unlock()
    if logFile != nil {
        logFile.Close()
        logFile = nil
    }
}