Skip to content

Commit f53f953

Browse files
committed
chore(deps-dev): added prettier
1 parent 6d2f0b2 commit f53f953

File tree

9 files changed

+149
-111
lines changed

9 files changed

+149
-111
lines changed

.eslintrc

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
{
22
"root": true,
3-
"extends": "airbnb-base",
4-
"rules": {
5-
"comma-dangle": 0,
6-
"indent": 2,
7-
"object-shorthand": 0,
8-
"func-names": 0,
9-
"max-len": [1, 120, 2],
10-
"no-use-before-define": ["warn"],
11-
"no-param-reassign": 0,
3+
"extends": ["airbnb-base", "prettier"],
4+
"plugins": ["import"],
5+
"rules": {
6+
"comma-dangle": 0,
7+
"indent": 2,
8+
"object-shorthand": 0,
9+
"func-names": 0,
10+
"max-len": [1, 120, 2],
11+
"no-use-before-define": ["warn"],
12+
"no-param-reassign": 0,
1213
"strict": 0,
1314
"import/no-extraneous-dependencies": 1,
1415
"prefer-spread": 0,
15-
"prefer-rest-params": 0,
16-
"prefer-destructuring": 0
17-
},
16+
"prefer-rest-params": 0,
17+
"prefer-destructuring": 0
18+
},
1819
"parserOptions": {
1920
"ecmaVersion": 6
20-
}
21+
},
22+
"ignorePatterns": ["coverage/**/*", "commitlint.config.js"]
2123
}

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
coverage
2+
.github
3+
.nyc_output

README.md

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ npm install log4js @log4js-node/logstash-http
88

99
## Configuration
1010

11-
* `type` - `@log4js-node/logstash-http`
12-
* `url` - `string` - logFaces receiver servlet URL
13-
* `application` - `string` (optional) - used to identify your application's logs
14-
* `logChannel` - `string` (optional) - also used to identify your application's logs [but in a more specific way]
15-
* `logType` - `string` (optional) - used for the `type` field in the logstash data
16-
* `timeout` - `integer` (optional, defaults to 5000ms) - the timeout for the HTTP request.
17-
* `agent` - `http.Agent | https.Agent` (optional) - used to configure the requests being sent out if needed.
11+
- `type` - `@log4js-node/logstash-http`
12+
- `url` - `string` - logFaces receiver servlet URL
13+
- `application` - `string` (optional) - used to identify your application's logs
14+
- `logChannel` - `string` (optional) - also used to identify your application's logs [but in a more specific way]
15+
- `logType` - `string` (optional) - used for the `type` field in the logstash data
16+
- `timeout` - `integer` (optional, defaults to 5000ms) - the timeout for the HTTP request.
17+
- `agent` - `http.Agent | https.Agent` (optional) - used to configure the requests being sent out if needed.
1818

1919
This appender will also pick up Logger context values from the events, and add them as `p_` values in the logFaces event. See the example below for more details.
2020

@@ -23,16 +23,23 @@ This appender will also pick up Logger context values from the events, and add t
2323
```javascript
2424
log4js.configure({
2525
appenders: {
26-
logstash: { type: '@log4js-node/logstash-http', url: 'http://localhost:9200/_bulk', application: 'logstash-log4js', logType: 'application', logChannel: 'node' }
26+
logstash: {
27+
type: "@log4js-node/logstash-http",
28+
url: "http://localhost:9200/_bulk",
29+
application: "logstash-log4js",
30+
logType: "application",
31+
logChannel: "node",
32+
},
2733
},
2834
categories: {
29-
default: { appenders: [ 'logstash' ], level: 'info' }
30-
}
35+
default: { appenders: ["logstash"], level: "info" },
36+
},
3137
});
3238

3339
const logger = log4js.getLogger();
34-
logger.addContext('requestId', '123');
35-
logger.info('some interesting log message');
36-
logger.error('something has gone wrong');
40+
logger.addContext("requestId", "123");
41+
logger.info("some interesting log message");
42+
logger.error("something has gone wrong");
3743
```
44+
3845
This example will result in two log events being sent to your `localhost:9200`. Both events will have a `context.requestId` property with a value of `123`.

lib/index.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
'use strict';
1+
"use strict";
22

