1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Merge pull request #183 from BillKeenan/addLogging

added a basic logging module, and a basic log 'running' in wtf.go
This commit is contained in:
Chris Cummer 2018-06-08 10:46:49 -07:00 committed by GitHub
commit a50b32eb05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 0 deletions

2
wtf.go
View File

@ -293,4 +293,6 @@ func main() {
fmt.Printf("An error occurred: %v\n", err)
os.Exit(1)
}
wtf.Log("running!")
}

26
wtf/log.go Normal file
View File

@ -0,0 +1,26 @@
package wtf
import (
"log"
"os"
"path/filepath"
)
//Log basic message logging, defaults to ~/.wtf/log.txt
func Log(message string) {
dir, err := Home()
if err != nil {
return
}
logfile := filepath.Join(dir, ".wtf", "log.txt")
f, err := os.OpenFile(logfile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("error opening file: %v", err)
}
defer f.Close()
log.SetOutput(f)
log.Println(message)
}