Skip to content

Commit

Permalink
fix: use log.file=eventlog as default value, if running as windows se…
Browse files Browse the repository at this point in the history
…rvice (#1771)

Signed-off-by: Jan-Otto Kröpke <[email protected]>
  • Loading branch information
jkroepke authored Nov 26, 2024
1 parent fd55ac4 commit ca04ad8
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
9 changes: 8 additions & 1 deletion cmd/windows_exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,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"))
Expand Down
6 changes: 3 additions & 3 deletions installer/files.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
~ limitations under the License.
-->

<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"
xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util">
<Wix xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util"
xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Fragment>
<DirectoryRef Id="APPLICATIONFOLDER">
<Component Transitive="yes">
Expand All @@ -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]">
<util:ServiceConfig
ResetPeriodInDays="1"
FirstFailureActionType="restart"
Expand Down
6 changes: 3 additions & 3 deletions installer/main.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
~ limitations under the License.
-->

<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"
xmlns:fw="http://wixtoolset.org/schemas/v4/wxs/firewall"
xmlns:ui="http://wixtoolset.org/schemas/v4/wxs/ui">
<Wix xmlns:fw="http://wixtoolset.org/schemas/v4/wxs/firewall"
xmlns:ui="http://wixtoolset.org/schemas/v4/wxs/ui"
xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Package UpgradeCode="66a6eb5b-1fc2-4b14-a362-5ceec6413308" Name="$(var.ProductName)" Version="$(var.Version)"
Manufacturer="prometheus-community" Language="1033" Scope="perMachine">
<SummaryInformation Manufacturer="prometheus-community" Description="$(var.ProductName) $(var.Version) installer" />
Expand Down
7 changes: 5 additions & 2 deletions internal/log/flag/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ 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)
}
4 changes: 4 additions & 0 deletions internal/log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ type AllowedFile struct {
}

func (f *AllowedFile) String() string {
if f == nil {
return ""
}

return f.s
}

Expand Down

0 comments on commit ca04ad8

Please sign in to comment.