Skip to content

Commit

Permalink
Write to log file instead of STDOUT
Browse files Browse the repository at this point in the history
  • Loading branch information
mnlkrs committed Mar 5, 2017
1 parent 2e84346 commit d273bc8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
*.exe
*.lnk
*.lnk
*.txt
*.vbs
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
VPlanClient watches a folder and uploads every new/edited file to a webserver

## Installing

(Assuming you already have a working go directory)
`go get github.com/mpggu/vplanclient`

## Building

`go build VPlanClient.go`

## Usage

`./VPlanClient -url="http://foo.bar" -folder="~/vplan" -auth="XXX_secret"`


Expand Down
11 changes: 11 additions & 0 deletions VPlanClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io/ioutil"
"log"
"net/http"
"os"

"github.com/fsnotify/fsnotify"
)
Expand All @@ -20,6 +21,14 @@ func main() {
var folder = flag.String("folder", "", "The folder to watch")
var auth = flag.String("auth", "", "The authentication secret")

// Log to file
f, err := os.OpenFile("logs.txt", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatal("error opening log file")
}
defer f.Close()
log.SetOutput(f)

flag.Parse()
log.Println(*url, *folder)
watcher, err := fsnotify.NewWatcher()
Expand Down Expand Up @@ -94,5 +103,7 @@ func postVPlan(url, data, auth string) {
return
}

log.Println("Neuer Vertretungsplan hochgeladen")

defer resp.Body.Close()
}

0 comments on commit d273bc8

Please sign in to comment.