summary refs log tree commit diff stats
path: root/svc/conf.go
diff options
context:
space:
mode:
Diffstat (limited to 'svc/conf.go')
-rw-r--r--svc/conf.go34
1 files changed, 23 insertions, 11 deletions
diff --git a/svc/conf.go b/svc/conf.go
index 538b701..c1b9abb 100644
--- a/svc/conf.go
+++ b/svc/conf.go
@@ -11,13 +11,16 @@ import (
 	"github.com/spf13/viper"
 )
 
+var reqLog *log.Logger
+
 // Configuration values are held in an instance of
 // this struct.
 type Configuration struct {
 	Mu            sync.RWMutex
 	IsProxied     bool          `yaml:"BehindProxy"`
 	Port          int           `yaml:"ListenPort"`
-	LogFile       string        `yaml:"LogFile"`
+	MsgLog        string        `yaml:"MessageLog"`
+	ReqLog        string        `yaml:"RequestLog"`
 	DBType        string        `yaml:"DatabaseType"`
 	DBPath        string        `yaml:"DatabasePath"`
 	AssetsDir     string        `yaml:"-"`
@@ -68,28 +71,34 @@ func initConfig() {
 }
 
 // Registers either stdout or a specified file
-// to the default logger.
+// to the default logger, and the same for the
+// request logger.
 func initLogging() {
 
 	confObj.Mu.RLock()
 	if confObj.StdoutLogging {
 		log.SetOutput(os.Stdout)
+		reqLog = log.New(os.Stdout, "", log.LstdFlags)
 
 	} else {
-		logfile, err := os.OpenFile(confObj.LogFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600)
+		msgLog, err := os.OpenFile(confObj.MsgLog, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600)
+		errLog("Could not open log file: ", err)
+		reqLogFile, err := os.OpenFile(confObj.ReqLog, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600)
 		errLog("Could not open log file: ", err)
 
 		// Listen for the signal to close the log file
 		// in a separate thread. Passing it as an argument
 		// to prevent race conditions when the config is
 		// reloaded.
-		go func(logfile *os.File) {
+		go func(msg *os.File, req *os.File) {
 			<-closeLog
-			log.Printf("Closing log file ...\n\n")
-			errLog("Could not close log file: ", logfile.Close())
-		}(logfile)
+			log.Printf("Closing log files ...\n\n")
+			errLog("Could not close log file: ", msg.Close())
+			errLog("Could not close log file: ", req.Close())
+		}(msgLog, reqLogFile)
 
-		log.SetOutput(logfile)
+		log.SetOutput(msgLog)
+		reqLog = log.New(reqLogFile, "", log.LstdFlags)
 	}
 	confObj.Mu.RUnlock()
 }
@@ -102,7 +111,8 @@ func setConfigDefaults() {
 	viper.SetDefault("TLSCert", "cert.pem")
 	viper.SetDefault("TLSKey", "key.pem")
 	viper.SetDefault("ListenPort", 9001)
-	viper.SetDefault("LogFile", "getwtxt.log")
+	viper.SetDefault("MessageLog", "logs/message.log")
+	viper.SetDefault("RequestLog", "logs/request.log")
 	viper.SetDefault("DatabasePath", "getwtxt.db")
 	viper.SetDefault("AssetsDirectory", "assets")
 	viper.SetDefault("DatabaseType", "leveldb")
@@ -148,7 +158,8 @@ func bindConfig() {
 
 	confObj.IsProxied = viper.GetBool("BehindProxy")
 	confObj.Port = viper.GetInt("ListenPort")
-	confObj.LogFile = viper.GetString("LogFile")
+	confObj.MsgLog = viper.GetString("MessageLog")
+	confObj.ReqLog = viper.GetString("RequestLog")
 	confObj.DBType = strings.ToLower(viper.GetString("DatabaseType"))
 	confObj.DBPath = viper.GetString("DatabasePath")
 	confObj.AssetsDir = viper.GetString("AssetsDirectory")
@@ -199,7 +210,8 @@ func announceConfig() {
 	if confObj.StdoutLogging {
 		log.Printf("Logging to: stdout\n")
 	} else {
-		log.Printf("Logging to: %v\n", confObj.LogFile)
+		log.Printf("Logging messages to: %v\n", confObj.MsgLog)
+		log.Printf("Logging requests to: %v\n", confObj.ReqLog)
 	}
 	log.Printf("Using %v database: %v\n", confObj.DBType, confObj.DBPath)
 	log.Printf("Database push interval: %v\n", confObj.DBInterval)
mitter hut <hut@lavabit.com> 2010-01-10 22:54:04 +0100 added chmod command' href='/akspecs/ranger/commit/TODO?h=v1.4.4&id=277ecc9ea7110b79ea0d6c0e25804ea2b218287f'>277ecc9e ^
9983328c ^
33cb688a ^
a1274aba ^
b42eb058 ^
b13518af ^
316ff5a9 ^
fc486c60 ^
b4934e42 ^
2c1d2db0 ^
291ca616 ^
50845f37 ^
039c03ef ^
af6658b3 ^
efe2d7a3 ^
f0df3fa5 ^
9487bd97 ^
3fe38754 ^

66c5bb93 ^
4be8b401 ^



d955e3f0 ^
75013dc7 ^
67bb838c ^
a808a661 ^
bba8d293 ^
2a64495f ^
5e449699 ^
fc486c60 ^
7b04e507 ^
0268e3c3 ^
dd4a4145 ^
d994d0d6 ^

6f43de0a ^




fca1fc4f ^
f70ee6b2 ^
0db4c9b2 ^
b2d63ef5 ^
291ca616 ^
d994d0d6 ^
66c5bb93 ^
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73