Clean up logging

This commit is contained in:
Justin Hawkins 2021-10-10 14:54:08 +10:30
parent 3776374747
commit ec8b2453cd
3 changed files with 9 additions and 12 deletions

11
dau.go
View File

@ -64,7 +64,7 @@ func main() {
func startWatchers(config *config.ConfigService, up *upload.Uploader, configChange chan bool) {
for {
log.Printf("Creating watchers")
daulog.SendLog("Creating watchers", daulog.LogTypeInfo)
ctx, cancel := context.WithCancel(context.Background())
for _, c := range config.Config.Watchers {
log.Printf("Creating watcher for %s interval %d", c.Path, config.Config.WatchInterval)
@ -74,7 +74,7 @@ func startWatchers(config *config.ConfigService, up *upload.Uploader, configChan
// wait for single that the config changed
<-configChange
cancel()
log.Printf("starting new watchers due to config change")
daulog.SendLog("starting new watchers due to config change", daulog.LogTypeInfo)
}
}
@ -83,7 +83,7 @@ func (w *watch) Watch(interval int, ctx context.Context) {
for {
select {
case <-ctx.Done():
log.Printf("Killing old watcher")
daulog.SendLog("Killing old watcher", daulog.LogTypeInfo)
return
default:
newFiles := w.ProcessNewFiles()
@ -123,11 +123,11 @@ func (w *watch) ProcessNewFiles() []string {
func (w *watch) checkPath() bool {
src, err := os.Stat(w.config.Path)
if err != nil {
log.Printf("Problem with path '%s': %s", w.config.Path, err)
daulog.SendLog(fmt.Sprintf("Problem with path '%s': %s", w.config.Path, err), daulog.LogTypeError)
return false
}
if !src.IsDir() {
log.Printf("Problem with path '%s': is not a directory", w.config.Path)
daulog.SendLog(fmt.Sprintf("Problem with path '%s': is not a directory", w.config.Path), daulog.LogTypeError)
return false
}
return true
@ -212,7 +212,6 @@ func checkUpdates() {
}
daulog.SendLog("already running latest version", daulog.LogTypeInfo)
}
func parseOptions() {

View File

@ -188,7 +188,7 @@ func (u *Upload) processUpload() {
}
if retriesRemaining == 0 {
log.Fatal("Failed to upload, even after retries")
daulog.SendLog("Failed to upload, even after all retries", daulog.LogTypeError)
}
}
@ -233,7 +233,7 @@ func (u *Upload) applyWatermark() {
im, _, err := image.Decode(reader)
if err != nil {
log.Printf("Cannot decode image: %v - skipping watermarking", err)
daulog.SendLog(fmt.Sprintf("Cannot decode image: %v - skipping watermarking", err), daulog.LogTypeError)
u.watermark = false
u.filenameToUpload = u.originalFilename
return

View File

@ -45,15 +45,13 @@ func (ws *WebService) getStatic(w http.ResponseWriter, r *http.Request) {
if extension == ".html" { // html file
t, err := template.ParseFS(webFS, "data/wrapper.tmpl", "data/"+path)
if err != nil {
log.Printf("when fetching: %s got: %s", path, err)
daulog.SendLog(fmt.Sprintf("when fetching: %s got: %s", path, err), daulog.LogTypeError)
w.Header().Add("Content-Type", "text/plain")
w.WriteHeader(http.StatusNotFound)
w.Write([]byte("not found"))
return
}
log.Printf("req: %s", r.URL.Path)
var b struct {
Body string
Path string
@ -71,7 +69,7 @@ func (ws *WebService) getStatic(w http.ResponseWriter, r *http.Request) {
otherStatic, err := webFS.ReadFile("data/" + path)
if err != nil {
log.Printf("when fetching: %s got: %s", path, err)
daulog.SendLog(fmt.Sprintf("when fetching: %s got: %s", path, err), daulog.LogTypeError)
w.Header().Add("Content-Type", "text/plain")
w.WriteHeader(http.StatusNotFound)
w.Write([]byte("not found"))