@geekmidas/telescope 0.0.1
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 +521 -0
- package/dist/Telescope-B3Wd82yk.cjs +602 -0
- package/dist/Telescope-B3Wd82yk.cjs.map +1 -0
- package/dist/Telescope-C5dyDYYB.d.cts +133 -0
- package/dist/Telescope-D-uoZB6b.mjs +596 -0
- package/dist/Telescope-D-uoZB6b.mjs.map +1 -0
- package/dist/Telescope-DyIWgh9-.d.mts +133 -0
- package/dist/Telescope.cjs +3 -0
- package/dist/Telescope.d.cts +3 -0
- package/dist/Telescope.d.mts +3 -0
- package/dist/Telescope.mjs +3 -0
- package/dist/chunk-CUT6urMc.cjs +30 -0
- package/dist/index.cjs +5 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.mjs +4 -0
- package/dist/logger/console.cjs +161 -0
- package/dist/logger/console.cjs.map +1 -0
- package/dist/logger/console.d.cts +109 -0
- package/dist/logger/console.d.mts +109 -0
- package/dist/logger/console.mjs +159 -0
- package/dist/logger/console.mjs.map +1 -0
- package/dist/logger/pino.cjs +118 -0
- package/dist/logger/pino.cjs.map +1 -0
- package/dist/logger/pino.d.cts +89 -0
- package/dist/logger/pino.d.mts +89 -0
- package/dist/logger/pino.mjs +116 -0
- package/dist/logger/pino.mjs.map +1 -0
- package/dist/memory-9-B9WACq.cjs +110 -0
- package/dist/memory-9-B9WACq.cjs.map +1 -0
- package/dist/memory-Cm0eevCS.d.mts +38 -0
- package/dist/memory-DiP1a-pp.d.cts +38 -0
- package/dist/memory-SdN5vtG9.mjs +104 -0
- package/dist/memory-SdN5vtG9.mjs.map +1 -0
- package/dist/server/hono.cjs +180 -0
- package/dist/server/hono.cjs.map +1 -0
- package/dist/server/hono.d.cts +26 -0
- package/dist/server/hono.d.mts +26 -0
- package/dist/server/hono.mjs +176 -0
- package/dist/server/hono.mjs.map +1 -0
- package/dist/storage/kysely.cjs +336 -0
- package/dist/storage/kysely.cjs.map +1 -0
- package/dist/storage/kysely.d.cts +161 -0
- package/dist/storage/kysely.d.mts +161 -0
- package/dist/storage/kysely.mjs +334 -0
- package/dist/storage/kysely.mjs.map +1 -0
- package/dist/storage/memory.cjs +3 -0
- package/dist/storage/memory.d.cts +3 -0
- package/dist/storage/memory.d.mts +3 -0
- package/dist/storage/memory.mjs +3 -0
- package/dist/types-BGDhFv4R.d.cts +170 -0
- package/dist/types-CZbzz8kx.d.mts +170 -0
- package/dist/types.cjs +0 -0
- package/dist/types.d.cts +2 -0
- package/dist/types.d.mts +2 -0
- package/dist/types.mjs +0 -0
- package/dist/ui-assets-D6-8TAr_.mjs +30 -0
- package/dist/ui-assets-D6-8TAr_.mjs.map +1 -0
- package/dist/ui-assets-ulevVble.cjs +48 -0
- package/dist/ui-assets-ulevVble.cjs.map +1 -0
- package/dist/ui-assets.cjs +5 -0
- package/dist/ui-assets.d.cts +12 -0
- package/dist/ui-assets.d.mts +12 -0
- package/dist/ui-assets.mjs +3 -0
- package/package.json +83 -0
- package/scripts/embed-ui.ts +90 -0
- package/src/Telescope.ts +714 -0
- package/src/__tests__/Telescope.spec.ts +356 -0
- package/src/index.ts +23 -0
- package/src/logger/__tests__/console.spec.ts +266 -0
- package/src/logger/__tests__/pino.spec.ts +217 -0
- package/src/logger/console.ts +230 -0
- package/src/logger/pino.ts +191 -0
- package/src/server/__tests__/hono.spec.ts +340 -0
- package/src/server/hono.ts +247 -0
- package/src/storage/__tests__/kysely.spec.ts +715 -0
- package/src/storage/__tests__/memory.spec.ts +411 -0
- package/src/storage/kysely.ts +572 -0
- package/src/storage/memory.ts +168 -0
- package/src/types.ts +188 -0
- package/src/ui-assets.ts +40 -0
- package/ui/index.html +12 -0
- package/ui/node_modules/.bin/browserslist +21 -0
- package/ui/node_modules/.bin/jiti +21 -0
- package/ui/node_modules/.bin/terser +21 -0
- package/ui/node_modules/.bin/tsc +21 -0
- package/ui/node_modules/.bin/tsserver +21 -0
- package/ui/node_modules/.bin/tsx +21 -0
- package/ui/node_modules/.bin/vite +21 -0
- package/ui/package.json +24 -0
- package/ui/src/App.tsx +342 -0
- package/ui/src/api.ts +75 -0
- package/ui/src/components/ExceptionDetail.tsx +100 -0
- package/ui/src/components/LogDetail.tsx +91 -0
- package/ui/src/components/RequestDetail.tsx +143 -0
- package/ui/src/main.tsx +10 -0
- package/ui/src/styles.css +10 -0
- package/ui/src/types.ts +63 -0
- package/ui/src/vite-env.d.ts +1 -0
- package/ui/src/vite-plugin-gkm-config.ts +54 -0
- package/ui/tsconfig.json +20 -0
- package/ui/tsconfig.tsbuildinfo +14 -0
- package/ui/vite.config.ts +13 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { ExceptionEntry, LogEntry, QueryOptions, RequestEntry, TelescopeEvent, TelescopeOptions, TelescopeStats } from "./types-CZbzz8kx.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/Telescope.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Framework-agnostic Telescope class for debugging and monitoring applications.
|
|
7
|
+
* Use framework-specific adapters (e.g., @geekmidas/telescope/hono) for integration.
|
|
8
|
+
*/
|
|
9
|
+
declare class Telescope {
|
|
10
|
+
private storage;
|
|
11
|
+
private options;
|
|
12
|
+
private wsClients;
|
|
13
|
+
private pruneInterval?;
|
|
14
|
+
constructor(options: TelescopeOptions);
|
|
15
|
+
/**
|
|
16
|
+
* Record a request entry
|
|
17
|
+
*/
|
|
18
|
+
recordRequest(entry: Omit<RequestEntry, 'id' | 'timestamp'>): Promise<string>;
|
|
19
|
+
/**
|
|
20
|
+
* Log entry input for batch operations
|
|
21
|
+
*/
|
|
22
|
+
private saveLogEntries;
|
|
23
|
+
/**
|
|
24
|
+
* Record log entries in batch.
|
|
25
|
+
* More efficient than individual calls for database storage.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* await telescope.log([
|
|
29
|
+
* { level: 'info', message: 'Request started' },
|
|
30
|
+
* { level: 'debug', message: 'Processing...', context: { step: 1 } },
|
|
31
|
+
* ]);
|
|
32
|
+
*/
|
|
33
|
+
log(entries: Array<{
|
|
34
|
+
level: 'debug' | 'info' | 'warn' | 'error';
|
|
35
|
+
message: string;
|
|
36
|
+
context?: Record<string, unknown>;
|
|
37
|
+
requestId?: string;
|
|
38
|
+
}>): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Log a debug message
|
|
41
|
+
*/
|
|
42
|
+
debug(message: string, context?: Record<string, unknown>, requestId?: string): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Log an info message
|
|
45
|
+
*/
|
|
46
|
+
info(message: string, context?: Record<string, unknown>, requestId?: string): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Log a warning message
|
|
49
|
+
*/
|
|
50
|
+
warn(message: string, context?: Record<string, unknown>, requestId?: string): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Log an error message
|
|
53
|
+
*/
|
|
54
|
+
error(message: string, context?: Record<string, unknown>, requestId?: string): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Record an exception
|
|
57
|
+
*/
|
|
58
|
+
exception(error: Error, requestId?: string): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Get requests from storage
|
|
61
|
+
*/
|
|
62
|
+
getRequests(options?: QueryOptions): Promise<RequestEntry[]>;
|
|
63
|
+
/**
|
|
64
|
+
* Get a single request by ID
|
|
65
|
+
*/
|
|
66
|
+
getRequest(id: string): Promise<RequestEntry | null>;
|
|
67
|
+
/**
|
|
68
|
+
* Get exceptions from storage
|
|
69
|
+
*/
|
|
70
|
+
getExceptions(options?: QueryOptions): Promise<ExceptionEntry[]>;
|
|
71
|
+
/**
|
|
72
|
+
* Get a single exception by ID
|
|
73
|
+
*/
|
|
74
|
+
getException(id: string): Promise<ExceptionEntry | null>;
|
|
75
|
+
/**
|
|
76
|
+
* Get logs from storage
|
|
77
|
+
*/
|
|
78
|
+
getLogs(options?: QueryOptions): Promise<LogEntry[]>;
|
|
79
|
+
/**
|
|
80
|
+
* Get storage statistics
|
|
81
|
+
*/
|
|
82
|
+
getStats(): Promise<TelescopeStats>;
|
|
83
|
+
/**
|
|
84
|
+
* Add a WebSocket client for real-time updates
|
|
85
|
+
*/
|
|
86
|
+
addWsClient(ws: WebSocket): void;
|
|
87
|
+
/**
|
|
88
|
+
* Remove a WebSocket client
|
|
89
|
+
*/
|
|
90
|
+
removeWsClient(ws: WebSocket): void;
|
|
91
|
+
/**
|
|
92
|
+
* Broadcast an event to all connected WebSocket clients
|
|
93
|
+
*/
|
|
94
|
+
broadcast(event: TelescopeEvent): void;
|
|
95
|
+
/**
|
|
96
|
+
* Manually prune old entries
|
|
97
|
+
*/
|
|
98
|
+
prune(olderThan: Date): Promise<number>;
|
|
99
|
+
/**
|
|
100
|
+
* Clean up resources
|
|
101
|
+
*/
|
|
102
|
+
destroy(): void;
|
|
103
|
+
/**
|
|
104
|
+
* Get the telescope path
|
|
105
|
+
*/
|
|
106
|
+
get path(): string;
|
|
107
|
+
/**
|
|
108
|
+
* Check if telescope is enabled
|
|
109
|
+
*/
|
|
110
|
+
get enabled(): boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Check if body recording is enabled
|
|
113
|
+
*/
|
|
114
|
+
get recordBody(): boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Get max body size
|
|
117
|
+
*/
|
|
118
|
+
get maxBodySize(): number;
|
|
119
|
+
/**
|
|
120
|
+
* Check if a path should be ignored
|
|
121
|
+
*/
|
|
122
|
+
shouldIgnore(path: string): boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Get the dashboard HTML
|
|
125
|
+
*/
|
|
126
|
+
getDashboardHtml(): string;
|
|
127
|
+
private normalizeOptions;
|
|
128
|
+
private parseStack;
|
|
129
|
+
private autoPrune;
|
|
130
|
+
}
|
|
131
|
+
//#endregion
|
|
132
|
+
export { Telescope };
|
|
133
|
+
//# sourceMappingURL=Telescope-DyIWgh9-.d.mts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
|
|
25
|
+
Object.defineProperty(exports, '__toESM', {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return __toESM;
|
|
29
|
+
}
|
|
30
|
+
});
|
package/dist/index.cjs
ADDED
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ExceptionEntry, LogEntry, NormalizedTelescopeOptions, QueryOptions, RequestContext, RequestEntry, SourceContext, StackFrame, TelescopeEvent, TelescopeEventType, TelescopeOptions, TelescopeStats, TelescopeStorage } from "./types-BGDhFv4R.cjs";
|
|
2
|
+
import { Telescope } from "./Telescope-C5dyDYYB.cjs";
|
|
3
|
+
import { InMemoryStorage, InMemoryStorageOptions } from "./memory-DiP1a-pp.cjs";
|
|
4
|
+
export { ExceptionEntry, InMemoryStorage, InMemoryStorageOptions, LogEntry, NormalizedTelescopeOptions, QueryOptions, RequestContext, RequestEntry, SourceContext, StackFrame, Telescope, TelescopeEvent, TelescopeEventType, TelescopeOptions, TelescopeStats, TelescopeStorage };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ExceptionEntry, LogEntry, NormalizedTelescopeOptions, QueryOptions, RequestContext, RequestEntry, SourceContext, StackFrame, TelescopeEvent, TelescopeEventType, TelescopeOptions, TelescopeStats, TelescopeStorage } from "./types-CZbzz8kx.mjs";
|
|
2
|
+
import { Telescope } from "./Telescope-DyIWgh9-.mjs";
|
|
3
|
+
import { InMemoryStorage, InMemoryStorageOptions } from "./memory-Cm0eevCS.mjs";
|
|
4
|
+
export { ExceptionEntry, InMemoryStorage, InMemoryStorageOptions, LogEntry, NormalizedTelescopeOptions, QueryOptions, RequestContext, RequestEntry, SourceContext, StackFrame, Telescope, TelescopeEvent, TelescopeEventType, TelescopeOptions, TelescopeStats, TelescopeStorage };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/logger/console.ts
|
|
3
|
+
/**
|
|
4
|
+
* A logger that sends logs to both Telescope and an optional underlying logger.
|
|
5
|
+
* Implements the Logger interface from @geekmidas/logger.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { Telescope, InMemoryStorage } from '@geekmidas/telescope';
|
|
10
|
+
* import { TelescopeLogger } from '@geekmidas/telescope/logger/console';
|
|
11
|
+
* import { ConsoleLogger } from '@geekmidas/logger/console';
|
|
12
|
+
*
|
|
13
|
+
* const telescope = new Telescope({ storage: new InMemoryStorage() });
|
|
14
|
+
*
|
|
15
|
+
* // With underlying logger (logs to both console and Telescope)
|
|
16
|
+
* const logger = new TelescopeLogger({
|
|
17
|
+
* telescope,
|
|
18
|
+
* logger: new ConsoleLogger({ app: 'myApp' }),
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // Without underlying logger (logs only to Telescope)
|
|
22
|
+
* const telescopeOnly = new TelescopeLogger({ telescope });
|
|
23
|
+
*
|
|
24
|
+
* // Usage
|
|
25
|
+
* logger.info({ userId: '123' }, 'User logged in');
|
|
26
|
+
* logger.error({ error: 'Something failed' }, 'Operation failed');
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
var TelescopeLogger = class TelescopeLogger {
|
|
30
|
+
telescope;
|
|
31
|
+
logger;
|
|
32
|
+
requestId;
|
|
33
|
+
context;
|
|
34
|
+
constructor(options) {
|
|
35
|
+
this.telescope = options.telescope;
|
|
36
|
+
this.logger = options.logger;
|
|
37
|
+
this.requestId = options.requestId;
|
|
38
|
+
this.context = options.context ?? {};
|
|
39
|
+
}
|
|
40
|
+
createLogFn(level) {
|
|
41
|
+
const fn = (objOrMsg, msg, ...args) => {
|
|
42
|
+
let context;
|
|
43
|
+
let message;
|
|
44
|
+
if (typeof objOrMsg === "string") {
|
|
45
|
+
context = { ...this.context };
|
|
46
|
+
message = objOrMsg;
|
|
47
|
+
} else {
|
|
48
|
+
context = {
|
|
49
|
+
...this.context,
|
|
50
|
+
...objOrMsg
|
|
51
|
+
};
|
|
52
|
+
message = msg ?? "";
|
|
53
|
+
}
|
|
54
|
+
if (this.logger) if (typeof objOrMsg === "string") this.logger[level](objOrMsg);
|
|
55
|
+
else this.logger[level](objOrMsg, msg, ...args);
|
|
56
|
+
this.telescope[level](message, context, this.requestId).catch(() => {});
|
|
57
|
+
};
|
|
58
|
+
return fn;
|
|
59
|
+
}
|
|
60
|
+
debug = this.createLogFn("debug");
|
|
61
|
+
info = this.createLogFn("info");
|
|
62
|
+
warn = this.createLogFn("warn");
|
|
63
|
+
error = this.createLogFn("error");
|
|
64
|
+
fatal = (objOrMsg, msg, ...args) => {
|
|
65
|
+
if (this.logger) if (typeof objOrMsg === "string") this.logger.fatal(objOrMsg);
|
|
66
|
+
else this.logger.fatal(objOrMsg, msg, ...args);
|
|
67
|
+
let context;
|
|
68
|
+
let message;
|
|
69
|
+
if (typeof objOrMsg === "string") {
|
|
70
|
+
context = {
|
|
71
|
+
...this.context,
|
|
72
|
+
level: "fatal"
|
|
73
|
+
};
|
|
74
|
+
message = objOrMsg;
|
|
75
|
+
} else {
|
|
76
|
+
context = {
|
|
77
|
+
...this.context,
|
|
78
|
+
...objOrMsg,
|
|
79
|
+
level: "fatal"
|
|
80
|
+
};
|
|
81
|
+
message = msg ?? "";
|
|
82
|
+
}
|
|
83
|
+
this.telescope.error(message, context, this.requestId).catch(() => {});
|
|
84
|
+
};
|
|
85
|
+
trace = (objOrMsg, msg, ...args) => {
|
|
86
|
+
if (this.logger) if (typeof objOrMsg === "string") this.logger.trace(objOrMsg);
|
|
87
|
+
else this.logger.trace(objOrMsg, msg, ...args);
|
|
88
|
+
let context;
|
|
89
|
+
let message;
|
|
90
|
+
if (typeof objOrMsg === "string") {
|
|
91
|
+
context = {
|
|
92
|
+
...this.context,
|
|
93
|
+
level: "trace"
|
|
94
|
+
};
|
|
95
|
+
message = objOrMsg;
|
|
96
|
+
} else {
|
|
97
|
+
context = {
|
|
98
|
+
...this.context,
|
|
99
|
+
...objOrMsg,
|
|
100
|
+
level: "trace"
|
|
101
|
+
};
|
|
102
|
+
message = msg ?? "";
|
|
103
|
+
}
|
|
104
|
+
this.telescope.debug(message, context, this.requestId).catch(() => {});
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Creates a child logger with additional context.
|
|
108
|
+
* The child logger inherits all context from the parent.
|
|
109
|
+
*/
|
|
110
|
+
child(obj) {
|
|
111
|
+
return new TelescopeLogger({
|
|
112
|
+
telescope: this.telescope,
|
|
113
|
+
logger: this.logger?.child(obj),
|
|
114
|
+
requestId: this.requestId,
|
|
115
|
+
context: {
|
|
116
|
+
...this.context,
|
|
117
|
+
...obj
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Create a child logger bound to a specific request ID.
|
|
123
|
+
* Useful for correlating logs with HTTP requests.
|
|
124
|
+
*/
|
|
125
|
+
withRequestId(requestId) {
|
|
126
|
+
return new TelescopeLogger({
|
|
127
|
+
telescope: this.telescope,
|
|
128
|
+
logger: this.logger,
|
|
129
|
+
requestId,
|
|
130
|
+
context: this.context
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Create a logger that sends logs to Telescope.
|
|
136
|
+
* Convenience function for creating a TelescopeLogger.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* import { createTelescopeLogger } from '@geekmidas/telescope/logger/console';
|
|
141
|
+
* import { ConsoleLogger } from '@geekmidas/logger/console';
|
|
142
|
+
*
|
|
143
|
+
* const telescope = new Telescope({ storage: new InMemoryStorage() });
|
|
144
|
+
* const baseLogger = new ConsoleLogger({ app: 'myApp' });
|
|
145
|
+
*
|
|
146
|
+
* const logger = createTelescopeLogger(telescope, baseLogger);
|
|
147
|
+
* logger.info({ action: 'startup' }, 'Application started');
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
function createTelescopeLogger(telescope, logger, context) {
|
|
151
|
+
return new TelescopeLogger({
|
|
152
|
+
telescope,
|
|
153
|
+
logger,
|
|
154
|
+
context
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
//#endregion
|
|
159
|
+
exports.TelescopeLogger = TelescopeLogger;
|
|
160
|
+
exports.createTelescopeLogger = createTelescopeLogger;
|
|
161
|
+
//# sourceMappingURL=console.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console.cjs","names":["options: TelescopeLoggerOptions","level: LogLevel","objOrMsg: T | string","msg?: string","context: Record<string, unknown>","message: string","objOrMsg: object | string","obj: object","requestId: string","telescope: Telescope","logger?: Logger","context?: Record<string, unknown>"],"sources":["../../src/logger/console.ts"],"sourcesContent":["import type { Telescope } from '../Telescope';\n\n/**\n * Logger interface matching @geekmidas/logger\n */\nexport interface Logger {\n debug: LogFn;\n info: LogFn;\n warn: LogFn;\n error: LogFn;\n fatal: LogFn;\n trace: LogFn;\n child: (obj: object) => Logger;\n}\n\nexport type LogFn = {\n <T extends object>(obj: T, msg?: string, ...args: any[]): void;\n (msg: string): void;\n};\n\nexport interface TelescopeLoggerOptions {\n /**\n * The Telescope instance to send logs to\n */\n telescope: Telescope;\n /**\n * Optional underlying logger to also forward logs to.\n * If not provided, logs will only go to Telescope.\n */\n logger?: Logger;\n /**\n * Request ID to associate logs with a specific request.\n */\n requestId?: string;\n /**\n * Initial context data to include in all log messages\n */\n context?: Record<string, unknown>;\n}\n\ntype LogLevel = 'debug' | 'info' | 'warn' | 'error';\n\n/**\n * A logger that sends logs to both Telescope and an optional underlying logger.\n * Implements the Logger interface from @geekmidas/logger.\n *\n * @example\n * ```typescript\n * import { Telescope, InMemoryStorage } from '@geekmidas/telescope';\n * import { TelescopeLogger } from '@geekmidas/telescope/logger/console';\n * import { ConsoleLogger } from '@geekmidas/logger/console';\n *\n * const telescope = new Telescope({ storage: new InMemoryStorage() });\n *\n * // With underlying logger (logs to both console and Telescope)\n * const logger = new TelescopeLogger({\n * telescope,\n * logger: new ConsoleLogger({ app: 'myApp' }),\n * });\n *\n * // Without underlying logger (logs only to Telescope)\n * const telescopeOnly = new TelescopeLogger({ telescope });\n *\n * // Usage\n * logger.info({ userId: '123' }, 'User logged in');\n * logger.error({ error: 'Something failed' }, 'Operation failed');\n * ```\n */\nexport class TelescopeLogger implements Logger {\n private telescope: Telescope;\n private logger?: Logger;\n private requestId?: string;\n private context: Record<string, unknown>;\n\n constructor(options: TelescopeLoggerOptions) {\n this.telescope = options.telescope;\n this.logger = options.logger;\n this.requestId = options.requestId;\n this.context = options.context ?? {};\n }\n\n private createLogFn(level: LogLevel): LogFn {\n const fn = <T extends object>(\n objOrMsg: T | string,\n msg?: string,\n ...args: any[]\n ): void => {\n let context: Record<string, unknown>;\n let message: string;\n\n if (typeof objOrMsg === 'string') {\n context = { ...this.context };\n message = objOrMsg;\n } else {\n context = { ...this.context, ...objOrMsg };\n message = msg ?? '';\n }\n\n // Forward to underlying logger if present\n if (this.logger) {\n if (typeof objOrMsg === 'string') {\n this.logger[level](objOrMsg);\n } else {\n this.logger[level](objOrMsg as any, msg, ...args);\n }\n }\n\n // Send to Telescope (fire and forget)\n this.telescope[level](message, context, this.requestId).catch(() => {});\n };\n\n return fn as LogFn;\n }\n\n debug: LogFn = this.createLogFn('debug');\n info: LogFn = this.createLogFn('info');\n warn: LogFn = this.createLogFn('warn');\n error: LogFn = this.createLogFn('error');\n\n // Map fatal and trace to error and debug for Telescope\n fatal: LogFn = ((\n objOrMsg: object | string,\n msg?: string,\n ...args: any[]\n ): void => {\n // Forward to underlying logger if present\n if (this.logger) {\n if (typeof objOrMsg === 'string') {\n this.logger.fatal(objOrMsg);\n } else {\n this.logger.fatal(objOrMsg as any, msg, ...args);\n }\n }\n\n // Send to Telescope as error level\n let context: Record<string, unknown>;\n let message: string;\n\n if (typeof objOrMsg === 'string') {\n context = { ...this.context, level: 'fatal' };\n message = objOrMsg;\n } else {\n context = { ...this.context, ...objOrMsg, level: 'fatal' };\n message = msg ?? '';\n }\n\n this.telescope.error(message, context, this.requestId).catch(() => {});\n }) as LogFn;\n\n trace: LogFn = ((\n objOrMsg: object | string,\n msg?: string,\n ...args: any[]\n ): void => {\n // Forward to underlying logger if present\n if (this.logger) {\n if (typeof objOrMsg === 'string') {\n this.logger.trace(objOrMsg);\n } else {\n this.logger.trace(objOrMsg as any, msg, ...args);\n }\n }\n\n // Send to Telescope as debug level\n let context: Record<string, unknown>;\n let message: string;\n\n if (typeof objOrMsg === 'string') {\n context = { ...this.context, level: 'trace' };\n message = objOrMsg;\n } else {\n context = { ...this.context, ...objOrMsg, level: 'trace' };\n message = msg ?? '';\n }\n\n this.telescope.debug(message, context, this.requestId).catch(() => {});\n }) as LogFn;\n\n /**\n * Creates a child logger with additional context.\n * The child logger inherits all context from the parent.\n */\n child(obj: object): Logger {\n return new TelescopeLogger({\n telescope: this.telescope,\n logger: this.logger?.child(obj),\n requestId: this.requestId,\n context: { ...this.context, ...obj },\n });\n }\n\n /**\n * Create a child logger bound to a specific request ID.\n * Useful for correlating logs with HTTP requests.\n */\n withRequestId(requestId: string): TelescopeLogger {\n return new TelescopeLogger({\n telescope: this.telescope,\n logger: this.logger,\n requestId,\n context: this.context,\n });\n }\n}\n\n/**\n * Create a logger that sends logs to Telescope.\n * Convenience function for creating a TelescopeLogger.\n *\n * @example\n * ```typescript\n * import { createTelescopeLogger } from '@geekmidas/telescope/logger/console';\n * import { ConsoleLogger } from '@geekmidas/logger/console';\n *\n * const telescope = new Telescope({ storage: new InMemoryStorage() });\n * const baseLogger = new ConsoleLogger({ app: 'myApp' });\n *\n * const logger = createTelescopeLogger(telescope, baseLogger);\n * logger.info({ action: 'startup' }, 'Application started');\n * ```\n */\nexport function createTelescopeLogger(\n telescope: Telescope,\n logger?: Logger,\n context?: Record<string, unknown>,\n): TelescopeLogger {\n return new TelescopeLogger({ telescope, logger, context });\n}\n\nexport type { Telescope };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,IAAa,kBAAb,MAAa,gBAAkC;CAC7C,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CAER,YAAYA,SAAiC;AAC3C,OAAK,YAAY,QAAQ;AACzB,OAAK,SAAS,QAAQ;AACtB,OAAK,YAAY,QAAQ;AACzB,OAAK,UAAU,QAAQ,WAAW,CAAE;CACrC;CAED,AAAQ,YAAYC,OAAwB;EAC1C,MAAM,KAAK,CACTC,UACAC,KACA,GAAG,SACM;GACT,IAAIC;GACJ,IAAIC;AAEJ,cAAW,aAAa,UAAU;AAChC,cAAU,EAAE,GAAG,KAAK,QAAS;AAC7B,cAAU;GACX,OAAM;AACL,cAAU;KAAE,GAAG,KAAK;KAAS,GAAG;IAAU;AAC1C,cAAU,OAAO;GAClB;AAGD,OAAI,KAAK,OACP,YAAW,aAAa,SACtB,MAAK,OAAO,OAAO,SAAS;OAE5B,MAAK,OAAO,OAAO,UAAiB,KAAK,GAAG,KAAK;AAKrD,QAAK,UAAU,OAAO,SAAS,SAAS,KAAK,UAAU,CAAC,MAAM,MAAM,CAAE,EAAC;EACxE;AAED,SAAO;CACR;CAED,QAAe,KAAK,YAAY,QAAQ;CACxC,OAAc,KAAK,YAAY,OAAO;CACtC,OAAc,KAAK,YAAY,OAAO;CACtC,QAAe,KAAK,YAAY,QAAQ;CAGxC,QAAgB,CACdC,UACAH,KACA,GAAG,SACM;AAET,MAAI,KAAK,OACP,YAAW,aAAa,SACtB,MAAK,OAAO,MAAM,SAAS;MAE3B,MAAK,OAAO,MAAM,UAAiB,KAAK,GAAG,KAAK;EAKpD,IAAIC;EACJ,IAAIC;AAEJ,aAAW,aAAa,UAAU;AAChC,aAAU;IAAE,GAAG,KAAK;IAAS,OAAO;GAAS;AAC7C,aAAU;EACX,OAAM;AACL,aAAU;IAAE,GAAG,KAAK;IAAS,GAAG;IAAU,OAAO;GAAS;AAC1D,aAAU,OAAO;EAClB;AAED,OAAK,UAAU,MAAM,SAAS,SAAS,KAAK,UAAU,CAAC,MAAM,MAAM,CAAE,EAAC;CACvE;CAED,QAAgB,CACdC,UACAH,KACA,GAAG,SACM;AAET,MAAI,KAAK,OACP,YAAW,aAAa,SACtB,MAAK,OAAO,MAAM,SAAS;MAE3B,MAAK,OAAO,MAAM,UAAiB,KAAK,GAAG,KAAK;EAKpD,IAAIC;EACJ,IAAIC;AAEJ,aAAW,aAAa,UAAU;AAChC,aAAU;IAAE,GAAG,KAAK;IAAS,OAAO;GAAS;AAC7C,aAAU;EACX,OAAM;AACL,aAAU;IAAE,GAAG,KAAK;IAAS,GAAG;IAAU,OAAO;GAAS;AAC1D,aAAU,OAAO;EAClB;AAED,OAAK,UAAU,MAAM,SAAS,SAAS,KAAK,UAAU,CAAC,MAAM,MAAM,CAAE,EAAC;CACvE;;;;;CAMD,MAAME,KAAqB;AACzB,SAAO,IAAI,gBAAgB;GACzB,WAAW,KAAK;GAChB,QAAQ,KAAK,QAAQ,MAAM,IAAI;GAC/B,WAAW,KAAK;GAChB,SAAS;IAAE,GAAG,KAAK;IAAS,GAAG;GAAK;EACrC;CACF;;;;;CAMD,cAAcC,WAAoC;AAChD,SAAO,IAAI,gBAAgB;GACzB,WAAW,KAAK;GAChB,QAAQ,KAAK;GACb;GACA,SAAS,KAAK;EACf;CACF;AACF;;;;;;;;;;;;;;;;;AAkBD,SAAgB,sBACdC,WACAC,QACAC,SACiB;AACjB,QAAO,IAAI,gBAAgB;EAAE;EAAW;EAAQ;CAAS;AAC1D"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import "../types-BGDhFv4R.cjs";
|
|
2
|
+
import { Telescope } from "../Telescope-C5dyDYYB.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/logger/console.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Logger interface matching @geekmidas/logger
|
|
7
|
+
*/
|
|
8
|
+
interface Logger {
|
|
9
|
+
debug: LogFn;
|
|
10
|
+
info: LogFn;
|
|
11
|
+
warn: LogFn;
|
|
12
|
+
error: LogFn;
|
|
13
|
+
fatal: LogFn;
|
|
14
|
+
trace: LogFn;
|
|
15
|
+
child: (obj: object) => Logger;
|
|
16
|
+
}
|
|
17
|
+
type LogFn = {
|
|
18
|
+
<T extends object>(obj: T, msg?: string, ...args: any[]): void;
|
|
19
|
+
(msg: string): void;
|
|
20
|
+
};
|
|
21
|
+
interface TelescopeLoggerOptions {
|
|
22
|
+
/**
|
|
23
|
+
* The Telescope instance to send logs to
|
|
24
|
+
*/
|
|
25
|
+
telescope: Telescope;
|
|
26
|
+
/**
|
|
27
|
+
* Optional underlying logger to also forward logs to.
|
|
28
|
+
* If not provided, logs will only go to Telescope.
|
|
29
|
+
*/
|
|
30
|
+
logger?: Logger;
|
|
31
|
+
/**
|
|
32
|
+
* Request ID to associate logs with a specific request.
|
|
33
|
+
*/
|
|
34
|
+
requestId?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Initial context data to include in all log messages
|
|
37
|
+
*/
|
|
38
|
+
context?: Record<string, unknown>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A logger that sends logs to both Telescope and an optional underlying logger.
|
|
42
|
+
* Implements the Logger interface from @geekmidas/logger.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* import { Telescope, InMemoryStorage } from '@geekmidas/telescope';
|
|
47
|
+
* import { TelescopeLogger } from '@geekmidas/telescope/logger/console';
|
|
48
|
+
* import { ConsoleLogger } from '@geekmidas/logger/console';
|
|
49
|
+
*
|
|
50
|
+
* const telescope = new Telescope({ storage: new InMemoryStorage() });
|
|
51
|
+
*
|
|
52
|
+
* // With underlying logger (logs to both console and Telescope)
|
|
53
|
+
* const logger = new TelescopeLogger({
|
|
54
|
+
* telescope,
|
|
55
|
+
* logger: new ConsoleLogger({ app: 'myApp' }),
|
|
56
|
+
* });
|
|
57
|
+
*
|
|
58
|
+
* // Without underlying logger (logs only to Telescope)
|
|
59
|
+
* const telescopeOnly = new TelescopeLogger({ telescope });
|
|
60
|
+
*
|
|
61
|
+
* // Usage
|
|
62
|
+
* logger.info({ userId: '123' }, 'User logged in');
|
|
63
|
+
* logger.error({ error: 'Something failed' }, 'Operation failed');
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
declare class TelescopeLogger implements Logger {
|
|
67
|
+
private telescope;
|
|
68
|
+
private logger?;
|
|
69
|
+
private requestId?;
|
|
70
|
+
private context;
|
|
71
|
+
constructor(options: TelescopeLoggerOptions);
|
|
72
|
+
private createLogFn;
|
|
73
|
+
debug: LogFn;
|
|
74
|
+
info: LogFn;
|
|
75
|
+
warn: LogFn;
|
|
76
|
+
error: LogFn;
|
|
77
|
+
fatal: LogFn;
|
|
78
|
+
trace: LogFn;
|
|
79
|
+
/**
|
|
80
|
+
* Creates a child logger with additional context.
|
|
81
|
+
* The child logger inherits all context from the parent.
|
|
82
|
+
*/
|
|
83
|
+
child(obj: object): Logger;
|
|
84
|
+
/**
|
|
85
|
+
* Create a child logger bound to a specific request ID.
|
|
86
|
+
* Useful for correlating logs with HTTP requests.
|
|
87
|
+
*/
|
|
88
|
+
withRequestId(requestId: string): TelescopeLogger;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Create a logger that sends logs to Telescope.
|
|
92
|
+
* Convenience function for creating a TelescopeLogger.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* import { createTelescopeLogger } from '@geekmidas/telescope/logger/console';
|
|
97
|
+
* import { ConsoleLogger } from '@geekmidas/logger/console';
|
|
98
|
+
*
|
|
99
|
+
* const telescope = new Telescope({ storage: new InMemoryStorage() });
|
|
100
|
+
* const baseLogger = new ConsoleLogger({ app: 'myApp' });
|
|
101
|
+
*
|
|
102
|
+
* const logger = createTelescopeLogger(telescope, baseLogger);
|
|
103
|
+
* logger.info({ action: 'startup' }, 'Application started');
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
declare function createTelescopeLogger(telescope: Telescope, logger?: Logger, context?: Record<string, unknown>): TelescopeLogger;
|
|
107
|
+
//#endregion
|
|
108
|
+
export { LogFn, Logger, Telescope, TelescopeLogger, TelescopeLoggerOptions, createTelescopeLogger };
|
|
109
|
+
//# sourceMappingURL=console.d.cts.map
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import "../types-CZbzz8kx.mjs";
|
|
2
|
+
import { Telescope } from "../Telescope-DyIWgh9-.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/logger/console.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Logger interface matching @geekmidas/logger
|
|
7
|
+
*/
|
|
8
|
+
interface Logger {
|
|
9
|
+
debug: LogFn;
|
|
10
|
+
info: LogFn;
|
|
11
|
+
warn: LogFn;
|
|
12
|
+
error: LogFn;
|
|
13
|
+
fatal: LogFn;
|
|
14
|
+
trace: LogFn;
|
|
15
|
+
child: (obj: object) => Logger;
|
|
16
|
+
}
|
|
17
|
+
type LogFn = {
|
|
18
|
+
<T extends object>(obj: T, msg?: string, ...args: any[]): void;
|
|
19
|
+
(msg: string): void;
|
|
20
|
+
};
|
|
21
|
+
interface TelescopeLoggerOptions {
|
|
22
|
+
/**
|
|
23
|
+
* The Telescope instance to send logs to
|
|
24
|
+
*/
|
|
25
|
+
telescope: Telescope;
|
|
26
|
+
/**
|
|
27
|
+
* Optional underlying logger to also forward logs to.
|
|
28
|
+
* If not provided, logs will only go to Telescope.
|
|
29
|
+
*/
|
|
30
|
+
logger?: Logger;
|
|
31
|
+
/**
|
|
32
|
+
* Request ID to associate logs with a specific request.
|
|
33
|
+
*/
|
|
34
|
+
requestId?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Initial context data to include in all log messages
|
|
37
|
+
*/
|
|
38
|
+
context?: Record<string, unknown>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A logger that sends logs to both Telescope and an optional underlying logger.
|
|
42
|
+
* Implements the Logger interface from @geekmidas/logger.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* import { Telescope, InMemoryStorage } from '@geekmidas/telescope';
|
|
47
|
+
* import { TelescopeLogger } from '@geekmidas/telescope/logger/console';
|
|
48
|
+
* import { ConsoleLogger } from '@geekmidas/logger/console';
|
|
49
|
+
*
|
|
50
|
+
* const telescope = new Telescope({ storage: new InMemoryStorage() });
|
|
51
|
+
*
|
|
52
|
+
* // With underlying logger (logs to both console and Telescope)
|
|
53
|
+
* const logger = new TelescopeLogger({
|
|
54
|
+
* telescope,
|
|
55
|
+
* logger: new ConsoleLogger({ app: 'myApp' }),
|
|
56
|
+
* });
|
|
57
|
+
*
|
|
58
|
+
* // Without underlying logger (logs only to Telescope)
|
|
59
|
+
* const telescopeOnly = new TelescopeLogger({ telescope });
|
|
60
|
+
*
|
|
61
|
+
* // Usage
|
|
62
|
+
* logger.info({ userId: '123' }, 'User logged in');
|
|
63
|
+
* logger.error({ error: 'Something failed' }, 'Operation failed');
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
declare class TelescopeLogger implements Logger {
|
|
67
|
+
private telescope;
|
|
68
|
+
private logger?;
|
|
69
|
+
private requestId?;
|
|
70
|
+
private context;
|
|
71
|
+
constructor(options: TelescopeLoggerOptions);
|
|
72
|
+
private createLogFn;
|
|
73
|
+
debug: LogFn;
|
|
74
|
+
info: LogFn;
|
|
75
|
+
warn: LogFn;
|
|
76
|
+
error: LogFn;
|
|
77
|
+
fatal: LogFn;
|
|
78
|
+
trace: LogFn;
|
|
79
|
+
/**
|
|
80
|
+
* Creates a child logger with additional context.
|
|
81
|
+
* The child logger inherits all context from the parent.
|
|
82
|
+
*/
|
|
83
|
+
child(obj: object): Logger;
|
|
84
|
+
/**
|
|
85
|
+
* Create a child logger bound to a specific request ID.
|
|
86
|
+
* Useful for correlating logs with HTTP requests.
|
|
87
|
+
*/
|
|
88
|
+
withRequestId(requestId: string): TelescopeLogger;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Create a logger that sends logs to Telescope.
|
|
92
|
+
* Convenience function for creating a TelescopeLogger.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* import { createTelescopeLogger } from '@geekmidas/telescope/logger/console';
|
|
97
|
+
* import { ConsoleLogger } from '@geekmidas/logger/console';
|
|
98
|
+
*
|
|
99
|
+
* const telescope = new Telescope({ storage: new InMemoryStorage() });
|
|
100
|
+
* const baseLogger = new ConsoleLogger({ app: 'myApp' });
|
|
101
|
+
*
|
|
102
|
+
* const logger = createTelescopeLogger(telescope, baseLogger);
|
|
103
|
+
* logger.info({ action: 'startup' }, 'Application started');
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
declare function createTelescopeLogger(telescope: Telescope, logger?: Logger, context?: Record<string, unknown>): TelescopeLogger;
|
|
107
|
+
//#endregion
|
|
108
|
+
export { LogFn, Logger, Telescope, TelescopeLogger, TelescopeLoggerOptions, createTelescopeLogger };
|
|
109
|
+
//# sourceMappingURL=console.d.mts.map
|