diff --git a/cmd/commons/args.go b/cmd/commons/args.go index 42d5389..07bf673 100644 --- a/cmd/commons/args.go +++ b/cmd/commons/args.go @@ -37,6 +37,7 @@ func SetCommonFlags(command *cobra.Command) { command.Flags().StringP("config", "c", "", "Set config file (yaml)") command.Flags().String("instance_id", "", "Set instance ID") + command.Flags().String("log_path", "", "Set log file path") command.Flags().String("host", "", "Set iRODS host") command.Flags().Int("port", 1247, "Set iRODS port") @@ -229,6 +230,14 @@ func ProcessCommonFlags(command *cobra.Command, args []string) (*commons.Config, } } + logPathFlag := command.Flags().Lookup("log_path") + if logPathFlag != nil { + logPath := logPathFlag.Value.String() + if len(logPath) > 0 { + config.LogPath = logPath + } + } + dataRootFlag := command.Flags().Lookup("data_root") if dataRootFlag != nil { dataRoot := dataRootFlag.Value.String() diff --git a/cmd/commons/daemon.go b/cmd/commons/daemon.go index 744a1dd..49c45e8 100644 --- a/cmd/commons/daemon.go +++ b/cmd/commons/daemon.go @@ -28,6 +28,10 @@ func (w *NilWriter) Write(p []byte) (n int, err error) { return len(p), nil } +func (w *NilWriter) Close() (err error) { + return nil +} + func ReportChildProcessError() { fmt.Fprintln(os.Stderr, InterProcessCommunicationFinishError) } @@ -182,14 +186,16 @@ func ChildProcessReadConfigViaSTDIN() (*commons.Config, io.WriteCloser, error) { } // output to log file - var logWriter io.WriteCloser logFilePath := config.GetLogFilePath() - if len(logFilePath) > 0 { + if len(logFilePath) > 0 && logFilePath != "-" { logWriter, childLogFilePath := getLogWriterForChildProcess(logFilePath) log.SetOutput(logWriter) logger.Infof("Logging to %s", childLogFilePath) + return config, logWriter, nil + } else { + var nilWriter NilWriter + log.SetOutput(&nilWriter) + return config, &nilWriter, nil } - - return config, logWriter, nil } diff --git a/commons/config.go b/commons/config.go index 3fc73c7..55e17be 100644 --- a/commons/config.go +++ b/commons/config.go @@ -240,6 +240,11 @@ func (config *Config) GetInstanceDataRootDirPath() string { // MakeLogDir makes a log dir required func (config *Config) MakeLogDir() error { logFilePath := config.GetLogFilePath() + if logFilePath == "-" { + // skip + return nil + } + logDirPath := filepath.Dir(logFilePath) err := config.makeDir(logDirPath) if err != nil {