diff options
author | Jesse Hallam <jesse.hallam@gmail.com> | 2018-04-13 20:09:38 -0400 |
---|---|---|
committer | Derrick Anderson <derrick@andersonwebstudio.com> | 2018-04-13 20:09:38 -0400 |
commit | 8056dc33e31d87ff81d286b9991883f953705f15 (patch) | |
tree | 1ec8e3290d979d2aa25a0e0d0f437b779d1d3e50 /utils/config.go | |
parent | a7fd13384b3f147d9b482fc43f886f747704134c (diff) | |
download | chat-8056dc33e31d87ff81d286b9991883f953705f15.tar.gz chat-8056dc33e31d87ff81d286b9991883f953705f15.tar.bz2 chat-8056dc33e31d87ff81d286b9991883f953705f15.zip |
Prevent disabling or modifying l4g logging filters (#8628)
The underlying l4g library is not resilient to filter modifications in
the presence of concurrent goroutines. In particular, it's not safe to
call Close() on filters which might be actively held by a goroutine for
logging.
This change disables all modifications to existing filters once
initialized by the App layer. In practice, we might be able to get away
with some modifications to the existing filters (i.e. changing levels),
but the [golang memory model](https://golang.org/ref/mem) makes no
guarantees that it is safe to do so:
> Programs that modify data being simultaneously accessed by multiple goroutines must serialize such access.
We can solve this holistically by introducing the requisite locking
within our fork of the l4g library. For now, we just disable all
modifications.
Diffstat (limited to 'utils/config.go')
-rw-r--r-- | utils/config.go | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/utils/config.go b/utils/config.go index 13295b362..6026f43f9 100644 --- a/utils/config.go +++ b/utils/config.go @@ -83,13 +83,15 @@ func ConfigureCmdLineLog() { ConfigureLog(&ls) } +// ConfigureLog enables and configures logging. +// +// Note that it is not currently possible to disable filters nor to modify previously enabled +// filters, given the lack of concurrency guarantees from the underlying l4g library. +// // TODO: this code initializes console and file logging. It will eventually be replaced by JSON logging in logger/logger.go // See PLT-3893 for more information func ConfigureLog(s *model.LogSettings) { - - l4g.Close() - - if s.EnableConsole { + if _, alreadySet := l4g.Global["stdout"]; !alreadySet && s.EnableConsole { level := l4g.DEBUG if s.ConsoleLevel == "INFO" { level = l4g.INFO @@ -104,8 +106,7 @@ func ConfigureLog(s *model.LogSettings) { l4g.AddFilter("stdout", level, lw) } - if s.EnableFile { - + if _, alreadySet := l4g.Global["file"]; !alreadySet && s.EnableFile { var fileFormat = s.FileFormat if fileFormat == "" { |