@tiledesk/tiledesk-tybot-connector 2.0.7-rc1 → 2.0.7-rc3

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.
Files changed (3) hide show
  1. package/Logger.js +17 -13
  2. package/logs/app.log +32131 -0
  3. package/package.json +3 -2
package/Logger.js CHANGED
@@ -2,15 +2,16 @@ let { Publisher } = require("@tiledesk/tiledesk-multi-worker");
2
2
 
3
3
  const FLOW_LOGS_ENABLED = process.env.FLOW_LOGS_ENABLED;
4
4
  const AMQP_MANAGER_URL = process.env.AMQP_MANAGER_URL;
5
+ const LOGS_BASE_ROUTING_KEY = process.env.LOGS_BASE_ROUTING_KEY || "apps.tilechat.logs";
6
+
7
+ const levels = { error: 0, warn: 1, info: 2, debug: 3 };
8
+
5
9
  let publisher = new Publisher(AMQP_MANAGER_URL, {
6
10
  debug: false,
7
11
  queueName: "logs_queue",
8
- exchange: "tiledesk-multi",
9
- topic: "logs",
12
+ exchange: "amq.topic"
10
13
  })
11
14
 
12
- const levels = { error: 0, warn: 1, info: 2, debug: 3 };
13
-
14
15
  class Logger {
15
16
 
16
17
  constructor(config) {
@@ -35,9 +36,12 @@ class Logger {
35
36
  }
36
37
 
37
38
  this.request_id = config.request_id;
39
+
38
40
  this.dev = false;
39
41
  if (config.dev && config.dev === true) {
40
42
  this.dev = true;
43
+ } else {
44
+ this._disableDebugMethods()
41
45
  }
42
46
 
43
47
  // if (!AMQP_MANAGER_URL) {
@@ -70,12 +74,13 @@ class Logger {
70
74
 
71
75
  base(level, text) {
72
76
  if (!this.request_id || !publisher) {
73
- //console.log("Return because request or publisher is undefined", this.request_id, publisher);
77
+ console.log("Return because request or publisher is undefined", this.request_id, publisher);
74
78
  return;
75
79
  }
76
80
 
77
81
  let data = {
78
82
  request_id: this.request_id,
83
+ id_project: this.request_id.split("-")[2],
79
84
  text: text,
80
85
  level: level,
81
86
  nlevel: levels[level],
@@ -83,15 +88,14 @@ class Logger {
83
88
  dev: this.dev
84
89
  }
85
90
 
86
- publisher.publish(data, (err, ok) => {
87
- if (err) console.warn("publish log fail: ", err);
88
- return;
89
- })
91
+ let topic = LOGS_BASE_ROUTING_KEY + `.${this.request_id}`;
92
+ publisher.publish(data, topic);
93
+ return;
90
94
  }
91
95
 
92
96
  formatLog(args) {
93
97
  return args
94
- .map(arg => (typeof arg === "object" ? JSON.stringify(arg, null, 2) : arg ))
98
+ .map(arg => (typeof arg === "object" ? JSON.stringify(arg, null, 2) : arg))
95
99
  .join(" ")
96
100
  }
97
101
 
@@ -99,13 +103,13 @@ class Logger {
99
103
  _disableMethods() {
100
104
  const methods = ['error', 'warn', 'info', 'debug'];
101
105
  methods.forEach(method => {
102
- this[method] = () => {};
106
+ this[method] = () => { };
103
107
  });
104
108
  }
105
109
 
106
- _disableDebugMethod() {
110
+ _disableDebugMethods() {
107
111
  const method = 'debug';
108
- this[method] = () => {};
112
+ this[method] = () => { };
109
113
  }
110
114
 
111
115
  }