diff options
author | Sebastien Douheret <sebastien.douheret@iot.bzh> | 2017-05-17 17:10:45 +0200 |
---|---|---|
committer | Sebastien Douheret <sebastien.douheret@iot.bzh> | 2017-05-17 17:10:45 +0200 |
commit | a50baa7c309f7eb55fe87c71f4c688ace325b6ac (patch) | |
tree | 14ed08e3abad729bce718bfbd596eb62d1676675 /lib/xdsconfig/config.go | |
parent | 59784289d1d0296e470c46dc279aa3576c60801e (diff) |
Add logsDir setting and more
- add logsDir setting in config.json
- redirect Syncthing and Syncthing-inotify into log files
- Use autogenerated Syncthing apikey if gui-apikey not set in config.json
Diffstat (limited to 'lib/xdsconfig/config.go')
-rw-r--r-- | lib/xdsconfig/config.go | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/lib/xdsconfig/config.go b/lib/xdsconfig/config.go index 1f53cbd..efea5ba 100644 --- a/lib/xdsconfig/config.go +++ b/lib/xdsconfig/config.go @@ -7,6 +7,7 @@ import ( "github.com/Sirupsen/logrus" "github.com/codegangsta/cli" + "github.com/iotbzh/xds-server/lib/common" ) // Config parameters (json format) of /config command @@ -16,9 +17,9 @@ type Config struct { VersionGitTag string `json:"gitTag"` // Private / un-exported fields - HTTPPort string `json:"-"` - FileConf *FileConfig - log *logrus.Logger + HTTPPort string `json:"-"` + FileConf *FileConfig `json:"-"` + Log *logrus.Logger `json:"-"` } // Config default values @@ -29,7 +30,7 @@ const ( ) // Init loads the configuration on start-up -func Init(ctx *cli.Context, log *logrus.Logger) (Config, error) { +func Init(ctx *cli.Context, log *logrus.Logger) (*Config, error) { var err error // Define default configuration @@ -39,27 +40,26 @@ func Init(ctx *cli.Context, log *logrus.Logger) (Config, error) { VersionGitTag: ctx.App.Metadata["git-tag"].(string), HTTPPort: DefaultPort, - log: log, + Log: log, } // config file settings overwrite default config c.FileConf, err = updateConfigFromFile(&c, ctx.GlobalString("config")) if err != nil { - return Config{}, err + return nil, err } - return c, nil + if c.FileConf.LogsDir != "" && !common.Exists(c.FileConf.LogsDir) { + if err := os.MkdirAll(c.FileConf.LogsDir, 0770); err != nil { + return nil, fmt.Errorf("Cannot create logs dir: %v", err) + } + } + c.Log.Infoln("Logs directory: ", c.FileConf.LogsDir) + + return &c, nil } // UpdateAll Update the current configuration func (c *Config) UpdateAll(newCfg Config) error { return fmt.Errorf("Not Supported") } - -func dirExists(path string) bool { - _, err := os.Stat(path) - if os.IsNotExist(err) { - return false - } - return true -} |