@5minds/node-red-contrib-processcube-elasticsearch 0.3.1-add-update-cycle-49119c-m3ra2qmc → 0.3.1-add-update-cycle-5f3443-m3sifcje

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.
@@ -1,6 +1,8 @@
1
1
  module.exports = function (RED) {
2
2
  'use strict';
3
3
 
4
+ let lock = false;
5
+
4
6
  function LogElasticLoggerNode(config) {
5
7
  let winston = require('winston');
6
8
  let winstonElasticSearch = require('winston-elasticsearch');
@@ -15,6 +17,8 @@ module.exports = function (RED) {
15
17
  let url, user, password, index;
16
18
 
17
19
  function refresh() {
20
+ if (lock) return;
21
+
18
22
  // Elastic settings
19
23
  let newUrl = RED.util.evaluateNodeProperty(config.url, config.urlType, this);
20
24
  if (newUrl == '') {
@@ -44,8 +48,6 @@ module.exports = function (RED) {
44
48
  return;
45
49
  }
46
50
 
47
- if (this.logger) this.logger.close();
48
-
49
51
  url = newUrl;
50
52
  user = newUser;
51
53
  password = newPassword;
@@ -85,13 +87,24 @@ module.exports = function (RED) {
85
87
  Debug: 3,
86
88
  },
87
89
  };
88
- this.logger = new winston.createLogger({
90
+
91
+ const newLogger = new winston.createLogger({
89
92
  exitOnError: false,
90
93
  level: 'Debug',
91
94
  levels: logLevels.levels,
92
95
  transports: transports,
93
96
  });
94
97
 
98
+ lock = true;
99
+
100
+ try {
101
+ if (this.logger) this.logger.close();
102
+
103
+ this.logger = newLogger;
104
+ } finally {
105
+ lock = false;
106
+ }
107
+
95
108
  this.debug('elastic-search logger created');
96
109
  }
97
110
 
@@ -139,7 +152,20 @@ module.exports = function (RED) {
139
152
  },
140
153
  });
141
154
 
142
- LogElasticLoggerNode.prototype.addToLog = function addTolog(loglevel, msg) {
143
- this.logger.log(loglevel, msg.payload.message, msg.payload.meta);
155
+ LogElasticLoggerNode.prototype.addToLog = function addToLog(loglevel, msg) {
156
+ let attempt = 0;
157
+
158
+ const tryLog = () => {
159
+ if (!lock && this.logger) {
160
+ this.logger.log(loglevel, msg.payload.message, msg.payload.meta);
161
+ } else if (attempt < 5) {
162
+ attempt++;
163
+ setTimeout(tryLog, 10);
164
+ } else {
165
+ this.error('Failed to log message after multiple attempts due to logger lock.');
166
+ }
167
+ };
168
+
169
+ tryLog();
144
170
  };
145
171
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@5minds/node-red-contrib-processcube-elasticsearch",
3
- "version": "0.3.1-add-update-cycle-49119c-m3ra2qmc",
3
+ "version": "0.3.1-add-update-cycle-5f3443-m3sifcje",
4
4
  "license": "MIT",
5
5
  "description": "Node-RED nodes for Elasticsearch",
6
6
  "scripts": {