summary refs log tree commit diff stats
path: root/init.go
blob: 612bb6defbec24b48eeabda288b4fba8e5a495c3 (plain) (blame)
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
package main

import (
	"log"
	"os"
)

// Sets up logging before the main function executes
func init() {
	logfile, err := os.OpenFile("getwtxt.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600)
	if err != nil {
		log.Printf("Could not open log file: %v\n", err)
	}

	// Listen for the signal to close the log file
	go func() {
		<-closelog
		log.Printf("Closing log file ...\n")
		err = logfile.Close()
		if err != nil {
			log.Printf("Couldn't close log file: %v\n", err)
		}
	}()

	log.SetOutput(logfile)

}