Skip to content

Commit

Permalink
initial commit for heroku log format
Browse files Browse the repository at this point in the history
  • Loading branch information
Adnan Rahic committed Nov 26, 2020
1 parent b6b45c4 commit 0422bc0
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
1 change: 1 addition & 0 deletions bin/logagent.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ var moduleAlias = {
sql: '../lib/plugins/output-filter/sql.js',
'access-watch': '../lib/plugins/output-filter/access-watch.js',
'cloudfoundry-format': '../lib/plugins/output-filter/cloudfoundry-format.js',
'heroku-format': '../lib/plugins/output-filter/heroku-format.js',
'hash-fields': '../lib/plugins/output-filter/hash-fields.js',
'aes-encrypt-fields': '../lib/plugins/output-filter/aes-encrypt-fields.js',
'ip-truncate-fields': '../lib/plugins/output-filter/ip-truncate-fields.js',
Expand Down
20 changes: 20 additions & 0 deletions config/examples/heroku-elasticsearch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Global options
options:
# includeOriginalLine: true
# debug: true

input:
cloudFoundry:
module: input-heroku
port: 9999

outputFilter:
heroku-format:
module: heroku-format

output:
elasticsearch:
module: elasticsearch
url: https://logsene-receiver.sematext.com
# debug: true

3 changes: 1 addition & 2 deletions lib/plugins/output-filter/cloudfoundry-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ function filterCloudFoundryMessage (data, context) {
}

function parseCloudFoundryTags (tags) {
console.log(tags)
try {
const parsedTags2dArr = tags
.split(' ')
Expand All @@ -53,7 +52,7 @@ function parseCloudFoundryTags (tags) {

return parsedTags
} catch (error) {
console.log(error)
console.error(error)
return tags
}
}
Expand Down
42 changes: 42 additions & 0 deletions lib/plugins/output-filter/heroku-format.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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)
}
}
return data
}

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)
} catch (err) {
console.error(err)
return callback(null, log)
}
}

0 comments on commit 0422bc0

Please sign in to comment.