logger.go (view raw)
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 |
package watchman_client import ( "fmt" "os" "time" "github.com/google/uuid" "github.com/wbrijesh/watchman_client/utils" ) func InitialiseWatchman() { if _, err := os.Stat("log.json"); os.IsNotExist(err) { fmt.Println("Creating log.json file") file, _ := os.Create("log.json") defer file.Close() } else { fmt.Println("log.json file already exists") } } func GenerateUUID() string { return uuid.New().String() } func Log(log utils.LoggerProps) { utils.PrintLog(log) utils.WriteLog(log) } func BackgroundLogSync(seconds int) { ticker := time.NewTicker(time.Duration(seconds) * time.Second) defer ticker.Stop() for range ticker.C { if utils.IsLogFileEmpty() { fmt.Println("Log file is empty") } else { utils.SendLogsToServer() } } } |