make the location of the log file configurable

pull/144/head
John Shahid 2013-12-11 13:49:11 -05:00
parent 69544aa6bf
commit 4a58dce5b7
5 changed files with 30 additions and 3 deletions

3
.gitignore vendored
View File

@ -45,3 +45,6 @@ autom4te.cache/
config.log
config.status
Makefile
# log file
influxdb.log

View File

@ -235,6 +235,11 @@ define sample_config
# seed-servers =
datadir = "/opt/influxdb/shared/data/db"
[logging]
# logging level can be one of "debug", "info", "warn" or "error"
# level = "info"
file = "/opt/influxdb/shared/log.txt"
# Configure the admin server
[admin]
# port = 8083

View File

@ -7,6 +7,11 @@
# seed-servers =
# datadir = "/tmp/influxdb/development/db"
[logging]
# logging level can be one of "debug", "info", "warn" or "error"
# level = "info"
# file = "influxdb.log"
# Configure the admin server
[admin]
# port = 8083

View File

@ -21,6 +21,8 @@ type Configuration struct {
RaftDir string
ProtobufPort int
Hostname string
LogFile string
LogLevel string
}
func LoadConfiguration(fileName string) *Configuration {
@ -42,6 +44,8 @@ func parseTomlConfiguration(filename string) (*Configuration, error) {
seedServers := configSet.String("seed-servers", "")
dataDir := configSet.String("datadir", "/tmp/influxdb/development/db")
protobufPort := configSet.Int("protobuf.port", 8099)
logFile := configSet.String("logging.file", "influxdb.log")
logLevel := configSet.String("logging.level", "info")
if err := configSet.Parse(filename); err != nil {
return nil, err
@ -55,6 +59,8 @@ func parseTomlConfiguration(filename string) (*Configuration, error) {
RaftDir: *raftDir,
ProtobufPort: *protobufPort,
DataDir: *dataDir,
LogFile: *logFile,
LogLevel: *logLevel,
}
servers := strings.Split(*seedServers, ",")

View File

@ -67,7 +67,7 @@ func startProfiler(filename *string) error {
return nil
}
func setupLogging(loggingLevel string) {
func setupLogging(loggingLevel, logFile string) {
level := log.DEBUG
switch loggingLevel {
case "info":
@ -81,6 +81,15 @@ func setupLogging(loggingLevel string) {
for _, filter := range log.Global {
filter.Level = level
}
flw := log.NewFileLogWriter(logFile, false)
flw.SetFormat("[%D %T] [%L] (%S) %M")
flw.SetRotate(true)
flw.SetRotateSize(0)
flw.SetRotateLines(0)
flw.SetRotateDaily(true)
log.AddFilter("file", level, flw)
log.Info("Redirectoring logging to %s", logFile)
}
func main() {
@ -95,13 +104,12 @@ func main() {
startProfiler(cpuProfiler)
setupLogging("debug")
if wantsVersion != nil && *wantsVersion {
fmt.Printf("InfluxDB v%s (git: %s)\n", version, gitSha)
return
}
config := configuration.LoadConfiguration(*fileName)
setupLogging(config.LogLevel, config.LogFile)
if pidFile != nil && *pidFile != "" {
pid := strconv.Itoa(os.Getpid())