@canmingir/link-express 1.6.10 → 1.6.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canmingir/link-express",
3
- "version": "1.6.10",
3
+ "version": "1.6.11",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "NucTeam",
@@ -21,6 +21,7 @@
21
21
  "dependencies": {
22
22
  "@aws-sdk/client-dynamodb": "^3.614.0",
23
23
  "@aws-sdk/lib-dynamodb": "^3.614.0",
24
+ "@elastic/ecs-pino-format": "^1.5.0",
24
25
  "axios": "^1.7.2",
25
26
  "cors": "^2.8.5",
26
27
  "dotenv": "^16.4.5",
@@ -33,6 +34,8 @@
33
34
  "lodash": "^4.17.21",
34
35
  "morgan": "^1.10.0",
35
36
  "pg": "^8.12.0",
37
+ "pino": "^10.1.0",
38
+ "pino-elasticsearch": "^8.1.0",
36
39
  "prom-client": "^15.1.3",
37
40
  "sequelize": "^6.37.3",
38
41
  "swagger-jsdoc": "^6.2.8",
package/src/logger.js ADDED
@@ -0,0 +1,34 @@
1
+ const { ecsFormat } = require("@elastic/ecs-pino-format");
2
+ const pino = require("pino");
3
+ const pinoElastic = require("pino-elasticsearch");
4
+
5
+ const config = require("./config");
6
+
7
+ const { logger: loggerConfig, project } = config();
8
+
9
+ const streams = [{ stream: process.stdout }];
10
+
11
+ const streamToElastic = pinoElastic({
12
+ index: loggerConfig.elasticsearch.index,
13
+ consistency: loggerConfig.elasticsearch.consistency || "one",
14
+ node: loggerConfig.elasticsearch.node,
15
+ esVersion: loggerConfig.elasticsearch.esVersion || 8,
16
+ flushBytes: loggerConfig.elasticsearch.flushBytes || 1000,
17
+ });
18
+
19
+ streams.push({ stream: streamToElastic });
20
+
21
+ const logger = pino(
22
+ {
23
+ ...ecsFormat(),
24
+ base: {
25
+ service: {
26
+ name: project.name,
27
+ version: project.version,
28
+ },
29
+ },
30
+ },
31
+ pino.multistream(streams)
32
+ );
33
+
34
+ module.exports = logger;
package/src/platform.js CHANGED
@@ -5,6 +5,7 @@ const error = require("./error");
5
5
  let _express;
6
6
  let _postgres;
7
7
  let _dynamodb;
8
+ let _logger;
8
9
 
9
10
  function init(config = {}) {
10
11
  return new Promise((resolve, reject) => {
@@ -13,10 +14,16 @@ function init(config = {}) {
13
14
  module.exports = fs.readFileSync(filename, "utf8").trim();
14
15
  };
15
16
 
16
- const { postgres, dynamodb } = require("./config").init(config);
17
+ const { postgres, dynamodb, logger } = require("./config").init(config);
17
18
 
18
19
  _express = require("./express");
19
20
 
21
+ if (logger) {
22
+ _logger = require("./logger");
23
+ } else {
24
+ _logger = console;
25
+ }
26
+
20
27
  if (postgres) {
21
28
  _postgres = require("./postgres");
22
29
  }
@@ -43,4 +50,7 @@ module.exports = {
43
50
  require: (pkg) => require(pkg),
44
51
  authorization,
45
52
  error,
53
+ get logger() {
54
+ return _logger;
55
+ },
46
56
  };