Skip to content

Commit

Permalink
Fix panic if logging directory cannot be generated (#2571)
Browse files Browse the repository at this point in the history
* Assigns log rotator only after successful creation. Otherwise panic can happen during shutdown if directory cannot be generated as it tries to log.

Closes #2490
  • Loading branch information
ruflin authored and tsg committed Sep 19, 2016
1 parent 325dc8e commit 6ae821b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ https://github.com/elastic/beats/compare/v5.0.0-alpha5...master[Check the HEAD d
- Fix array value support in -E CLI flag. {pull}2521[2521]
- Fix merging array values if -c CLI flag is used multiple times. {pull}2521[2521]
- Fix beats failing to start due to invalid duplicate key error in configuration file. {pull}2521[2521]
- Fix panic on non writable logging directory.

*Metricbeat*
- Fix module filters to work properly with drop_event filter. {issue}2249[2249]
Expand Down
11 changes: 7 additions & 4 deletions libbeat/logp/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,7 @@ func SetToSyslog(toSyslog bool, prefix string) {
}

func SetToFile(toFile bool, rotator *FileRotator) error {
_log.toFile = toFile
if _log.toFile {
_log.rotator = rotator

if toFile {
err := rotator.CreateDirectory()
if err != nil {
return err
Expand All @@ -174,6 +171,12 @@ func SetToFile(toFile bool, rotator *FileRotator) error {
if err != nil {
return err
}

// Only assign rotator on no errors
_log.rotator = rotator
}

_log.toFile = toFile

return nil
}

0 comments on commit 6ae821b

Please sign in to comment.