diff --git a/cmd/windows_exporter/main.go b/cmd/windows_exporter/main.go index d0b596e9b..ade657acb 100644 --- a/cmd/windows_exporter/main.go +++ b/cmd/windows_exporter/main.go @@ -109,7 +109,14 @@ func run() int { ).Default("normal").String() ) - logConfig := &log.Config{} + logFile := &log.AllowedFile{} + + _ = logFile.Set("stdout") + if windowsservice.IsService { + _ = logFile.Set("eventlog") + } + + logConfig := &log.Config{File: logFile} flag.AddFlags(app, logConfig) app.Version(version.Print("windows_exporter")) diff --git a/installer/files.wxs b/installer/files.wxs index 405ff14a7..64df8d9f3 100644 --- a/installer/files.wxs +++ b/installer/files.wxs @@ -13,8 +13,8 @@ ~ limitations under the License. --> - + @@ -28,7 +28,7 @@ Start="auto" Type="ownProcess" Vital="yes" - Arguments="--log.file eventlog [ConfigFileFlag] [CollectorsFlag] [ListenFlag] [MetricsPathFlag] [TextfileDirsFlag] [ExtraFlags]"> + Arguments="[ConfigFileFlag] [CollectorsFlag] [ListenFlag] [MetricsPathFlag] [TextfileDirsFlag] [ExtraFlags]"> - + diff --git a/internal/log/flag/flag.go b/internal/log/flag/flag.go index d31c217b3..6b41e284e 100644 --- a/internal/log/flag/flag.go +++ b/internal/log/flag/flag.go @@ -34,6 +34,8 @@ func AddFlags(a *kingpin.Application, config *log.Config) { config.Config = new(promslog.Config) flag.AddFlags(a, config.Config) - config.File = &log.AllowedFile{} - a.Flag(FileFlagName, FileFlagHelp).Default("stderr").SetValue(config.File) + if config.File == nil { + config.File = &log.AllowedFile{} + } + a.Flag(FileFlagName, FileFlagHelp).Default(config.File.String()).SetValue(config.File) } diff --git a/internal/log/logger.go b/internal/log/logger.go index 6efa87d30..c245783e2 100644 --- a/internal/log/logger.go +++ b/internal/log/logger.go @@ -34,6 +34,10 @@ type AllowedFile struct { } func (f *AllowedFile) String() string { + if f == nil { + return "" + } + return f.s }