@emberkit/core 0.2.10 → 0.3.0
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/dist/dev-server/index.d.ts +4 -0
- package/dist/dev-server/index.d.ts.map +1 -1
- package/dist/dev-server/index.js +33 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/logger/helpers/create-logger.d.ts +12 -0
- package/dist/logger/helpers/create-logger.d.ts.map +1 -0
- package/dist/logger/helpers/create-logger.js +178 -0
- package/dist/logger/index.d.ts +10 -0
- package/dist/logger/index.d.ts.map +1 -0
- package/dist/logger/index.js +16 -0
- package/dist/logger/types.d.ts +33 -0
- package/dist/logger/types.d.ts.map +1 -0
- package/dist/logger/types.js +1 -0
- package/package.json +3 -1
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import type { Logger, LogLevel } from '../logger/types.js';
|
|
1
2
|
export interface DevServerOptions {
|
|
2
3
|
port?: number;
|
|
3
4
|
host?: string;
|
|
4
5
|
cors?: boolean;
|
|
5
6
|
hmr?: boolean;
|
|
7
|
+
logLevel?: LogLevel;
|
|
8
|
+
logger?: Logger;
|
|
6
9
|
}
|
|
7
10
|
export interface ServerStats {
|
|
8
11
|
uptime: number;
|
|
@@ -12,6 +15,7 @@ export interface ServerStats {
|
|
|
12
15
|
}
|
|
13
16
|
export declare class DevServer {
|
|
14
17
|
private errorCount;
|
|
18
|
+
private readonly logger;
|
|
15
19
|
private readonly options;
|
|
16
20
|
private requestCount;
|
|
17
21
|
private server;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dev-server/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,GAAG,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dev-server/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAG3D,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC;CACjC;AAED,qBAAa,SAAS;IACpB,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA0D;IAClF,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,MAAM,CAAsC;IACpD,OAAO,CAAC,SAAS,CAAK;gBAEV,OAAO,GAAE,gBAAqB;IAU1C,QAAQ,IAAI,WAAW;IASjB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAwBtB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAoB3B,OAAO,CAAC,oBAAoB;YAyCd,YAAY;YAeZ,aAAa;IAgC3B,OAAO,CAAC,eAAe;IAWvB,OAAO,CAAC,SAAS;CAIlB;AAED,wBAAsB,eAAe,CAAC,OAAO,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,SAAS,CAAC,CAIpF"}
|
package/dist/dev-server/index.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import { createLogger, createHttpLogger } from '../logger/index.js';
|
|
1
2
|
export class DevServer {
|
|
2
3
|
errorCount = 0;
|
|
4
|
+
logger;
|
|
3
5
|
options;
|
|
4
6
|
requestCount = 0;
|
|
5
7
|
server = null;
|
|
6
8
|
startTime = 0;
|
|
7
9
|
constructor(options = {}) {
|
|
10
|
+
this.logger = options.logger ?? createLogger({ name: '@emberkit/dev-server', level: options.logLevel ?? 'info' });
|
|
8
11
|
this.options = {
|
|
9
12
|
port: options.port ?? 3000,
|
|
10
13
|
host: options.host ?? 'localhost',
|
|
@@ -27,11 +30,14 @@ export class DevServer {
|
|
|
27
30
|
this.server = http.createServer(handler);
|
|
28
31
|
await new Promise((resolve, reject) => {
|
|
29
32
|
this.server.listen(this.options.port, this.options.host, () => {
|
|
30
|
-
|
|
33
|
+
this.logger.info(`Dev server running at http://${this.options.host}:${this.options.port}`, {
|
|
34
|
+
port: this.options.port,
|
|
35
|
+
host: this.options.host,
|
|
36
|
+
});
|
|
31
37
|
resolve();
|
|
32
38
|
});
|
|
33
39
|
this.server.on('error', (err) => {
|
|
34
|
-
|
|
40
|
+
this.logger.error('Server error', err);
|
|
35
41
|
reject(err);
|
|
36
42
|
});
|
|
37
43
|
});
|
|
@@ -44,9 +50,11 @@ export class DevServer {
|
|
|
44
50
|
}
|
|
45
51
|
this.server.close((err) => {
|
|
46
52
|
if (err) {
|
|
53
|
+
this.logger.error('Error closing server', err);
|
|
47
54
|
reject(err);
|
|
48
55
|
}
|
|
49
56
|
else {
|
|
57
|
+
this.logger.info('Dev server stopped');
|
|
50
58
|
this.server = null;
|
|
51
59
|
resolve();
|
|
52
60
|
}
|
|
@@ -54,14 +62,35 @@ export class DevServer {
|
|
|
54
62
|
});
|
|
55
63
|
}
|
|
56
64
|
createRequestHandler() {
|
|
65
|
+
const httpLogger = createHttpLogger(this.logger);
|
|
57
66
|
return async (req, res) => {
|
|
58
67
|
this.requestCount++;
|
|
68
|
+
const startTime = Date.now();
|
|
69
|
+
const method = req.method ?? 'GET';
|
|
70
|
+
const path = req.url ?? '/';
|
|
71
|
+
const logContext = {
|
|
72
|
+
method,
|
|
73
|
+
path,
|
|
74
|
+
remoteAddress: req.socket.remoteAddress,
|
|
75
|
+
userAgent: req.headers['user-agent'],
|
|
76
|
+
};
|
|
59
77
|
try {
|
|
60
78
|
await this.handleRequest(req, res);
|
|
79
|
+
const responseTime = Date.now() - startTime;
|
|
80
|
+
this.logger.debug(`${method} ${path}`, {
|
|
81
|
+
...logContext,
|
|
82
|
+
statusCode: res.statusCode,
|
|
83
|
+
responseTime,
|
|
84
|
+
});
|
|
61
85
|
}
|
|
62
86
|
catch (error) {
|
|
63
87
|
this.errorCount++;
|
|
64
|
-
|
|
88
|
+
const responseTime = Date.now() - startTime;
|
|
89
|
+
this.logger.error(`${method} ${path} - Error`, {
|
|
90
|
+
...logContext,
|
|
91
|
+
responseTime,
|
|
92
|
+
error: error instanceof Error ? error.message : String(error),
|
|
93
|
+
});
|
|
65
94
|
this.sendError(res, 500, 'Internal Server Error');
|
|
66
95
|
}
|
|
67
96
|
};
|
|
@@ -83,6 +112,7 @@ export class DevServer {
|
|
|
83
112
|
async handleRequest(req, res) {
|
|
84
113
|
const url = new URL(req.url ?? '/', `http://${req.headers.host}`);
|
|
85
114
|
if (url.pathname === '/__emberkit_hmr') {
|
|
115
|
+
this.logger.trace('HMR request', { pathname: url.pathname });
|
|
86
116
|
this.handleWebSocket(req, res);
|
|
87
117
|
return;
|
|
88
118
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -16,5 +16,7 @@ export type { HeadProps } from './meta/index.js';
|
|
|
16
16
|
export { generateMeta, generateBreadcrumbs, generateArticleSchema, generateProductSchema, } from './meta/index.js';
|
|
17
17
|
export type { MetaData, OpenGraphData, TwitterCardData } from './meta/index.js';
|
|
18
18
|
export type { FC, RouteComponent, RouteChildren } from './runtime/types.js';
|
|
19
|
+
export { createLogger, createHttpLogger } from './logger/index.js';
|
|
20
|
+
export type { Logger, LoggerOptions, LogLevel, RequestLog, ResponseLog } from './logger/index.js';
|
|
19
21
|
export declare function defineConfig(config: Record<string, unknown>): Record<string, unknown>;
|
|
20
22
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,UAAU,CAAC;AAE/B,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,EACL,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,KAAK,EACL,OAAO,EACP,MAAM,EACN,QAAQ,EACR,MAAM,GACP,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,KAAK,YAAY,EAAE,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC7F,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AACnF,YAAY,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC1E,YAAY,EAAE,MAAM,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACjF,OAAO,EACL,oBAAoB,EACpB,aAAa,EACb,cAAc,EACd,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAEjE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,kB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;AAC1E,YAAY,EAAE,MAAM,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACjF,OAAO,EACL,oBAAoB,EACpB,aAAa,EACb,cAAc,EACd,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAEjE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEzF,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEhF,YAAY,EAAE,EAAE,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAE5E,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACnE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAElG,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAErF"}
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,7 @@ export { compileMDX, compileSync, useMDX } from './mdx/index.js';
|
|
|
11
11
|
export { DataCache, createCache, getCached, setCache, prefetch } from './cache/index.js';
|
|
12
12
|
export { Head } from './meta/index.js';
|
|
13
13
|
export { generateMeta, generateBreadcrumbs, generateArticleSchema, generateProductSchema, } from './meta/index.js';
|
|
14
|
+
export { createLogger, createHttpLogger } from './logger/index.js';
|
|
14
15
|
export function defineConfig(config) {
|
|
15
16
|
return config;
|
|
16
17
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Logger, LoggerOptions } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Create a logger instance with configurable log level and transport
|
|
4
|
+
* @param options Logger configuration
|
|
5
|
+
* @returns Logger instance
|
|
6
|
+
*/
|
|
7
|
+
export declare function createLogger(options?: LoggerOptions): Logger;
|
|
8
|
+
/**
|
|
9
|
+
* Default logger instance
|
|
10
|
+
*/
|
|
11
|
+
export declare const logger: Logger;
|
|
12
|
+
//# sourceMappingURL=create-logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-logger.d.ts","sourceRoot":"","sources":["../../../src/logger/helpers/create-logger.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAY,MAAM,aAAa,CAAC;AAWnE;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,aAAkB,GAAG,MAAM,CA+IhE;AAED;;GAEG;AACH,eAAO,MAAM,MAAM,QAAiB,CAAC"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import pino from 'pino';
|
|
2
|
+
const LOG_LEVEL_TO_PINO = {
|
|
3
|
+
trace: 10,
|
|
4
|
+
debug: 20,
|
|
5
|
+
info: 30,
|
|
6
|
+
warn: 40,
|
|
7
|
+
error: 50,
|
|
8
|
+
fatal: 60,
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Create a logger instance with configurable log level and transport
|
|
12
|
+
* @param options Logger configuration
|
|
13
|
+
* @returns Logger instance
|
|
14
|
+
*/
|
|
15
|
+
export function createLogger(options = {}) {
|
|
16
|
+
const isProduction = process.env.NODE_ENV === 'production';
|
|
17
|
+
const isDev = !isProduction;
|
|
18
|
+
const pinoOptions = {
|
|
19
|
+
name: options.name ?? '@emberkit/core',
|
|
20
|
+
level: options.level ?? 'info',
|
|
21
|
+
};
|
|
22
|
+
let pinoLogger;
|
|
23
|
+
if (options.transport === false) {
|
|
24
|
+
// No transport, just use basic pino
|
|
25
|
+
pinoLogger = pino(pinoOptions);
|
|
26
|
+
}
|
|
27
|
+
else if (options.transport) {
|
|
28
|
+
// Use custom transport
|
|
29
|
+
pinoOptions.transport = options.transport;
|
|
30
|
+
pinoLogger = pino(pinoOptions);
|
|
31
|
+
}
|
|
32
|
+
else if (isDev && !process.env.CI && typeof window === 'undefined') {
|
|
33
|
+
// Development: try to use pino-pretty if available, fallback to basic
|
|
34
|
+
try {
|
|
35
|
+
pinoOptions.transport = {
|
|
36
|
+
target: 'pino-pretty',
|
|
37
|
+
options: {
|
|
38
|
+
colorize: true,
|
|
39
|
+
singleLine: false,
|
|
40
|
+
translateTime: 'SYS:standard',
|
|
41
|
+
ignore: 'pid,hostname',
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
pinoLogger = pino(pinoOptions);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// Fallback to basic pino if pino-pretty is not available
|
|
48
|
+
delete pinoOptions.transport;
|
|
49
|
+
pinoLogger = pino(pinoOptions);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
// Production: use basic pino
|
|
54
|
+
pinoLogger = pino(pinoOptions);
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
fatal: (msg, err) => {
|
|
58
|
+
if (err instanceof Error) {
|
|
59
|
+
pinoLogger.fatal({ err }, msg);
|
|
60
|
+
}
|
|
61
|
+
else if (err) {
|
|
62
|
+
pinoLogger.fatal(err, msg);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
pinoLogger.fatal(msg);
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
error: (msg, err) => {
|
|
69
|
+
if (err instanceof Error) {
|
|
70
|
+
pinoLogger.error({ err }, msg);
|
|
71
|
+
}
|
|
72
|
+
else if (err) {
|
|
73
|
+
pinoLogger.error(err, msg);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
pinoLogger.error(msg);
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
warn: (msg, obj) => {
|
|
80
|
+
if (obj) {
|
|
81
|
+
pinoLogger.warn(obj, msg);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
pinoLogger.warn(msg);
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
info: (msg, obj) => {
|
|
88
|
+
if (obj) {
|
|
89
|
+
pinoLogger.info(obj, msg);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
pinoLogger.info(msg);
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
debug: (msg, obj) => {
|
|
96
|
+
if (obj) {
|
|
97
|
+
pinoLogger.debug(obj, msg);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
pinoLogger.debug(msg);
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
trace: (msg, obj) => {
|
|
104
|
+
if (obj) {
|
|
105
|
+
pinoLogger.trace(obj, msg);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
pinoLogger.trace(msg);
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
child: (bindings) => {
|
|
112
|
+
const childPino = pinoLogger.child(bindings);
|
|
113
|
+
return {
|
|
114
|
+
fatal: (msg, err) => {
|
|
115
|
+
if (err instanceof Error) {
|
|
116
|
+
childPino.fatal({ err }, msg);
|
|
117
|
+
}
|
|
118
|
+
else if (err) {
|
|
119
|
+
childPino.fatal(err, msg);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
childPino.fatal(msg);
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
error: (msg, err) => {
|
|
126
|
+
if (err instanceof Error) {
|
|
127
|
+
childPino.error({ err }, msg);
|
|
128
|
+
}
|
|
129
|
+
else if (err) {
|
|
130
|
+
childPino.error(err, msg);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
childPino.error(msg);
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
warn: (msg, obj) => {
|
|
137
|
+
if (obj) {
|
|
138
|
+
childPino.warn(obj, msg);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
childPino.warn(msg);
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
info: (msg, obj) => {
|
|
145
|
+
if (obj) {
|
|
146
|
+
childPino.info(obj, msg);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
childPino.info(msg);
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
debug: (msg, obj) => {
|
|
153
|
+
if (obj) {
|
|
154
|
+
childPino.debug(obj, msg);
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
childPino.debug(msg);
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
trace: (msg, obj) => {
|
|
161
|
+
if (obj) {
|
|
162
|
+
childPino.trace(obj, msg);
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
childPino.trace(msg);
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
child: (bindings) => {
|
|
169
|
+
return createLogger(options).child(bindings);
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Default logger instance
|
|
177
|
+
*/
|
|
178
|
+
export const logger = createLogger();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Logger } from './types.js';
|
|
2
|
+
export type { Logger, LoggerOptions, LogLevel, RequestLog, ResponseLog } from './types.js';
|
|
3
|
+
export { createLogger } from './helpers/create-logger.js';
|
|
4
|
+
/**
|
|
5
|
+
* Create HTTP request/response logger middleware
|
|
6
|
+
* @param loggerInstance Optional logger instance. If not provided, creates a new one.
|
|
7
|
+
* @returns Pino HTTP middleware
|
|
8
|
+
*/
|
|
9
|
+
export declare function createHttpLogger(loggerInstance?: Logger): import("pino-http").HttpLogger<Error, import("http").ServerResponse<import("http").IncomingMessage>, never>;
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/logger/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAGzC,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC3F,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,cAAc,CAAC,EAAE,MAAM,+GAWvD"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import pinoHttp from 'pino-http';
|
|
2
|
+
import { createLogger } from './helpers/create-logger.js';
|
|
3
|
+
export { createLogger } from './helpers/create-logger.js';
|
|
4
|
+
/**
|
|
5
|
+
* Create HTTP request/response logger middleware
|
|
6
|
+
* @param loggerInstance Optional logger instance. If not provided, creates a new one.
|
|
7
|
+
* @returns Pino HTTP middleware
|
|
8
|
+
*/
|
|
9
|
+
export function createHttpLogger(loggerInstance) {
|
|
10
|
+
const logger = loggerInstance ?? createLogger({ name: '@emberkit/http' });
|
|
11
|
+
return pinoHttp({
|
|
12
|
+
logger: logger,
|
|
13
|
+
customErrorMessage: (error) => error.message,
|
|
14
|
+
customSuccessMessage: () => 'Request processed',
|
|
15
|
+
}, logger);
|
|
16
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export type LogLevel = 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace';
|
|
2
|
+
export interface LoggerOptions {
|
|
3
|
+
name?: string;
|
|
4
|
+
level?: LogLevel;
|
|
5
|
+
transport?: false | {
|
|
6
|
+
target: string;
|
|
7
|
+
options?: Record<string, unknown>;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export interface Logger {
|
|
11
|
+
fatal(msg: string, err?: Error | Record<string, unknown>): void;
|
|
12
|
+
error(msg: string, err?: Error | Record<string, unknown>): void;
|
|
13
|
+
warn(msg: string, obj?: Record<string, unknown>): void;
|
|
14
|
+
info(msg: string, obj?: Record<string, unknown>): void;
|
|
15
|
+
debug(msg: string, obj?: Record<string, unknown>): void;
|
|
16
|
+
trace(msg: string, obj?: Record<string, unknown>): void;
|
|
17
|
+
child(bindings: Record<string, unknown>): Logger;
|
|
18
|
+
}
|
|
19
|
+
export interface RequestLog {
|
|
20
|
+
method: string;
|
|
21
|
+
url: string;
|
|
22
|
+
statusCode?: number;
|
|
23
|
+
responseTime?: number;
|
|
24
|
+
contentLength?: number;
|
|
25
|
+
userAgent?: string;
|
|
26
|
+
remoteAddress?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface ResponseLog {
|
|
29
|
+
statusCode: number;
|
|
30
|
+
contentLength?: number;
|
|
31
|
+
responseTime: number;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/logger/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;AAE/E,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB,SAAS,CAAC,EAAE,KAAK,GAAG;QAClB,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACnC,CAAC;CACH;AAED,MAAM,WAAW,MAAM;IACrB,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,GAA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|
|
|
1
1
|
{
|
|
2
2
|
"name": "@emberkit/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Lightweight TypeScript-first JSX framework core",
|
|
@@ -48,6 +48,8 @@
|
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@mdx-js/mdx": "^3.1.1",
|
|
51
|
+
"pino": "^10.3.1",
|
|
52
|
+
"pino-http": "^11.0.0",
|
|
51
53
|
"remark-gfm": "^4.0.0",
|
|
52
54
|
"vite": "^6.0.0",
|
|
53
55
|
"vite-plugin-compression2": "^2.5.3"
|