@opengis/fastify-table 1.1.32 → 1.1.33

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.
package/index.js CHANGED
@@ -51,17 +51,14 @@ async function plugin(fastify, opt) {
51
51
  });
52
52
 
53
53
  fastify.setErrorHandler((error, request, reply) => {
54
- // console.log(error)
55
- debugger;
56
54
  if (error.validation) {
57
- // request.log.warn(request, { code: error?.code, status: 422, error: error.toString() });
58
- const { params, instancePath } = error.validation?.[0] || {};
59
- return reply.status(422).send(`invalid params: ${instancePath?.substring(1)} (${params?.pattern})`);
55
+ request.log.warn(request, { code: error?.code, status: 422, error: error.toString() });
56
+ return reply.status(422).send(error.toString());
60
57
  }
61
58
  if (error.stack?.startsWith('Error: unhandled exception')) {
59
+ request.log.fatal(request, { status: 501, error: error.toString() });
62
60
  return reply.status(500).send('ServerError');
63
61
  }
64
-
65
62
  return reply.status(error.statusCode || 500).send(error);
66
63
  });
67
64
 
@@ -1,30 +1,24 @@
1
- 'use strict';
2
- const streams = {}
1
+ const streams = {};
3
2
 
3
+ import build from 'pino-abstract-transport';
4
4
  import { createStream } from 'rotating-file-stream';
5
5
  import labels from './labels.js';
6
6
 
7
7
  import config from '../config.js';
8
8
 
9
-
10
- const generator = (opt) => () => {
11
-
9
+ const generator = () => () => {
12
10
  const date = new Date();
13
11
  const tzOffset = date.getTimezoneOffset();
14
12
  const currentTimeWithTimezome = date - tzOffset * 60 * 1000;
15
13
 
16
- if (opt.interval === '1h') {
17
- return `${new Date(currentTimeWithTimezome).toISOString().substring(0, 13).replace(/:/g, '_')}.log`;
18
- }
19
- if (opt.interval === '1m') {
20
- return `${new Date(currentTimeWithTimezome).toISOString().substring(0, 16).replace(/:/g, '_')}.log`;
21
- }
22
- if (!opt.interval || opt.interval === '1d') {
23
- return `${new Date(currentTimeWithTimezome).toISOString().split('T')[0].replace(/:/g, '_')}.log`;
24
- }
14
+ // if (!opt.interval || opt.interval === '1d') {
15
+ return `${new Date(currentTimeWithTimezome).toISOString().split('T')[0].replace(/:/g, '_')}.log`;
16
+ // }
25
17
  };
26
18
 
27
- const { dir = 'log', interval = '1d', compress = 'gzip', maxFiles = 90, local: teeToStdout } = config?.log || {};
19
+ const {
20
+ dir = 'log', interval = '1d', compress = 'gzip', maxFiles = 90, local: teeToStdout,
21
+ } = config?.log || {};
28
22
  function createFileStream({ level }) {
29
23
  console.log(dir, level, generator({ interval })(), interval, compress);
30
24
  const params = {
@@ -41,18 +35,16 @@ function createFileStream({ level }) {
41
35
  return createStream(generator({ interval }), params);
42
36
  }
43
37
 
44
-
45
- import build from 'pino-abstract-transport'
46
-
47
38
  export default function () {
48
- return build(function (source) {
49
- source.on('data', function (obj) {
39
+ return build((source) => {
40
+ source.on('data', (obj) => {
41
+ if (['incoming request', 'request completed'].includes(obj.msg)) return;
50
42
  // console.log(obj)
51
43
  const lvl = obj.msg?.file || obj.file || labels[obj.level];
52
- streams[lvl] = streams[lvl] || createFileStream({ level: lvl })
53
- streams[lvl].write(JSON.stringify(obj) + '\n');
54
- })
44
+ streams[lvl] = streams[lvl] || createFileStream({ level: lvl });
45
+ streams[lvl].write(`${JSON.stringify(obj)}\n`);
46
+ });
55
47
  }, {
56
- parseLine: (line) => JSON.parse(line)
57
- })
48
+ parseLine: (line) => JSON.parse(line),
49
+ });
58
50
  }
@@ -19,6 +19,12 @@ const options = {
19
19
  transport: {
20
20
  targets: [{
21
21
  target: './createFileStream.js', // path.resolve('utils/createFileStream.js')
22
+ }, {
23
+ // Use target: 'pino/file' with STDOUT descriptor 1 to write
24
+ // logs without any change.
25
+ level: 'error',
26
+ target: 'pino/file',
27
+ options: { destination: 1 },
22
28
  }],
23
29
  },
24
30
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "1.1.32",
3
+ "version": "1.1.33",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "main": "index.js",
package/server.js CHANGED
@@ -9,7 +9,15 @@ import loggerTest from './logger/logger.test.api.js';
9
9
  const app = Fastify({ logger });
10
10
  app.register(appService, config);
11
11
 
12
- app.get('/logger-test', loggerTest);
12
+ app.get('/logger-test', {
13
+ schema: {
14
+ querystring: {
15
+ name: { type: 'string' },
16
+ excitement: { type: 'integer' },
17
+ },
18
+ },
19
+ }, loggerTest);
20
+
13
21
  app.listen({ host: '0.0.0.0', port: process.env.PORT || 3000 }, (err) => {
14
22
  if (err) {
15
23
  app.log.error(err);