@hazeljs/core 0.2.0-beta.49 → 0.2.0-beta.51
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/README.md +12 -0
- package/dist/container.js +4 -4
- package/dist/hazel-app.d.ts.map +1 -1
- package/dist/hazel-app.js +23 -17
- package/dist/health.js +1 -1
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +15 -12
- package/dist/router.js +3 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -484,6 +484,18 @@ describe('UserController', () => {
|
|
|
484
484
|
});
|
|
485
485
|
```
|
|
486
486
|
|
|
487
|
+
## Logging
|
|
488
|
+
|
|
489
|
+
HTTP requests are logged in following format: `METHOD path status duration` (e.g. `GET /api/health 200 3ms`).
|
|
490
|
+
|
|
491
|
+
| Env var | Default | Description |
|
|
492
|
+
|---------|---------|-------------|
|
|
493
|
+
| `LOG_LEVEL` | `info` | Log level (error, warn, info, debug) |
|
|
494
|
+
| `LOG_HTTP` | `true` | Set to `false` to disable HTTP request logs |
|
|
495
|
+
| `LOG_ENABLED` | `true` | Set to `false` to disable all logging |
|
|
496
|
+
|
|
497
|
+
Startup and registration logs (controllers, routes, providers) are at `debug` level. Use `LOG_LEVEL=debug` for troubleshooting.
|
|
498
|
+
|
|
487
499
|
## API Reference
|
|
488
500
|
|
|
489
501
|
### Decorators
|
package/dist/container.js
CHANGED
|
@@ -17,7 +17,7 @@ class Container {
|
|
|
17
17
|
constructor() {
|
|
18
18
|
this.providers = new Map();
|
|
19
19
|
this.requestScopedProviders = new Map();
|
|
20
|
-
logger_1.default.
|
|
20
|
+
logger_1.default.debug('Container initialized');
|
|
21
21
|
}
|
|
22
22
|
static getInstance() {
|
|
23
23
|
if (!Container.instance) {
|
|
@@ -36,7 +36,7 @@ class Container {
|
|
|
36
36
|
*/
|
|
37
37
|
register(token, provider, scope = Scope.SINGLETON) {
|
|
38
38
|
const tokenName = this.getTokenName(token);
|
|
39
|
-
logger_1.default.
|
|
39
|
+
logger_1.default.debug(`Registering provider: ${tokenName} with scope: ${scope}`);
|
|
40
40
|
if (this.isProvider(provider)) {
|
|
41
41
|
this.registerProvider(provider);
|
|
42
42
|
}
|
|
@@ -216,7 +216,7 @@ class Container {
|
|
|
216
216
|
// Create instance with dependencies
|
|
217
217
|
const instance = new token(...dependencies);
|
|
218
218
|
if (logger_1.default.isDebugEnabled()) {
|
|
219
|
-
logger_1.default.
|
|
219
|
+
logger_1.default.debug(`Created instance of: ${this.getTokenName(token)}`);
|
|
220
220
|
}
|
|
221
221
|
return instance;
|
|
222
222
|
}
|
|
@@ -233,7 +233,7 @@ class Container {
|
|
|
233
233
|
* Clear all providers
|
|
234
234
|
*/
|
|
235
235
|
clear() {
|
|
236
|
-
logger_1.default.
|
|
236
|
+
logger_1.default.debug('Clearing container');
|
|
237
237
|
this.providers.clear();
|
|
238
238
|
this.requestScopedProviders.clear();
|
|
239
239
|
}
|
package/dist/hazel-app.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hazel-app.d.ts","sourceRoot":"","sources":["../src/hazel-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,OAAO,EAAU,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAE/D,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAI5D,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAuB,MAAM,UAAU,CAAC;AACnE,OAAO,EAAqB,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACpF,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC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B,GAAG,IAAI;IAK9D;;;OAGG;IACH,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI;CAIjE"}
|
package/dist/hazel-app.js
CHANGED
|
@@ -71,7 +71,7 @@ class HazelApp {
|
|
|
71
71
|
this.corsEnabled = false;
|
|
72
72
|
this.earlyHandlers = [];
|
|
73
73
|
this.proxyHandlers = [];
|
|
74
|
-
logger_1.default.
|
|
74
|
+
logger_1.default.debug('Initializing HazelApp');
|
|
75
75
|
this.container = container_1.Container.getInstance();
|
|
76
76
|
this.container.register(HazelApp, this);
|
|
77
77
|
this.router = new router_1.Router(this.container);
|
|
@@ -85,14 +85,14 @@ class HazelApp {
|
|
|
85
85
|
this.initialize();
|
|
86
86
|
}
|
|
87
87
|
initialize() {
|
|
88
|
-
logger_1.default.
|
|
88
|
+
logger_1.default.debug('Initializing module:', { moduleName: this.moduleType.name });
|
|
89
89
|
const metadata = Reflect.getMetadata(MODULE_METADATA_KEY, this.moduleType) || {};
|
|
90
90
|
logger_1.default.debug('Module metadata:', metadata);
|
|
91
91
|
// Collect all controllers from the module tree (root + imports, recursively)
|
|
92
92
|
const allControllers = this.collectControllers(this.moduleType);
|
|
93
93
|
// Register all controllers with the router
|
|
94
94
|
if (allControllers.length > 0) {
|
|
95
|
-
logger_1.default.
|
|
95
|
+
logger_1.default.debug('Registering controllers:', {
|
|
96
96
|
controllers: allControllers.map((c) => c.name),
|
|
97
97
|
});
|
|
98
98
|
allControllers.forEach((controller) => {
|
|
@@ -142,6 +142,18 @@ class HazelApp {
|
|
|
142
142
|
async listen(port) {
|
|
143
143
|
return new Promise((resolve) => {
|
|
144
144
|
this.server = new http_1.Server(async (req, res) => {
|
|
145
|
+
const startTime = Date.now();
|
|
146
|
+
const method = req.method || 'GET';
|
|
147
|
+
const url = req.url || '/';
|
|
148
|
+
const path = url.split('?')[0];
|
|
149
|
+
res.once('finish', () => {
|
|
150
|
+
if (process.env.LOG_HTTP === 'false')
|
|
151
|
+
return;
|
|
152
|
+
const duration = Date.now() - startTime;
|
|
153
|
+
const status = res.statusCode || 0;
|
|
154
|
+
const statusColor = status >= 500 ? chalk_1.default.red : status >= 400 ? chalk_1.default.yellow : chalk_1.default.green;
|
|
155
|
+
logger_1.default.info(`${chalk_1.default.bold(method)} ${path} ${statusColor(String(status))} ${chalk_1.default.gray(duration + 'ms')}`);
|
|
156
|
+
});
|
|
145
157
|
try {
|
|
146
158
|
if (!req.url) {
|
|
147
159
|
logger_1.default.warn('Invalid URL received');
|
|
@@ -342,9 +354,9 @@ class HazelApp {
|
|
|
342
354
|
this.shutdownManager.registerHandler({
|
|
343
355
|
name: 'http-server',
|
|
344
356
|
handler: async () => {
|
|
345
|
-
logger_1.default.
|
|
357
|
+
logger_1.default.debug('Closing HTTP server...');
|
|
346
358
|
await this.close();
|
|
347
|
-
logger_1.default.
|
|
359
|
+
logger_1.default.debug('HTTP server closed');
|
|
348
360
|
},
|
|
349
361
|
timeout: 10000,
|
|
350
362
|
});
|
|
@@ -367,9 +379,8 @@ class HazelApp {
|
|
|
367
379
|
}
|
|
368
380
|
catch (error) {
|
|
369
381
|
const httpError = error;
|
|
370
|
-
logger_1.default.error(`[${req.method}] ${req.url} - Route matching error: ${httpError.message} (status: ${httpError.statusCode || 404})`);
|
|
371
382
|
if (process.env.NODE_ENV === 'development' && httpError.stack) {
|
|
372
|
-
logger_1.default.debug(httpError.stack);
|
|
383
|
+
logger_1.default.debug(`Route not found: ${req.method} ${req.url}`, httpError.stack);
|
|
373
384
|
}
|
|
374
385
|
const status = httpError.statusCode || 404;
|
|
375
386
|
res.writeHead(status, { 'Content-Type': 'application/json' });
|
|
@@ -379,11 +390,6 @@ class HazelApp {
|
|
|
379
390
|
}));
|
|
380
391
|
return;
|
|
381
392
|
}
|
|
382
|
-
logger_1.default.info('Matched route:', {
|
|
383
|
-
method: req.method,
|
|
384
|
-
url: req.url,
|
|
385
|
-
params: context.params,
|
|
386
|
-
});
|
|
387
393
|
try {
|
|
388
394
|
const response = new HttpResponse(res);
|
|
389
395
|
const result = await route.handler(req, response);
|
|
@@ -444,7 +450,7 @@ class HazelApp {
|
|
|
444
450
|
setRequestTimeout(timeout, options) {
|
|
445
451
|
this.requestTimeout = timeout;
|
|
446
452
|
this.timeoutMiddleware = new timeout_middleware_1.TimeoutMiddleware({ ...options, timeout });
|
|
447
|
-
logger_1.default.
|
|
453
|
+
logger_1.default.debug(`Request timeout set to ${timeout}ms`);
|
|
448
454
|
}
|
|
449
455
|
/**
|
|
450
456
|
* Enable CORS
|
|
@@ -452,7 +458,7 @@ class HazelApp {
|
|
|
452
458
|
enableCors(options) {
|
|
453
459
|
this.corsEnabled = true;
|
|
454
460
|
this.corsOptions = options;
|
|
455
|
-
logger_1.default.
|
|
461
|
+
logger_1.default.debug('CORS enabled', options);
|
|
456
462
|
}
|
|
457
463
|
/**
|
|
458
464
|
* Disable CORS
|
|
@@ -460,7 +466,7 @@ class HazelApp {
|
|
|
460
466
|
disableCors() {
|
|
461
467
|
this.corsEnabled = false;
|
|
462
468
|
this.corsOptions = undefined;
|
|
463
|
-
logger_1.default.
|
|
469
|
+
logger_1.default.debug('CORS disabled');
|
|
464
470
|
}
|
|
465
471
|
/**
|
|
466
472
|
* Get health check manager
|
|
@@ -485,7 +491,7 @@ class HazelApp {
|
|
|
485
491
|
*/
|
|
486
492
|
addEarlyHandler(path, handler) {
|
|
487
493
|
this.earlyHandlers.push({ path, handler });
|
|
488
|
-
logger_1.default.
|
|
494
|
+
logger_1.default.debug('Early handler registered', { path });
|
|
489
495
|
}
|
|
490
496
|
/**
|
|
491
497
|
* Add a proxy handler (runs after body parsing, before router).
|
|
@@ -493,7 +499,7 @@ class HazelApp {
|
|
|
493
499
|
*/
|
|
494
500
|
addProxyHandler(pathPrefix, handler) {
|
|
495
501
|
this.proxyHandlers.push({ pathPrefix, handler });
|
|
496
|
-
logger_1.default.
|
|
502
|
+
logger_1.default.debug('Proxy handler registered', { pathPrefix });
|
|
497
503
|
}
|
|
498
504
|
}
|
|
499
505
|
exports.HazelApp = HazelApp;
|
package/dist/health.js
CHANGED
|
@@ -19,7 +19,7 @@ class HealthCheckManager {
|
|
|
19
19
|
*/
|
|
20
20
|
registerCheck(check) {
|
|
21
21
|
this.checks.set(check.name, check);
|
|
22
|
-
logger_1.default.
|
|
22
|
+
logger_1.default.debug(`Registered health check: ${check.name}`);
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
25
|
* Run all health checks
|
package/dist/logger.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAK9B,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAK9B,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAwQvD,eAAO,MAAM,aAAa,GACxB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,MAAM,MAAM,IAAI,KACf,IAuBF,CAAC;AAQF,QAAA,MAAM,cAAc;0BALO,OAAO;CAOhC,CAAC;AAGH,eAAe,cAAc,CAAC"}
|
package/dist/logger.js
CHANGED
|
@@ -69,15 +69,16 @@ const getCategoryColor = (message) => {
|
|
|
69
69
|
return chalk_1.default.white;
|
|
70
70
|
};
|
|
71
71
|
// Custom format for better readability with enhanced colors
|
|
72
|
-
const customFormat = winston_1.default.format.printf((
|
|
72
|
+
const customFormat = winston_1.default.format.printf((info) => {
|
|
73
|
+
const { level, message, timestamp, ...metadata } = info;
|
|
73
74
|
// Get the appropriate color for the log level
|
|
74
75
|
const levelColor = colors[level] || chalk_1.default.white;
|
|
75
76
|
// Format the timestamp with subtle color
|
|
76
|
-
const time = chalk_1.default.gray.dim(timestamp);
|
|
77
|
+
const time = chalk_1.default.gray.dim(String(timestamp ?? ''));
|
|
77
78
|
// Format the level with color and padding (no icons for professional look)
|
|
78
|
-
const levelStr = levelColor.bold(`[${level.toUpperCase()}]`.padEnd(9));
|
|
79
|
+
const levelStr = levelColor.bold(`[${String(level).toUpperCase()}]`.padEnd(9));
|
|
79
80
|
// Convert message to string
|
|
80
|
-
const messageStr = String(message);
|
|
81
|
+
const messageStr = String(message ?? '');
|
|
81
82
|
// Detect category and apply appropriate color to message
|
|
82
83
|
const categoryColor = getCategoryColor(messageStr);
|
|
83
84
|
let msg = categoryColor(messageStr);
|
|
@@ -173,8 +174,9 @@ if (logEnabled) {
|
|
|
173
174
|
if (logDir) {
|
|
174
175
|
transports.push(new winston_1.default.transports.File({
|
|
175
176
|
filename: path_1.default.join(logDir, 'combined.log'),
|
|
176
|
-
format: winston_1.default.format.combine(winston_1.default.format.timestamp(), winston_1.default.format.printf((
|
|
177
|
-
|
|
177
|
+
format: winston_1.default.format.combine(winston_1.default.format.timestamp(), winston_1.default.format.printf((info) => {
|
|
178
|
+
const { level, message, timestamp, ...metadata } = info;
|
|
179
|
+
let msg = `${timestamp} [${String(level).toUpperCase()}] ${message}`;
|
|
178
180
|
if (Object.keys(metadata).length > 0) {
|
|
179
181
|
msg += ` | ${JSON.stringify(metadata, (key, val) => {
|
|
180
182
|
if (key === 'socket' || key === 'parser' || key === 'res' || key === 'req') {
|
|
@@ -188,8 +190,9 @@ if (logEnabled) {
|
|
|
188
190
|
}), new winston_1.default.transports.File({
|
|
189
191
|
filename: path_1.default.join(logDir, 'error.log'),
|
|
190
192
|
level: 'error',
|
|
191
|
-
format: winston_1.default.format.combine(winston_1.default.format.timestamp(), winston_1.default.format.printf((
|
|
192
|
-
|
|
193
|
+
format: winston_1.default.format.combine(winston_1.default.format.timestamp(), winston_1.default.format.printf((info) => {
|
|
194
|
+
const { level, message, timestamp, ...metadata } = info;
|
|
195
|
+
let msg = `${timestamp} [${String(level).toUpperCase()}] ${message}`;
|
|
193
196
|
if (Object.keys(metadata).length > 0) {
|
|
194
197
|
msg += ` | ${JSON.stringify(metadata, (key, val) => {
|
|
195
198
|
if (key === 'socket' || key === 'parser' || key === 'res' || key === 'req') {
|
|
@@ -233,11 +236,11 @@ const requestLogger = (req, res, next) => {
|
|
|
233
236
|
: res.statusCode >= 200
|
|
234
237
|
? chalk_1.default.green
|
|
235
238
|
: chalk_1.default.white;
|
|
236
|
-
logger.info(`${chalk_1.default.bold(req.method)} ${req.url}`, {
|
|
237
|
-
status: statusColor(res.statusCode),
|
|
239
|
+
logger.info(`${chalk_1.default.bold(req.method ?? '')} ${req.url ?? ''}`, {
|
|
240
|
+
status: statusColor(String(res.statusCode)),
|
|
238
241
|
duration: chalk_1.default.yellow(`${duration}ms`),
|
|
239
|
-
userAgent: chalk_1.default.gray(req.headers['user-agent']),
|
|
240
|
-
ip: chalk_1.default.gray(req.socket.remoteAddress),
|
|
242
|
+
userAgent: chalk_1.default.gray(String(req.headers['user-agent'] ?? '')),
|
|
243
|
+
ip: chalk_1.default.gray(String(req.socket.remoteAddress ?? '')),
|
|
241
244
|
});
|
|
242
245
|
});
|
|
243
246
|
next();
|
package/dist/router.js
CHANGED
|
@@ -31,7 +31,7 @@ class Router {
|
|
|
31
31
|
this.routesByMethod.set('PATCH', new Map());
|
|
32
32
|
}
|
|
33
33
|
registerController(controller) {
|
|
34
|
-
logger_1.default.
|
|
34
|
+
logger_1.default.debug(`Registering controller: ${controller.name}`);
|
|
35
35
|
const controllerMetadata = Reflect.getMetadata(CONTROLLER_METADATA_KEY, controller) || {};
|
|
36
36
|
const routes = Reflect.getMetadata(ROUTE_METADATA_KEY, controller) || [];
|
|
37
37
|
logger_1.default.debug('Controller metadata:', controllerMetadata);
|
|
@@ -41,7 +41,7 @@ class Router {
|
|
|
41
41
|
const basePath = controllerMetadata.path || '';
|
|
42
42
|
const routePath = path || '';
|
|
43
43
|
const fullPath = this.normalizePath(`${basePath}${routePath}`);
|
|
44
|
-
logger_1.default.
|
|
44
|
+
logger_1.default.debug(`Registering route: ${method} ${fullPath} (handler: ${String(propertyKey)})`);
|
|
45
45
|
// Get parameter types from TypeScript metadata
|
|
46
46
|
const paramTypes = Reflect.getMetadata('design:paramtypes', controller.prototype, propertyKey) || [];
|
|
47
47
|
logger_1.default.debug('Parameter types:', paramTypes.map((t) => t?.name || 'undefined'));
|
|
@@ -436,7 +436,7 @@ class Router {
|
|
|
436
436
|
// Match the request method and URL
|
|
437
437
|
const match = await this.match(req.method || 'GET', req.url || '/', context);
|
|
438
438
|
if (!match) {
|
|
439
|
-
logger_1.default.
|
|
439
|
+
logger_1.default.debug(`No route found for ${req.method} ${req.url}`);
|
|
440
440
|
res.status(404).json({ error: 'Not Found' });
|
|
441
441
|
return;
|
|
442
442
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hazeljs/core",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.51",
|
|
4
4
|
"description": "Core HazelJS framework - Dependency injection, routing, decorators, and base functionality",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"url": "https://github.com/hazeljs/hazel-js/issues"
|
|
64
64
|
},
|
|
65
65
|
"homepage": "https://hazeljs.com",
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "fcb2b1ac29131c222d5e529aa3ca41a4f9a54725"
|
|
67
67
|
}
|