33
/**
44
* logstashHTTP appender sends JSON formatted log events to logstashHTTP receivers.
55
*/
6-
const util = require('util');
7-
const axios = require('axios');
6+
const util = require("util");
7+
const axios = require("axios");
88

99
function format(logData) {
1010
return util.format(...logData);
@@ -26,7 +26,7 @@ function logstashHTTPAppender(config) {
2626
const sender = axios.create({
2727
baseURL: config.url,
2828
timeout: config.timeout || 5000,
29-
headers: { 'Content-Type': 'application/x-ndjson' },
29+
headers: { "Content-Type": "application/x-ndjson" },
3030
withCredentials: true,
3131
// The user should pass in the correct Agent type for their url
3232
// since their url won't change after config this should be fine
@@ -48,25 +48,28 @@ function logstashHTTPAppender(config) {
4848
level: event.level.level / 100,
4949
level_name: event.level.levelStr,
5050
channel: config.logChannel,
51-
datetime: (new Date(event.startTime)).toISOString(),
51+
datetime: new Date(event.startTime).toISOString(),
5252
extra: {},
5353
},
5454
];
55-
const logstashJSON = `${JSON.stringify(logstashEvent[0])}\n${JSON.stringify(logstashEvent[1])}\n`;
55+
const logstashJSON = `${JSON.stringify(logstashEvent[0])}\n${JSON.stringify(
56+
logstashEvent[1]
57+
)}\n`;
5658

5759
// send to server
58-
sender.post('', logstashJSON)
59-
.catch((error) => {
60-
if (error.response) {
61-
// eslint-disable-next-line
62-
console.error(
63-
`log4js.logstashHTTP Appender error posting to ${config.url}: ${error.response.status} - ${JSON.stringify(error.response.data)}`
64-
);
65-
} else {
66-
// eslint-disable-next-line
67-
console.error(`log4js.logstashHTTP Appender error: ${error.message}`);
68-
}
69-
});
60+
sender.post("", logstashJSON).catch((error) => {
61+
if (error.response) {
62+
// eslint-disable-next-line
63+
console.error(
64+
`log4js.logstashHTTP Appender error posting to ${config.url}: ${
65+
error.response.status
66+
} - ${JSON.stringify(error.response.data)}`
67+
);
68+
} else {
69+
// eslint-disable-next-line
70+
console.error(`log4js.logstashHTTP Appender error: ${error.message}`);
71+
}
72+
});
7073
};
7174
}
7275

package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"scripts": {
3232
"prepush": "npm test",
3333
"commitmsg": "validate-commit-msg",
34-
"pretest": "eslint \"lib/**/*.js\" \"test/**/*.js\"",
34+
"prettier:fix": "prettier --write .",
35+
"pretest": "prettier --check . && eslint \"lib/**/*.js\" \"test/**/*.js\"",
3536
"test": "tap test/tap/**/*.js --100",
3637
"typings": "tsc -p types/tsconfig.json",
3738
"codecov": "tap 'test/tap/**/*.js' --cov --coverage-report=lcov && codecov"
@@ -49,11 +50,13 @@
4950
"conventional-changelog": "^3.1.25",
5051
"eslint": "^8.29.0",
5152
"eslint-config-airbnb-base": "^15.0.0",
53+
"eslint-config-prettier": "^8.5.0",
5254
"eslint-import-resolver-node": "^0.3.6",
5355
"eslint-plugin-import": "^2.26.0",
5456
"husky": "^8.0.1",
5557
"log4js": "^6.5.2",
5658
"nyc": "^15.1.0",
59+
"prettier": "^2.7.0",
5760
"tap": "^16.3.2",
5861
"typescript": "^4.7.2",
5962
"validate-commit-msg": "^2.14.0"

test/sandbox-coverage.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
'use strict';
1+
"use strict";
22

3-
const sandbox = require('@log4js-node/sandboxed-module');
4-
const NYC = require('nyc');
3+
const sandbox = require("@log4js-node/sandboxed-module");
4+
const NYC = require("nyc");
55

66
sandbox.configure({
77
sourceTransformers: {
88
nyc(source) {
9-
if (this.filename.indexOf('node_modules') > -1) {
9+
if (this.filename.indexOf("node_modules") > -1) {
1010
return source;
1111
}
1212
const nyc = new NYC({});

0 commit comments

Comments
 (0)