summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main.go21
1 files changed, 19 insertions, 2 deletions
diff --git a/main.go b/main.go
index 668738c..f9b32f3 100644
--- a/main.go
+++ b/main.go
@@ -178,6 +178,12 @@ func main() {
Value: defaultLogLevel,
},
cli.StringFlag{
+ Name: "logfile",
+ Value: "stderr",
+ Usage: "filename where logs will be redirected (default stderr)\n\t",
+ EnvVar: "XDS_LOGFILENAME",
+ },
+ cli.StringFlag{
Name: "url, u",
EnvVar: "XDS_AGENT_URL",
Value: "localhost:8800",
@@ -206,8 +212,8 @@ func main() {
// Add --config option to all commands to support --config option either before or after command verb
// IOW support following both syntaxes:
- // xds-cli exec --config myprj.conf ...
- // xds-cli --config myprj.conf exec ...
+ // xds-cli exec --config myPrj.conf ...
+ // xds-cli --config myPrj.conf exec ...
for i, cmd := range app.Commands {
if len(cmd.Flags) > 0 {
app.Commands[i].Flags = append(cmd.Flags, cli.StringFlag{Hidden: true, Name: "config, c"})
@@ -277,6 +283,17 @@ func main() {
}
Log.Formatter = &logrus.TextFormatter{}
+ if ctx.String("logfile") != "stderr" {
+ logFile, _ := common.ResolveEnvVar(ctx.String("logfile"))
+ fdL, err := os.OpenFile(logFile, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0666)
+ if err != nil {
+ msgErr := fmt.Sprintf("Cannot create log file %s", logFile)
+ return cli.NewExitError(msgErr, 1)
+ }
+ Log.Infof("Logging to file: %s", logFile)
+ Log.Out = fdL
+ }
+
Log.Infof("%s version: %s", AppName, app.Version)
earlyDisplay()
Log.Debugf("\nEnvironment: %v\n", os.Environ())