-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial commit for heroku log format
- Loading branch information
Adnan Rahic
committed
Nov 26, 2020
1 parent
b6b45c4
commit 0422bc0
Showing
4 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |