@zenvia/logger 1.5.0 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,38 @@
1
+ # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2
+ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
3
+
4
+ name: Node.js CI
5
+
6
+ on:
7
+ - push
8
+ - pull_request
9
+
10
+ jobs:
11
+ test:
12
+
13
+ runs-on: ubuntu-latest
14
+
15
+ strategy:
16
+ matrix:
17
+ node-version: [18.x]
18
+ # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
19
+
20
+ steps:
21
+ - name: Checkout
22
+ uses: actions/checkout@v3
23
+ - name: Use Node.js ${{ matrix.node-version }}
24
+ uses: actions/setup-node@v3
25
+ with:
26
+ node-version: ${{ matrix.node-version }}
27
+ cache: 'npm'
28
+ - name: Install dependencies
29
+ run: npm ci
30
+ - name: Run lint
31
+ run: npm run lint
32
+ - name: Run test
33
+ run: npm test
34
+ - name: Coveralls
35
+ uses: coverallsapp/github-action@v2
36
+ with:
37
+ github-token: ${{ secrets.GITHUB_TOKEN }}
38
+ path-to-lcov: ${{ github.workspace }}/coverage/lcov.info
@@ -0,0 +1,42 @@
1
+ # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
+ # For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
3
+
4
+ name: Node.js Package
5
+
6
+ on:
7
+ release:
8
+ types: [created]
9
+
10
+ jobs:
11
+ build:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v3
15
+ - uses: actions/setup-node@v3
16
+ with:
17
+ node-version: 18
18
+ - name: Install dependencies
19
+ run: npm ci
20
+ - name: Run lint
21
+ run: npm run lint
22
+ - name: Run test
23
+ run: npm test
24
+ - name: Coveralls
25
+ uses: coverallsapp/github-action@v2
26
+ with:
27
+ github-token: ${{ secrets.GITHUB_TOKEN }}
28
+ path-to-lcov: ${{ github.workspace }}/coverage/lcov.info
29
+
30
+ publish-npm:
31
+ needs: build
32
+ runs-on: ubuntu-latest
33
+ steps:
34
+ - uses: actions/checkout@v3
35
+ - uses: actions/setup-node@v3
36
+ with:
37
+ node-version: 18
38
+ registry-url: https://registry.npmjs.org/
39
+ - run: npm ci
40
+ - run: npm publish
41
+ env:
42
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
package/README.md CHANGED
@@ -7,7 +7,7 @@ A wrapper for [Winston](https://github.com/winstonjs/winston) Logging [Node.js](
7
7
  [![Coverage Status](https://coveralls.io/repos/github/zenvia/zenvia-logger-node/badge.svg?branch=master)](https://coveralls.io/github/zenvia/zenvia-logger-node?branch=master)
8
8
  [![Dependencies](https://img.shields.io/david/zenvia/zenvia-logger-node.svg)](https://david-dm.org/zenvia/zenvia-logger-node)
9
9
 
10
- [![Twitter Follow](https://img.shields.io/twitter/follow/ZenviaMobile.svg?style=social)](https://twitter.com/intent/follow?screen_name=ZenviaMobile)
10
+ [![Twitter Follow](https://img.shields.io/twitter/follow/ZENVIA_.svg?style=social)](https://twitter.com/intent/follow?screen_name=ZENVIA_)
11
11
 
12
12
 
13
13
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenvia/logger",
3
- "version": "1.5.0",
3
+ "version": "1.6.1",
4
4
  "description": "A wrapper for Winston Logging Node.js library that formats the output on STDOUT as Logstash JSON format.",
5
5
  "license": "MIT",
6
6
  "main": "./src/index",
@@ -33,8 +33,8 @@
33
33
  ],
34
34
  "dependencies": {
35
35
  "app-root-dir": "^1.0.2",
36
- "cls-rtracer": "^2.6.0",
37
- "winston": "^3.3.3"
36
+ "cls-rtracer": "^2.6.3",
37
+ "winston": "^3.11.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "chai": "^4.2.0",
package/src/index.d.ts CHANGED
@@ -1,5 +1,2 @@
1
- import logger from './lib/logger';
2
- import middleware from './middleware/trace';
3
-
4
- export default logger;
5
- export const traceMiddleware = middleware();
1
+ export { default } from './lib/logger';
2
+ export { default as traceMiddleware } from './middleware/trace';
package/src/lib/logger.js CHANGED
@@ -10,7 +10,25 @@ const rTrace = require('cls-rtracer');
10
10
 
11
11
  const appPackage = require(path.join(appRootDir, 'package'));
12
12
 
13
+ const sanitizeInfo = (info) => {
14
+ const sanitizeCRLFInjection = (str) => str
15
+ .replace(/\n|\r/g, (x) => (x === '\n' ? '#n' : '#r'));
16
+
17
+ Object.keys(info).forEach((key) => {
18
+ if (typeof info[key] === 'string') {
19
+ info[key] = sanitizeCRLFInjection(info[key]);
20
+ return;
21
+ }
22
+
23
+ if (info[key] instanceof Function) {
24
+ delete info[key];
25
+ }
26
+ });
27
+ };
28
+
13
29
  const customFormatJson = winston.format((info) => {
30
+ sanitizeInfo(info);
31
+
14
32
  let stack;
15
33
 
16
34
  if (info.stack) {
@@ -31,12 +49,6 @@ const customFormatJson = winston.format((info) => {
31
49
  traceId: rTrace.id(),
32
50
  };
33
51
 
34
- Object.keys(info).forEach((key) => {
35
- if (info[key] instanceof Function) {
36
- delete info[key];
37
- }
38
- });
39
-
40
52
  return info;
41
53
  });
42
54
 
@@ -1,3 +1,9 @@
1
- declare const traceMiddleware: () => (req: IncomingMessage, res: ServerResponse, next: (err?: any) => void) => void;
1
+ import rTracer from 'cls-rtracer';
2
2
 
3
- export default traceMiddleware;
3
+ declare const traceMiddleware: () =>
4
+ ReturnType<typeof rTracer.expressMiddleware> |
5
+ ReturnType<typeof rTracer.fastifyPlugin> |
6
+ typeof rTracer.hapiPlugin |
7
+ ReturnType<typeof rTracer.koaMiddleware>;
8
+
9
+ export default traceMiddleware;
@@ -241,6 +241,50 @@ describe('Logger test', () => {
241
241
  });
242
242
 
243
243
  describe('Logging format', () => {
244
+ it('should replace LF characters from log (POSIX systems)', () => {
245
+ logger.debug(`some message
246
+ other CRLF injection message`);
247
+ const expectedOutput = {
248
+ '@timestamp': '2018-06-05T18:20:42.345Z',
249
+ '@version': 1,
250
+ application: 'application-name',
251
+ host: os.hostname(),
252
+ message: 'some message#nother CRLF injection message',
253
+ level: 'DEBUG',
254
+ };
255
+
256
+ const actualOutput = stdMocks.flush().stdout[0];
257
+ JSON.parse(actualOutput).should.be.deep.equal(expectedOutput);
258
+
259
+ logger.debug('some\n CRLF\n injection\n message');
260
+ const expectedOutput2 = {
261
+ '@timestamp': '2018-06-05T18:20:42.345Z',
262
+ '@version': 1,
263
+ application: 'application-name',
264
+ host: os.hostname(),
265
+ message: 'some#n CRLF#n injection#n message',
266
+ level: 'DEBUG',
267
+ };
268
+
269
+ const actualOutput2 = stdMocks.flush().stdout[0];
270
+ JSON.parse(actualOutput2).should.be.deep.equal(expectedOutput2);
271
+ });
272
+
273
+ it('should replace CRLF characters from log (Windows systems)', () => {
274
+ logger.debug('some\r\n CRLF\r\n injection\r\n message');
275
+ const expectedOutput = {
276
+ '@timestamp': '2018-06-05T18:20:42.345Z',
277
+ '@version': 1,
278
+ application: 'application-name',
279
+ host: os.hostname(),
280
+ message: 'some#r#n CRLF#r#n injection#r#n message',
281
+ level: 'DEBUG',
282
+ };
283
+
284
+ const actualOutput = stdMocks.flush().stdout[0];
285
+ JSON.parse(actualOutput).should.be.deep.equal(expectedOutput);
286
+ });
287
+
244
288
  it('should get not format when LOGGING_FORMATTER_DISABLED environment is true', () => {
245
289
  delete require.cache[require.resolve('../../src/lib/logger')];
246
290
  process.env.LOGGING_FORMATTER_DISABLED = 'true';
package/.travis.yml DELETED
@@ -1,27 +0,0 @@
1
- language: node_js
2
-
3
- node_js:
4
- - 12
5
-
6
- before_script:
7
- - npm ci
8
-
9
- script:
10
- - npm run lint
11
- - npm test
12
-
13
- after_success:
14
- - npm run test:coveralls
15
-
16
- deploy:
17
- provider: npm
18
- email: $NPM_EMAIL
19
- api_key: $NPM_TOKEN
20
- skip_cleanup: true
21
- on:
22
- tags: true
23
-
24
- notifications:
25
- email:
26
- recipients:
27
- - apisupport@zenvia.com