Skip to content

Commit

Permalink
added json parsing heroku filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Adnan Rahic committed Nov 27, 2020
1 parent 0422bc0 commit 020d3f0
Showing 1 changed file with 9 additions and 26 deletions.
35 changes: 9 additions & 26 deletions lib/plugins/output-filter/heroku-format.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
function jsonParse (text) {
try {
return JSON.parse(text)
} catch (err) {
return null
}
}

function parseHerokuMessage (data, context) {
if (data) {
data._type = context.sourceName.replace('_' + context.index, '')
data.logSource = ('' + data.logSource).replace('_' + context.index, '')
if (!data['@timestamp']) {
data['@timestamp'] = new Date()
}
if (data.message) {
data.json = jsonParse(data.message)
const json = data.json
const message = data.message
delete data.json
delete data.message
return {
message,
...json,
...data
}
}
return data
Expand All @@ -23,18 +16,8 @@ function parseHerokuMessage (data, context) {
module.exports = function (context, config, eventEmitter, log, callback) {
try {
const parsedLog = parseHerokuMessage(log, context)
const json = parsedLog.json
const message = parsedLog.message
delete parsedLog.json
delete parsedLog.message

const structuredLog = {
message,
...json,
...parsedLog
}

return callback(null, structuredLog)
return callback(null, parsedLog)
} catch (err) {
console.error(err)
return callback(null, log)
Expand Down

0 comments on commit 020d3f0

Please sign in to comment.