Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Commit

Permalink
feat: make papertrail host configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubMatejka committed Mar 6, 2018
1 parent ee6f5f1 commit 864d632
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ The plugin ignores implicit Lambda logs (starting with `START`, `END` and `REPOR
custom:
papertrail:
port: 1234
host: logs.papertrailapp.com

plugins:
- '@keboola/serverless-papertrail-logging'
```
It must be put before **serverless-webpack** and other similar plugins to work correctly.
It must be put before **serverless-webpack** and other similar plugins to work correctly.

Host name is optional and has default value `logs.papertrailapp.com`.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@keboola/serverless-papertrail-logging",
"version": "1.0.8",
"version": "1.1.0",
"description": "Serverless plugin for log delivery from CloudWatch Logs to Papertrail using a lambda function with log groups subscription",
"main": "src/index.js",
"repository": "https://github.com/keboola/serverless-papertrail-logging",
Expand Down
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class PapertrailLogging {
if (!_.has(this.service, 'custom.papertrail.port')) {
throw new this.serverless.classes.Error('Configure Papertrail port in custom.papertrail.port of the serverless.yml');
}

this.papertrailHost = _.get(this.service, 'custom.papertrail.host', 'logs.papertrailapp.com');
}

static getFunctionName() {
Expand Down Expand Up @@ -55,6 +57,7 @@ class PapertrailLogging {
let templateFile = fs.readFileSync(templatePath, 'utf-8');

let handlerFunction = templateFile
.replace('%papertrailHost%', this.papertrailHost)
.replace('%papertrailPort%', this.service.custom.papertrail.port)
.replace('%papertrailHostname%', this.service.service)
.replace('%papertrailProgram%', this.service.provider.stage);
Expand Down
4 changes: 2 additions & 2 deletions src/logger.handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ const formatLog = (level, message) => {
}
};

exports.handler = function (event, context, callback) {
exports.handler = (event, context, callback) => {
const logger = new (winston.Logger)({
transports: [],
});
logger.add(papertrail, {
host: 'logs.papertrailapp.com',
host: '%papertrailHost%',
port: '%papertrailPort%',
hostname: '%papertrailHostname%',
program: '%papertrailProgram%',
Expand Down

0 comments on commit 864d632

Please sign in to comment.