@iobroker/js-controller-common 4.0.19 → 4.1.0-alpha.10-20220312-cb53b8bb
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/build/index.d.ts +5 -0
- package/build/index.js +30 -0
- package/build/lib/common/exitCodes.d.ts +58 -0
- package/build/lib/common/exitCodes.d.ts.map +1 -0
- package/build/lib/common/exitCodes.js +62 -0
- package/build/lib/common/exitCodes.js.map +1 -0
- package/build/lib/common/logger.d.ts +14 -0
- package/build/lib/common/logger.d.ts.map +1 -0
- package/{lib → build/lib}/common/logger.js +187 -193
- package/build/lib/common/logger.js.map +1 -0
- package/build/lib/common/password.d.ts +37 -0
- package/build/lib/common/password.d.ts.map +1 -0
- package/{lib → build/lib}/common/password.js +26 -46
- package/build/lib/common/password.js.map +1 -0
- package/build/lib/common/tools.d.ts +568 -0
- package/build/lib/common/tools.d.ts.map +1 -0
- package/{lib → build/lib}/common/tools.js +1110 -1475
- package/build/lib/common/tools.js.map +1 -0
- package/package.json +14 -9
- package/index.js +0 -6
- package/lib/common/exitCodes.js +0 -65
|
@@ -1,85 +1,106 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.logger = void 0;
|
|
26
|
+
const winston_1 = __importDefault(require("winston"));
|
|
27
|
+
const winston_daily_rotate_file_1 = __importDefault(require("winston-daily-rotate-file"));
|
|
28
|
+
const fs_1 = __importDefault(require("fs"));
|
|
29
|
+
const path_1 = __importDefault(require("path"));
|
|
30
|
+
const os_1 = __importDefault(require("os"));
|
|
31
|
+
const tools = __importStar(require("./tools"));
|
|
32
|
+
const winston_transport_1 = __importDefault(require("winston-transport"));
|
|
33
|
+
const triple_beam_1 = require("triple-beam");
|
|
34
|
+
const deep_clone_1 = __importDefault(require("deep-clone"));
|
|
13
35
|
const hostname = tools.getHostName();
|
|
14
|
-
const Transport = require('winston-transport');
|
|
15
|
-
const { LEVEL } = require('triple-beam');
|
|
16
|
-
const deepClone = require('deep-clone');
|
|
17
|
-
|
|
18
36
|
let SysLog;
|
|
19
37
|
try {
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
20
39
|
SysLog = require('winston-syslog').Syslog;
|
|
21
|
-
}
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
22
42
|
//console.log('No syslog support');
|
|
23
43
|
}
|
|
24
|
-
|
|
25
44
|
let Seq;
|
|
26
45
|
try {
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
27
47
|
Seq = require('@datalust/winston-seq').SeqTransport;
|
|
28
|
-
}
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
29
50
|
//console.log('No seq support');
|
|
30
51
|
}
|
|
31
|
-
|
|
32
52
|
// We must check if SysLog is defined before extending it
|
|
33
|
-
const IoSysLog =
|
|
34
|
-
SysLog &&
|
|
53
|
+
const IoSysLog = SysLog &&
|
|
35
54
|
class extends SysLog {
|
|
36
55
|
constructor(options) {
|
|
37
56
|
super(options);
|
|
38
57
|
}
|
|
39
|
-
|
|
40
58
|
log(info, callback) {
|
|
59
|
+
var _a;
|
|
41
60
|
// we need to map the ioBroker loglevels to the Syslog ones
|
|
42
61
|
const ioInfo = info;
|
|
43
|
-
if (ioInfo[LEVEL] === 'warn') {
|
|
44
|
-
ioInfo[LEVEL] = 'warning';
|
|
62
|
+
if (ioInfo[triple_beam_1.LEVEL] === 'warn') {
|
|
63
|
+
ioInfo[triple_beam_1.LEVEL] = 'warning';
|
|
45
64
|
}
|
|
46
|
-
if (ioInfo[LEVEL] === 'info') {
|
|
47
|
-
ioInfo[LEVEL] = 'notice';
|
|
65
|
+
if (ioInfo[triple_beam_1.LEVEL] === 'info') {
|
|
66
|
+
ioInfo[triple_beam_1.LEVEL] = 'notice';
|
|
48
67
|
}
|
|
49
|
-
if (ioInfo[LEVEL] === 'debug') {
|
|
50
|
-
ioInfo[LEVEL] = 'info';
|
|
68
|
+
if (ioInfo[triple_beam_1.LEVEL] === 'debug') {
|
|
69
|
+
ioInfo[triple_beam_1.LEVEL] = 'info';
|
|
51
70
|
}
|
|
52
|
-
if (ioInfo[LEVEL] === 'silly') {
|
|
53
|
-
ioInfo[LEVEL] = 'debug';
|
|
71
|
+
if (ioInfo[triple_beam_1.LEVEL] === 'silly') {
|
|
72
|
+
ioInfo[triple_beam_1.LEVEL] = 'debug';
|
|
54
73
|
}
|
|
55
|
-
|
|
74
|
+
// No clue why log could ever be undefined, but hey...
|
|
75
|
+
(_a = super.log) === null || _a === void 0 ? void 0 : _a.call(this, ioInfo, callback);
|
|
56
76
|
}
|
|
57
77
|
};
|
|
58
|
-
|
|
59
78
|
// We want to enhance some data for Seq
|
|
60
|
-
const IoSeq =
|
|
61
|
-
Seq &&
|
|
79
|
+
const IoSeq = Seq &&
|
|
62
80
|
class extends Seq {
|
|
63
81
|
log(info, callback) {
|
|
64
|
-
const ioInfo =
|
|
82
|
+
const ioInfo = (0, deep_clone_1.default)(info);
|
|
65
83
|
ioInfo.props = ioInfo.props || {};
|
|
66
|
-
|
|
67
84
|
// map our log levels to Seq levels
|
|
68
85
|
const level = (ioInfo.level || '').toLowerCase();
|
|
69
86
|
if (level.includes('error')) {
|
|
70
87
|
ioInfo.level = 'Error';
|
|
71
|
-
}
|
|
88
|
+
}
|
|
89
|
+
else if (level.includes('warn')) {
|
|
72
90
|
ioInfo.level = 'Warning';
|
|
73
|
-
}
|
|
91
|
+
}
|
|
92
|
+
else if (level.includes('info')) {
|
|
74
93
|
ioInfo.level = 'Information';
|
|
75
|
-
}
|
|
94
|
+
}
|
|
95
|
+
else if (level.includes('debug')) {
|
|
76
96
|
ioInfo.level = 'Debug';
|
|
77
|
-
}
|
|
97
|
+
}
|
|
98
|
+
else if (level.includes('silly')) {
|
|
78
99
|
ioInfo.level = 'Verbose';
|
|
79
|
-
}
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
80
102
|
ioInfo.level = 'Information';
|
|
81
103
|
}
|
|
82
|
-
|
|
83
104
|
// we add own properties
|
|
84
105
|
ioInfo.props.Hostname = tools.getHostName();
|
|
85
106
|
if (ioInfo.message) {
|
|
@@ -88,24 +109,23 @@ const IoSeq =
|
|
|
88
109
|
if (msgParts) {
|
|
89
110
|
ioInfo.props.Source = msgParts[1];
|
|
90
111
|
ioInfo.props.Pid = msgParts[2];
|
|
91
|
-
}
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
92
114
|
ioInfo.props.Source = 'js-controller';
|
|
93
115
|
}
|
|
94
116
|
}
|
|
95
117
|
super.log(ioInfo, callback);
|
|
96
118
|
}
|
|
97
119
|
};
|
|
98
|
-
|
|
99
120
|
// Class used to inform adapter about new log entry
|
|
100
|
-
class NotifierTransport extends
|
|
121
|
+
class NotifierTransport extends winston_transport_1.default {
|
|
101
122
|
constructor(opts) {
|
|
102
123
|
super(opts);
|
|
103
124
|
this.name = 'NT'; // NotifierTransport
|
|
104
125
|
}
|
|
105
|
-
|
|
106
126
|
log(info, callback) {
|
|
107
127
|
const msg = {
|
|
108
|
-
severity: info[LEVEL],
|
|
128
|
+
severity: info[triple_beam_1.LEVEL],
|
|
109
129
|
ts: new Date(info.timestamp).getTime(),
|
|
110
130
|
message: info.message
|
|
111
131
|
};
|
|
@@ -113,93 +133,74 @@ class NotifierTransport extends Transport {
|
|
|
113
133
|
callback();
|
|
114
134
|
}
|
|
115
135
|
}
|
|
116
|
-
|
|
117
|
-
const logger = function (level, files, noStdout, prefix) {
|
|
118
|
-
let userOptions = {};
|
|
136
|
+
function logger(level, files, noStdout, prefix) {
|
|
119
137
|
const options = {
|
|
120
138
|
transports: []
|
|
121
139
|
};
|
|
122
|
-
|
|
123
140
|
//var defaultMaxSize;// = 10 * 1024 * 1024;
|
|
124
|
-
|
|
125
141
|
if (typeof files === 'string') {
|
|
126
142
|
files = [files];
|
|
127
143
|
}
|
|
128
|
-
|
|
129
|
-
const formatter = info => `${timestamp(info.timestamp)} - ${info.level}: ${info.message}`;
|
|
130
|
-
|
|
144
|
+
const formatter = (info) => `${timestamp(info.timestamp)} - ${info.level}: ${info.message}`;
|
|
131
145
|
files = files || [];
|
|
132
|
-
|
|
133
146
|
// indicator which is used to determine the log dir for developing, where it should be inside the repository
|
|
134
147
|
const isNpm = !__dirname
|
|
135
148
|
.replace(/\\/g, '/')
|
|
136
149
|
.toLowerCase()
|
|
137
|
-
.includes(tools.appName.toLowerCase()
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
userOptions = deepClone(level);
|
|
141
|
-
|
|
150
|
+
.includes(`${tools.appName.toLowerCase()}.js-controller/packages/`);
|
|
151
|
+
if (tools.isObject(level)) {
|
|
152
|
+
const userOptions = (0, deep_clone_1.default)(level);
|
|
142
153
|
level = userOptions.level;
|
|
143
|
-
prefix = userOptions.prefix;
|
|
154
|
+
prefix = userOptions.prefix || '';
|
|
144
155
|
noStdout = userOptions.noStdout;
|
|
145
|
-
|
|
146
156
|
const winstonFormats = [];
|
|
147
|
-
|
|
157
|
+
/** @ts-expect-error formatter arg wrongly documented */
|
|
158
|
+
winstonFormats.push(winston_1.default.format.timestamp({ format: timestamp }));
|
|
148
159
|
if (userOptions.json === undefined || userOptions.json) {
|
|
149
|
-
winstonFormats.push(
|
|
160
|
+
winstonFormats.push(winston_1.default.format.json());
|
|
150
161
|
}
|
|
151
162
|
if (prefix) {
|
|
152
|
-
winstonFormats.push(
|
|
163
|
+
winstonFormats.push(winston_1.default.format.label({ label: prefix }));
|
|
153
164
|
}
|
|
154
165
|
if (userOptions.colorize === undefined || userOptions.colorize) {
|
|
155
|
-
winstonFormats.push(
|
|
166
|
+
winstonFormats.push(winston_1.default.format.colorize());
|
|
156
167
|
}
|
|
157
|
-
options.format =
|
|
158
|
-
|
|
168
|
+
options.format = winston_1.default.format.combine.apply(null, winstonFormats);
|
|
159
169
|
if (userOptions.prefix !== undefined) {
|
|
160
170
|
delete userOptions.prefix;
|
|
161
171
|
}
|
|
162
|
-
|
|
163
172
|
if (userOptions.transport) {
|
|
164
173
|
let fName = 0;
|
|
165
|
-
const isWindows =
|
|
174
|
+
const isWindows = os_1.default.platform().startsWith('win');
|
|
166
175
|
Object.keys(userOptions.transport).forEach(f => {
|
|
167
176
|
const transport = userOptions.transport[f];
|
|
168
|
-
|
|
169
177
|
transport._defaultConfigLoglevel = transport.level; // remember Loglevel if set
|
|
170
178
|
transport.level = transport.level || level;
|
|
171
|
-
|
|
172
179
|
if (transport.type === 'file' && transport.enabled !== false) {
|
|
173
180
|
transport.filename = transport.filename || 'log/' + tools.appName;
|
|
174
|
-
|
|
175
181
|
if (!transport.fileext && transport.filename.indexOf('.log') === -1) {
|
|
176
182
|
transport.fileext = '.log';
|
|
177
183
|
}
|
|
178
|
-
|
|
179
184
|
if (!fName) {
|
|
180
185
|
transport.systemLog = true;
|
|
181
186
|
}
|
|
182
|
-
|
|
183
187
|
transport.handleExceptions = false;
|
|
184
|
-
transport.name =
|
|
188
|
+
transport.name = fName ? `dailyRotateFile${fName}` : tools.appName;
|
|
185
189
|
fName++;
|
|
186
190
|
transport.filename = transport.filename.replace(/\\/g, '/');
|
|
187
191
|
if (transport.filename.match(/^\w:\/|^\//)) {
|
|
188
|
-
transport.filename =
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
);
|
|
192
|
+
transport.filename = path_1.default.normalize(transport.filename);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
transport.filename = path_1.default.normalize(`${tools.getControllerDir()}${isNpm ? '/../../' : '/'}${transport.filename}`);
|
|
193
196
|
}
|
|
194
|
-
transport.auditFile = transport.filename
|
|
195
|
-
|
|
197
|
+
transport.auditFile = `${transport.filename}-audit.json`;
|
|
196
198
|
transport.createSymlink =
|
|
197
199
|
transport.createSymlink !== undefined ? transport.createSymlink : !isWindows;
|
|
198
200
|
transport.symlinkName =
|
|
199
201
|
transport.symlinkName !== undefined
|
|
200
202
|
? transport.symlinkName
|
|
201
|
-
:
|
|
202
|
-
|
|
203
|
+
: path_1.default.basename(`${transport.filename}.current.log`);
|
|
203
204
|
transport.filename += '.%DATE%' + (transport.fileext || '');
|
|
204
205
|
//transport.label = prefix || ''; //TODO format.label()
|
|
205
206
|
// transport.json = (transport.json !== undefined) ? transport.json : false; // TODO format.json(), new Default!!
|
|
@@ -209,35 +210,35 @@ const logger = function (level, files, noStdout, prefix) {
|
|
|
209
210
|
transport.localTime !== undefined
|
|
210
211
|
? transport.localTime
|
|
211
212
|
: userOptions.localTime === undefined
|
|
212
|
-
|
|
213
|
-
|
|
213
|
+
? true
|
|
214
|
+
: userOptions.localTime;
|
|
214
215
|
transport.datePattern = 'YYYY-MM-DD';
|
|
215
|
-
transport.format =
|
|
216
|
+
transport.format = winston_1.default.format.combine(winston_1.default.format.printf(formatter));
|
|
216
217
|
/*transport.logException = function (message, info, next, err) {
|
|
217
218
|
console.error(message);
|
|
218
219
|
};*/
|
|
219
220
|
transport.zippedArchive = isWindows
|
|
220
221
|
? false
|
|
221
222
|
: transport.zippedArchive !== undefined
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
223
|
+
? transport.zippedArchive
|
|
224
|
+
: true;
|
|
225
225
|
if (transport.maxFiles === null && userOptions.maxDays) {
|
|
226
226
|
transport.maxFiles = userOptions.maxDays + 'd';
|
|
227
227
|
}
|
|
228
|
-
|
|
229
228
|
try {
|
|
230
|
-
const _log = new
|
|
229
|
+
const _log = new winston_daily_rotate_file_1.default(transport);
|
|
231
230
|
options.transports.push(_log);
|
|
232
|
-
}
|
|
231
|
+
}
|
|
232
|
+
catch (e) {
|
|
233
233
|
if (e.code === 'EACCES') {
|
|
234
234
|
// modify error code to make it unique for handling
|
|
235
235
|
e.code = 'EACCES_LOG';
|
|
236
236
|
}
|
|
237
237
|
throw e;
|
|
238
238
|
}
|
|
239
|
-
}
|
|
240
|
-
|
|
239
|
+
}
|
|
240
|
+
else if (transport.type === 'syslog' && transport.enabled !== false) {
|
|
241
|
+
if (!IoSysLog) {
|
|
241
242
|
console.error('Syslog configured, but not installed! Ignore');
|
|
242
243
|
return;
|
|
243
244
|
}
|
|
@@ -252,88 +253,93 @@ const logger = function (level, files, noStdout, prefix) {
|
|
|
252
253
|
// app_name: The name of the application (Default: process.title).
|
|
253
254
|
// eol: The end of line character to be added to the end of the message (Default: Message without modifications).
|
|
254
255
|
// replace the used by syslog attribute "type" with own "sysLogType"
|
|
255
|
-
|
|
256
256
|
// If no name defined, use hostname as name
|
|
257
257
|
transport.localhost = transport.localhost || hostname;
|
|
258
|
-
transport.format =
|
|
258
|
+
transport.format = winston_1.default.format.combine(winston_1.default.format.printf(formatter));
|
|
259
259
|
if (transport.sysLogType) {
|
|
260
260
|
transport.type = transport.sysLogType;
|
|
261
261
|
delete transport.sysLogType;
|
|
262
|
-
}
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
263
264
|
delete transport.type;
|
|
264
265
|
}
|
|
265
266
|
try {
|
|
266
267
|
options.transports.push(new IoSysLog(transport));
|
|
267
|
-
}
|
|
268
|
+
}
|
|
269
|
+
catch (err) {
|
|
268
270
|
console.log(`Cannot activate Syslog: ${err.message}`);
|
|
269
271
|
}
|
|
270
|
-
}
|
|
272
|
+
}
|
|
273
|
+
else if (transport.type === 'http' && transport.enabled !== false) {
|
|
271
274
|
// host: (Default: localhost) Remote host of the HTTP logging endpoint
|
|
272
275
|
// port: (Default: 80 or 443) Remote port of the HTTP logging endpoint
|
|
273
276
|
// path: (Default: /) Remote URI of the HTTP logging endpoint
|
|
274
277
|
// auth: (Default: None) An object representing the username and password for HTTP Basic Auth
|
|
275
278
|
// ssl: (Default: false) Value indicating if we should use HTTPS
|
|
276
|
-
|
|
277
279
|
// If no name defined, use hostname as name
|
|
278
280
|
transport.host = transport.host || 'localhost';
|
|
279
|
-
|
|
280
281
|
try {
|
|
281
|
-
options.transports.push(new
|
|
282
|
-
}
|
|
282
|
+
options.transports.push(new winston_1.default.transports.Http(transport));
|
|
283
|
+
}
|
|
284
|
+
catch (err) {
|
|
283
285
|
console.log(`Cannot activate HTTP: ${err.message}`);
|
|
284
286
|
}
|
|
285
|
-
}
|
|
287
|
+
}
|
|
288
|
+
else if (transport.type === 'stream' && transport.enabled !== false) {
|
|
286
289
|
// stream: any Node.js stream. If an objectMode stream is provided then the entire info object will be written. Otherwise info[MESSAGE] will be written.
|
|
287
290
|
// level: Level of messages that this transport should log (default: level set on parent logger).
|
|
288
291
|
// silent: Boolean flag indicating whether to suppress output (default false).
|
|
289
292
|
// eol: Line-ending character to use. (default: os.EOL).
|
|
290
|
-
|
|
291
293
|
// If no name defined, use hostname as name
|
|
292
294
|
transport.host = transport.host || 'localhost';
|
|
293
|
-
|
|
294
295
|
try {
|
|
295
296
|
if (typeof transport.stream === 'string') {
|
|
296
|
-
transport.stream =
|
|
297
|
-
transport.stream.on('error', err => {
|
|
298
|
-
console.log(`Error in Stream: ${err}`);
|
|
297
|
+
transport.stream = fs_1.default.createWriteStream(transport.stream);
|
|
298
|
+
transport.stream.on('error', (err) => {
|
|
299
|
+
console.log(`Error in Stream: ${err.message}`);
|
|
299
300
|
});
|
|
300
301
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
console.log(`Cannot activate Stream: ${err}`);
|
|
302
|
+
options.transports.push(new winston_1.default.transports.Stream(transport));
|
|
303
|
+
}
|
|
304
|
+
catch (err) {
|
|
305
|
+
console.log(`Cannot activate Stream: ${err.message}`);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
else if (transport.type === 'seq' && transport.enabled !== false) {
|
|
309
|
+
if (!IoSeq) {
|
|
310
|
+
console.error('Seq configured, but not installed! Ignore');
|
|
311
|
+
return;
|
|
305
312
|
}
|
|
306
|
-
} else if (transport.type === 'seq' && transport.enabled !== false) {
|
|
307
313
|
// serverUrl?: string;
|
|
308
314
|
// apiKey?: string;
|
|
309
315
|
// maxBatchingTime?: number;
|
|
310
316
|
// eventSizeLimit?: number;
|
|
311
317
|
// batchSizeLimit?: number;
|
|
312
|
-
|
|
313
318
|
// Add only if serverUrl is configured at least
|
|
314
319
|
if (transport.serverUrl) {
|
|
315
320
|
try {
|
|
316
|
-
transport.onError = e => {
|
|
317
|
-
console.log(`SEQ error: ${e}`);
|
|
321
|
+
transport.onError = (e) => {
|
|
322
|
+
console.log(`SEQ error: ${e.message}`);
|
|
318
323
|
};
|
|
319
324
|
const seqLogger = new IoSeq(transport);
|
|
320
325
|
options.transports.push(seqLogger);
|
|
321
|
-
}
|
|
326
|
+
}
|
|
327
|
+
catch (err) {
|
|
322
328
|
console.log(`Cannot activate SEQ: ${err.message}`);
|
|
323
329
|
}
|
|
324
|
-
}
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
325
332
|
console.log('Cannot activate SEQ: No serverUrl specified');
|
|
326
333
|
}
|
|
327
334
|
}
|
|
328
335
|
});
|
|
329
336
|
}
|
|
330
|
-
}
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
331
339
|
for (let i = 0; i < files.length; i++) {
|
|
332
340
|
const opt = {
|
|
333
341
|
name: i ? 'dailyRotateFile' + i : tools.appName,
|
|
334
|
-
filename:
|
|
335
|
-
isNpm ? `${__dirname}/../../../log/${files[i]}` : `${__dirname}/../log/${files[i]}`
|
|
336
|
-
),
|
|
342
|
+
filename: path_1.default.normalize(isNpm ? `${__dirname}/../../../log/${files[i]}` : `${__dirname}/../log/${files[i]}`),
|
|
337
343
|
extension: '.log',
|
|
338
344
|
datePattern: 'YYYY-MM-DD',
|
|
339
345
|
//json: false, // If true, messages will be logged as JSON (default true). TODO format.json()
|
|
@@ -346,80 +352,82 @@ const logger = function (level, files, noStdout, prefix) {
|
|
|
346
352
|
handleExceptions: false
|
|
347
353
|
//maxSize: defaultMaxSize
|
|
348
354
|
};
|
|
349
|
-
|
|
350
|
-
options.transports.push(new DailyRotateFile(opt));
|
|
355
|
+
options.transports.push(new winston_daily_rotate_file_1.default(opt));
|
|
351
356
|
}
|
|
352
357
|
}
|
|
353
|
-
|
|
354
358
|
if (!noStdout) {
|
|
355
|
-
options.transports.push(
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
})
|
|
364
|
-
);
|
|
359
|
+
options.transports.push(new winston_1.default.transports.Console({
|
|
360
|
+
level,
|
|
361
|
+
silent: false,
|
|
362
|
+
format: winston_1.default.format.combine(winston_1.default.format.printf(formatter))
|
|
363
|
+
//colorize: (userOptions.colorize === undefined) ? true : userOptions.colorize, // TODO format.colorize()
|
|
364
|
+
//timestamp: timestamp, // TODO: format.timestamp()
|
|
365
|
+
//label: prefix || '' // TODO format.label()
|
|
366
|
+
}));
|
|
365
367
|
}
|
|
366
|
-
|
|
367
368
|
// Must be registered, for adapter.js notification about new logs
|
|
368
|
-
options.transports.push(
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
const log = winston.createLogger(options);
|
|
376
|
-
|
|
369
|
+
options.transports.push(new NotifierTransport({
|
|
370
|
+
level,
|
|
371
|
+
silent: false
|
|
372
|
+
}));
|
|
373
|
+
const log = winston_1.default.createLogger(options);
|
|
374
|
+
/** @ts-expect-error why do we override/add method to foreign instance? TODO */
|
|
377
375
|
log.getFileName = function () {
|
|
376
|
+
/** @ts-expect-error we use undocumented stuff here TODO */
|
|
378
377
|
let transport = this.transports.find(t => (t.transport && t.transport.dirname) || t.dirname);
|
|
379
378
|
if (transport) {
|
|
379
|
+
/** @ts-expect-error we use undocumented stuff here TODO */
|
|
380
380
|
transport = transport.transport ? transport.transport : transport;
|
|
381
|
+
/** @ts-expect-error we use undocumented stuff here TODO */
|
|
381
382
|
return transport.dirname + '/' + transport.filename.replace('%DATE%', getDate());
|
|
382
|
-
}
|
|
383
|
+
}
|
|
384
|
+
else {
|
|
383
385
|
return '';
|
|
384
386
|
}
|
|
385
387
|
};
|
|
386
|
-
|
|
387
388
|
log.on('error', error => {
|
|
388
389
|
console.log('Logger error: ' + error);
|
|
389
390
|
});
|
|
390
|
-
|
|
391
391
|
// This cannot be deleted, because file rotate works with the size of files and not with the time
|
|
392
392
|
// TODO research and open new issue in winston-daily-rotate-file repo
|
|
393
|
+
/** @ts-expect-error why do we override/add method to foreign instance? TODO */
|
|
393
394
|
log.activateDateChecker = function (isEnabled, daysCount) {
|
|
395
|
+
/** @ts-expect-error we use undocumented stuff here TODO */
|
|
394
396
|
if (!isEnabled && this._fileChecker) {
|
|
397
|
+
/** @ts-expect-error we use undocumented stuff here TODO */
|
|
395
398
|
clearInterval(this._fileChecker);
|
|
396
|
-
|
|
399
|
+
/** @ts-expect-error we use undocumented stuff here TODO */
|
|
400
|
+
}
|
|
401
|
+
else if (isEnabled && !this._fileChecker) {
|
|
397
402
|
if (!daysCount) {
|
|
398
403
|
daysCount = 3;
|
|
399
404
|
}
|
|
400
|
-
|
|
401
405
|
// Check every hour
|
|
406
|
+
/** @ts-expect-error we use undocumented stuff here TODO */
|
|
402
407
|
this._fileChecker = setInterval(() => {
|
|
403
408
|
this.transports.forEach(transport => {
|
|
404
409
|
if (
|
|
405
|
-
|
|
410
|
+
/** @ts-expect-error we use undocumented stuff here TODO */
|
|
411
|
+
transport.name !== 'dailyRotateFile' ||
|
|
412
|
+
/** @ts-expect-error we use undocumented stuff here TODO */
|
|
406
413
|
!transport.options ||
|
|
407
|
-
|
|
408
|
-
|
|
414
|
+
/** @ts-expect-error we use undocumented stuff here TODO */
|
|
415
|
+
transport.options.name !== tools.appName) {
|
|
409
416
|
return;
|
|
410
417
|
}
|
|
411
|
-
|
|
412
|
-
if (transport &&
|
|
418
|
+
/** @ts-expect-error we use undocumented stuff here TODO */
|
|
419
|
+
if (transport && fs_1.default.existsSync(transport.dirname)) {
|
|
413
420
|
let files;
|
|
414
421
|
try {
|
|
415
|
-
|
|
416
|
-
|
|
422
|
+
/** @ts-expect-error we use undocumented stuff here TODO */
|
|
423
|
+
files = fs_1.default.readdirSync(transport.dirname);
|
|
424
|
+
}
|
|
425
|
+
catch (err) {
|
|
417
426
|
console.log(`host.${hostname} Cannot read log directory: ${err}`);
|
|
418
427
|
return;
|
|
419
428
|
}
|
|
420
429
|
const forXdays = new Date();
|
|
421
430
|
forXdays.setDate(forXdays.getDate() - daysCount - 1); // normally winston now takes care, for old or on errors make sure fallback works a day later
|
|
422
|
-
|
|
423
431
|
for (let i = 0; i < files.length; i++) {
|
|
424
432
|
const match = files[i].match(/.+\.(\d+-\d+-\d+)/);
|
|
425
433
|
if (match) {
|
|
@@ -432,20 +440,20 @@ const logger = function (level, files, noStdout, prefix) {
|
|
|
432
440
|
message: `host.${hostname} Delete log file ${files[i]}`
|
|
433
441
|
});
|
|
434
442
|
console.log(`host.${hostname} Delete log file ${files[i]}`);
|
|
435
|
-
|
|
436
|
-
|
|
443
|
+
/** @ts-expect-error we use undocumented stuff here TODO */
|
|
444
|
+
fs_1.default.unlinkSync(transport.dirname + '/' + files[i]);
|
|
445
|
+
}
|
|
446
|
+
catch (e) {
|
|
437
447
|
// there is a bug under windows, that file stays opened and cannot be deleted
|
|
438
448
|
this.log({
|
|
439
|
-
level:
|
|
440
|
-
message: `host.${hostname} Cannot delete file "${
|
|
441
|
-
|
|
442
|
-
)}": ${e}`
|
|
449
|
+
level: os_1.default.platform().startsWith('win') ? 'info' : 'error',
|
|
450
|
+
message: `host.${hostname} Cannot delete file "${path_1.default.normalize(
|
|
451
|
+
/** @ts-expect-error we use undocumented stuff here TODO */
|
|
452
|
+
transport.dirname + '/' + files[i])}": ${e}`
|
|
443
453
|
});
|
|
444
|
-
console.log(
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
)}": ${e}`
|
|
448
|
-
);
|
|
454
|
+
console.log(`host.${hostname} Cannot delete file "${path_1.default.normalize(
|
|
455
|
+
/** @ts-expect-error we use undocumented stuff here TODO */
|
|
456
|
+
transport.dirname + '/' + files[i])}": ${e.message}`);
|
|
449
457
|
}
|
|
450
458
|
}
|
|
451
459
|
}
|
|
@@ -455,23 +463,19 @@ const logger = function (level, files, noStdout, prefix) {
|
|
|
455
463
|
}, 3600000); // every hour
|
|
456
464
|
}
|
|
457
465
|
};
|
|
458
|
-
|
|
459
466
|
//winston.unhandleExceptions();
|
|
460
467
|
//log.unexceptions.handle();
|
|
461
|
-
|
|
462
468
|
return log;
|
|
463
|
-
}
|
|
464
|
-
|
|
469
|
+
}
|
|
470
|
+
exports.logger = logger;
|
|
465
471
|
function getDate() {
|
|
466
472
|
const ts = new Date();
|
|
467
473
|
let result = ts.getFullYear() + '-';
|
|
468
|
-
/** @type {number | string} */
|
|
469
474
|
let value = ts.getMonth() + 1;
|
|
470
475
|
if (value < 10) {
|
|
471
476
|
value = '0' + value;
|
|
472
477
|
}
|
|
473
478
|
result += value + '-';
|
|
474
|
-
|
|
475
479
|
value = ts.getDate();
|
|
476
480
|
if (value < 10) {
|
|
477
481
|
value = '0' + value;
|
|
@@ -479,52 +483,42 @@ function getDate() {
|
|
|
479
483
|
result += value;
|
|
480
484
|
return result;
|
|
481
485
|
}
|
|
482
|
-
|
|
483
486
|
function timestamp(date) {
|
|
484
487
|
const ts = date ? new Date(date) : new Date();
|
|
485
488
|
let result = ts.getFullYear() + '-';
|
|
486
|
-
|
|
487
|
-
/** @type {number | string} */
|
|
488
489
|
let value = ts.getMonth() + 1;
|
|
489
490
|
if (value < 10) {
|
|
490
491
|
value = '0' + value;
|
|
491
492
|
}
|
|
492
493
|
result += value + '-';
|
|
493
|
-
|
|
494
494
|
value = ts.getDate();
|
|
495
495
|
if (value < 10) {
|
|
496
496
|
value = '0' + value;
|
|
497
497
|
}
|
|
498
498
|
result += value + ' ';
|
|
499
|
-
|
|
500
499
|
value = ts.getHours();
|
|
501
500
|
if (value < 10) {
|
|
502
501
|
value = '0' + value;
|
|
503
502
|
}
|
|
504
503
|
result += value + ':';
|
|
505
|
-
|
|
506
504
|
value = ts.getMinutes();
|
|
507
505
|
if (value < 10) {
|
|
508
506
|
value = '0' + value;
|
|
509
507
|
}
|
|
510
508
|
result += value + ':';
|
|
511
|
-
|
|
512
509
|
value = ts.getSeconds();
|
|
513
510
|
if (value < 10) {
|
|
514
511
|
value = '0' + value;
|
|
515
512
|
}
|
|
516
513
|
result += value + '.';
|
|
517
|
-
|
|
518
514
|
value = ts.getMilliseconds();
|
|
519
515
|
if (value < 10) {
|
|
520
516
|
value = '00' + value;
|
|
521
|
-
}
|
|
517
|
+
}
|
|
518
|
+
else if (value < 100) {
|
|
522
519
|
value = '0' + value;
|
|
523
520
|
}
|
|
524
|
-
|
|
525
521
|
result += value + ' ';
|
|
526
|
-
|
|
527
522
|
return result;
|
|
528
523
|
}
|
|
529
|
-
|
|
530
|
-
module.exports = logger;
|
|
524
|
+
//# sourceMappingURL=logger.js.map
|