Files
Go-VPN-Client/internal/logger/logger.go
2026-04-05 20:33:30 +06:00

35 lines
961 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package logger
import (
"fmt"
"os"
"path/filepath"
"time"
)
// LogMessage записывает сообщение в лог-файл
func LogMessage(logFile, message string) error {
f, err := os.OpenFile(logFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return err
}
defer f.Close()
timestamp := time.Now().Format("2006-01-02 15:04:05")
logEntry := fmt.Sprintf("[%s] %s\n", timestamp, message)
_, err = f.WriteString(logEntry)
return err
}
// GetLogPath возвращает путь к лог-файлу
func GetLogPath(logsDir, logType string) string {
return filepath.Join(logsDir, fmt.Sprintf("%s.log", logType))
}
// GetTrafficLogPath возвращает путь к лог-файлу трафика с временной меткой
func GetTrafficLogPath(logsDir string) string {
timestamp := time.Now().Format("20060102_150405")
return filepath.Join(logsDir, fmt.Sprintf("vless_traffic_%s.log", timestamp))
}