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:
commit
a50b32eb05
2
wtf.go
2
wtf.go
@ -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
26
wtf/log.go
Normal 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)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user