Logglier / Lograge combination does not take in all fields into Loggly
Closed this issue · 2 comments
Hi!
I'm just trying out the combination of Loggly with logglier and lograge to get all my logs into Loggly. (Say that very fast three times in a row.)
I've been facing problems because I would receive the forms date
and severity
unparsed by Loggly, like so:
Introspecting into the code, I found that this is because logglier's logger is not appending these as JSON but rather as a string. However, I think it shouldn't do so, because my configuration specifies :json
formatter:
config.logger = Logglier.new('https://logs-01.loggly.com/inputs/[redacted]/tag/rails', threaded: true, format: :json)
config.lograge.enabled = true
config.lograge.formatter = Lograge::Formatters::Json.new
(Taken from Rails Logging, Loggly documentation.)
Diving into the code, I found that logglier will only merge these values as a hash if its provided a hash already (here), while Lograge's JSON formatter will deliver a string rather than a hash (here).
As a workaround, this is my current configuration which provides everything I need to:
config.logger = Logglier.new('https://logs-01.loggly.com/inputs/[redacted]/tag/rails', threaded: true, format: :json)
config.lograge.enabled = true
config.lograge.formatter = ->(data) { data }
# alternatively: config.lograge.formatter = Lograge::Formatters::Raw.new
However, I believe that logglier should still deliver a JSON output when the :json
formatter is set, even if it does not receive a Hash.
I may look into performing these modifications and sending a PR, but I'll need some time to get accustomed to the current set of tests. Also, I'd like to ask if this is the desired direction, or if it's preferable to ask Loggly to adjust its documentation and suggest the Raw formatter.
Thanks, and great work!
My suggestion would be to use the Lograge::Formatters::Raw
, which according to the docs returns a ruby hash object. This will allow Logglier to DTRT and format messages as loggly expects.
PS: A doc section about use with Lograge would be accepted. ;-)