evaengine 1.0.10 → 1.0.12
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 +1 -1
- package/src/engine.js +19 -17
- package/src/entities/index.js +6 -7
- package/src/middlewares/trace.js +1 -1
- package/src/middlewares/view_cache.js +1 -1
- package/src/swagger/index.js +4 -3
package/package.json
CHANGED
package/src/engine.js
CHANGED
|
@@ -113,8 +113,8 @@ export default class EvaEngine {
|
|
|
113
113
|
this.logger = logger || DI.get('logger');
|
|
114
114
|
this.config = config || DI.get('config');
|
|
115
115
|
this.namespace = namespace || DI.get('namespace');
|
|
116
|
-
this.logger.info('Engine started, Meta:', this.meta);
|
|
117
|
-
this.logger.debug('Engine config files loaded:', this.config.getMergedFiles());
|
|
116
|
+
this.logger.info('Engine started, Meta: %j', this.meta);
|
|
117
|
+
this.logger.debug('Engine config files loaded: %j', this.config.getMergedFiles());
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
/**
|
|
@@ -157,7 +157,7 @@ export default class EvaEngine {
|
|
|
157
157
|
throw new RuntimeException('No command registered yet');
|
|
158
158
|
}
|
|
159
159
|
this.registerServiceProviders(EvaEngine.getServiceProvidersForCLI());
|
|
160
|
-
this.logger.debug('Bound services', Object.keys(DI.getBound()));
|
|
160
|
+
this.logger.debug('Bound services %j', Object.keys(DI.getBound()));
|
|
161
161
|
const [, , commandNameFromArgv] = process.argv;
|
|
162
162
|
|
|
163
163
|
const commandName = commandNameInput || commandNameFromArgv;
|
|
@@ -281,7 +281,7 @@ export default class EvaEngine {
|
|
|
281
281
|
} else {
|
|
282
282
|
registerCommandClass(commands);
|
|
283
283
|
}
|
|
284
|
-
this.logger.debug('Registered commands', Object.keys(this.commands));
|
|
284
|
+
this.logger.debug('Registered commands %j', Object.keys(this.commands));
|
|
285
285
|
return this;
|
|
286
286
|
}
|
|
287
287
|
|
|
@@ -334,7 +334,7 @@ export default class EvaEngine {
|
|
|
334
334
|
((err, req, res, next) => { //eslint-disable-line no-unused-vars
|
|
335
335
|
let exception = err;
|
|
336
336
|
if (!(err instanceof Error)) {
|
|
337
|
-
this.logger.error(req.method, req.originalUrl || req.url,
|
|
337
|
+
this.logger.error('%s %s | %o', req.method, req.originalUrl || req.url, exception);
|
|
338
338
|
exception = (new RuntimeException('Unknown error')).setPrevError(err);
|
|
339
339
|
}
|
|
340
340
|
if (!(exception instanceof StandardException)) {
|
|
@@ -343,10 +343,12 @@ export default class EvaEngine {
|
|
|
343
343
|
if (exception instanceof RuntimeException) {
|
|
344
344
|
//TODO: report to sentry
|
|
345
345
|
//TODO: with req & res
|
|
346
|
-
this.logger.error(req.method, req.originalUrl || req.url,
|
|
346
|
+
this.logger.error('%s %s | %o', req.method, req.originalUrl || req.url, exception);
|
|
347
347
|
} else {
|
|
348
348
|
this.logger.warn(
|
|
349
|
-
|
|
349
|
+
'%s %s | %o',
|
|
350
|
+
req.method,
|
|
351
|
+
req.originalUrl || req.url,
|
|
350
352
|
exception.getImportance() > 0 ? exception : exception.message
|
|
351
353
|
);
|
|
352
354
|
}
|
|
@@ -388,7 +390,7 @@ export default class EvaEngine {
|
|
|
388
390
|
killTimer.unref();
|
|
389
391
|
this.server.close();
|
|
390
392
|
} catch (e) {
|
|
391
|
-
this.logger.error('Error when exit', e.stack);
|
|
393
|
+
this.logger.error('Error when exit %s', e.stack);
|
|
392
394
|
}
|
|
393
395
|
});
|
|
394
396
|
}
|
|
@@ -422,11 +424,11 @@ export default class EvaEngine {
|
|
|
422
424
|
// handle specific listen errors with friendly messages
|
|
423
425
|
switch (error.code) {
|
|
424
426
|
case 'EACCES':
|
|
425
|
-
this.logger.error(
|
|
427
|
+
this.logger.error('%s requires elevated privileges', bind);
|
|
426
428
|
process.exit(1);
|
|
427
429
|
break;
|
|
428
430
|
case 'EADDRINUSE':
|
|
429
|
-
this.logger.error(
|
|
431
|
+
this.logger.error('%s is already in use', bind);
|
|
430
432
|
process.exit(1);
|
|
431
433
|
break;
|
|
432
434
|
default:
|
|
@@ -441,8 +443,8 @@ export default class EvaEngine {
|
|
|
441
443
|
bootstrap() {
|
|
442
444
|
this.registerServiceProviders(EvaEngine.getServiceProvidersForWeb());
|
|
443
445
|
this.registerServiceProviders(EvaEngine.getMiddlewareProviders());
|
|
444
|
-
this.logger.info('Engine bootstrapped under env', DI.get('env').get());
|
|
445
|
-
this.logger.debug('Bound services', Object.keys(DI.getBound()));
|
|
446
|
+
this.logger.info('Engine bootstrapped under env %s', DI.get('env').get());
|
|
447
|
+
this.logger.debug('Bound services %j', Object.keys(DI.getBound()));
|
|
446
448
|
return this;
|
|
447
449
|
}
|
|
448
450
|
|
|
@@ -460,7 +462,7 @@ export default class EvaEngine {
|
|
|
460
462
|
this.server = http.createServer(EvaEngine.getApp());
|
|
461
463
|
this.server.listen(port || this.port);
|
|
462
464
|
this.server.on('error', this.getServerErrorHandler());
|
|
463
|
-
this.logger.info('Engine running http server by listening', this.port);
|
|
465
|
+
this.logger.info('Engine running http server by listening on %s', this.port);
|
|
464
466
|
return this;
|
|
465
467
|
}
|
|
466
468
|
|
|
@@ -474,7 +476,7 @@ export default class EvaEngine {
|
|
|
474
476
|
this.server = https.createServer(options, EvaEngine.getApp());
|
|
475
477
|
this.server.listen(port || this.port);
|
|
476
478
|
this.server.on('error', this.getServerErrorHandler());
|
|
477
|
-
this.logger.info('Engine running http server by listening', this.port);
|
|
479
|
+
this.logger.info('Engine running http server by listening on %s', this.port);
|
|
478
480
|
return this;
|
|
479
481
|
}
|
|
480
482
|
|
|
@@ -497,8 +499,8 @@ export default class EvaEngine {
|
|
|
497
499
|
return;
|
|
498
500
|
}
|
|
499
501
|
|
|
500
|
-
this.logger.debug('Start run command', commandName);
|
|
501
|
-
this.logger.debug('Received arguments', argv);
|
|
502
|
+
this.logger.debug('Start run command %s', commandName);
|
|
503
|
+
this.logger.debug('Received arguments %j', argv);
|
|
502
504
|
const CommandClass = this.commands[commandName];
|
|
503
505
|
this.command = new CommandClass(argv);
|
|
504
506
|
await this.command.run();
|
|
@@ -515,7 +517,7 @@ export default class EvaEngine {
|
|
|
515
517
|
throw new RuntimeException('No command registered yet');
|
|
516
518
|
}
|
|
517
519
|
this.registerServiceProviders(EvaEngine.getServiceProvidersForCLI());
|
|
518
|
-
this.logger.debug('Bound services', Object.keys(DI.getBound()));
|
|
520
|
+
this.logger.debug('Bound services %j', Object.keys(DI.getBound()));
|
|
519
521
|
//Cron jobs run in local time, matching the previous later.date.localTime() default
|
|
520
522
|
this.logger.info('Cron job using %s Timezone', 'Local');
|
|
521
523
|
const [commandName, ...options] = commandString.split(' ');
|
package/src/entities/index.js
CHANGED
|
@@ -53,22 +53,18 @@ export default class Entities {
|
|
|
53
53
|
* @returns {*}
|
|
54
54
|
*/
|
|
55
55
|
static addTracer(options = {}) {
|
|
56
|
-
const logger = DI.get('logger');
|
|
57
56
|
return Object.assign(options, {
|
|
58
57
|
benchmark: true,
|
|
59
58
|
logging: (...args) => {
|
|
60
59
|
const tracer = DI.get('namespace').get('tracer');
|
|
61
60
|
const [query, cost] = args;
|
|
62
|
-
let pushed = false;
|
|
63
61
|
if (tracer && cost > 0) {
|
|
64
62
|
tracer.queries.push({
|
|
65
63
|
query,
|
|
66
64
|
cost: cost * 1000,
|
|
67
65
|
finishedAt: getMicroTimestamp()
|
|
68
66
|
});
|
|
69
|
-
pushed = true;
|
|
70
67
|
}
|
|
71
|
-
logger.verbose(...args, !pushed ? '| Tracer' : '');
|
|
72
68
|
}
|
|
73
69
|
});
|
|
74
70
|
}
|
|
@@ -137,9 +133,13 @@ export default class Entities {
|
|
|
137
133
|
if (process.env.SEQUELIZE_REPLICATION_CONFIG_KEY) {
|
|
138
134
|
dbConfig.replication = dbConfig[process.env.SEQUELIZE_REPLICATION_CONFIG_KEY];
|
|
139
135
|
}
|
|
136
|
+
const sequelizeOptions = Object.assign({}, config.sequelize, dbConfig);
|
|
137
|
+
if (sequelizeOptions.logging !== false) {
|
|
138
|
+
Object.assign(sequelizeOptions, Entities.addTracer());
|
|
139
|
+
}
|
|
140
140
|
this.sequelize = new Sequelize(
|
|
141
141
|
config.db.database, null, null,
|
|
142
|
-
|
|
142
|
+
sequelizeOptions
|
|
143
143
|
);
|
|
144
144
|
} else {
|
|
145
145
|
this.sequelize = typeof this.sequelize === 'function' ? this.sequelize() : this.sequelize;
|
|
@@ -148,8 +148,7 @@ export default class Entities {
|
|
|
148
148
|
this.scan(this.entitiesPath, withAssociate);
|
|
149
149
|
this.scanned = true;
|
|
150
150
|
|
|
151
|
-
|
|
152
|
-
logger.debug('Entities init by scanned %s, Replication: %j', this.entitiesPath, this.sequelize.options.replication);
|
|
151
|
+
logger.debug('Entities init by scanned %s', this.entitiesPath);
|
|
153
152
|
return this;
|
|
154
153
|
}
|
|
155
154
|
|
package/src/middlewares/trace.js
CHANGED
|
@@ -232,7 +232,7 @@ function TraceMiddleware(ns, config, logger, client) {
|
|
|
232
232
|
method: 'POST',
|
|
233
233
|
json: zipkins
|
|
234
234
|
}).catch((e) => {
|
|
235
|
-
logger.error('Error happened on sending tracing data', e);
|
|
235
|
+
logger.error('Error happened on sending tracing data: %o', e);
|
|
236
236
|
});
|
|
237
237
|
};
|
|
238
238
|
|
|
@@ -113,7 +113,7 @@ function ViewCacheMiddleware(cache, logger) {
|
|
|
113
113
|
headersFilter(res) : defaultHeadersFilter(res);
|
|
114
114
|
if (res.statusCode <= 500) {
|
|
115
115
|
cache.namespace(namespace).set(cacheKey, { headers, body }, ttl).catch((e) => {
|
|
116
|
-
logger.error('View cache set failed for %s', cacheKey, e);
|
|
116
|
+
logger.error('View cache set failed for %s: %o', cacheKey, e);
|
|
117
117
|
});
|
|
118
118
|
}
|
|
119
119
|
};
|
package/src/swagger/index.js
CHANGED
|
@@ -549,14 +549,15 @@ export class ExSwagger {
|
|
|
549
549
|
);
|
|
550
550
|
Object.assign(exceptions, exceptionsInFile);
|
|
551
551
|
this.logger.debug(
|
|
552
|
-
'Scanner found %s exceptions',
|
|
553
|
-
Object.keys(exceptions).length,
|
|
552
|
+
'Scanner found %s exceptions: %j',
|
|
553
|
+
Object.keys(exceptions).length,
|
|
554
|
+
Object.keys(exceptions)
|
|
554
555
|
);
|
|
555
556
|
}
|
|
556
557
|
const modelDefinitions = this.models ?
|
|
557
558
|
ExSwagger.modelsToSwaggerDefinitions(this.models, this.modelBlacklist) : new Map();
|
|
558
559
|
const swaggerDocs = ExSwagger.mergeAll(template, fragments, exceptions, modelDefinitions);
|
|
559
|
-
this.logger.debug('Export to', dist);
|
|
560
|
+
this.logger.debug('Export to %s', dist);
|
|
560
561
|
await fs.writeFileSync(dist, JSON.stringify(swaggerDocs));
|
|
561
562
|
return swaggerDocs;
|
|
562
563
|
}
|