@ngn-net/nestjs-telescope 0.2.10 → 0.2.11

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.
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@ngn-net/nestjs-telescope",
3
- "version": "0.2.10",
4
- "builtAt": "2026-06-08T12:50:24.624Z"
3
+ "version": "0.2.11",
4
+ "builtAt": "2026-06-08T12:52:50.170Z"
5
5
  }
@@ -14,44 +14,6 @@ exports.LogWatcher = void 0;
14
14
  const common_1 = require("@nestjs/common");
15
15
  const telescope_service_1 = require("../telescope.service");
16
16
  const entry_type_enum_1 = require("../enums/entry-type.enum");
17
- class TelescopeLoggerWrapper {
18
- original;
19
- recordLog;
20
- constructor(original, recordLog) {
21
- this.original = original;
22
- this.recordLog = recordLog;
23
- }
24
- log(message, ...optionalParams) {
25
- this.recordLog('log', message, ...optionalParams);
26
- this.original.log(message, ...optionalParams);
27
- }
28
- error(message, ...optionalParams) {
29
- this.recordLog('error', message, ...optionalParams);
30
- this.original.error(message, ...optionalParams);
31
- }
32
- warn(message, ...optionalParams) {
33
- this.recordLog('warn', message, ...optionalParams);
34
- this.original.warn(message, ...optionalParams);
35
- }
36
- debug(message, ...optionalParams) {
37
- this.recordLog('debug', message, ...optionalParams);
38
- if (this.original.debug) {
39
- this.original.debug(message, ...optionalParams);
40
- }
41
- }
42
- verbose(message, ...optionalParams) {
43
- this.recordLog('verbose', message, ...optionalParams);
44
- if (this.original.verbose) {
45
- this.original.verbose(message, ...optionalParams);
46
- }
47
- }
48
- fatal(message, ...optionalParams) {
49
- this.recordLog('fatal', message, ...optionalParams);
50
- if (this.original.fatal) {
51
- this.original.fatal(message, ...optionalParams);
52
- }
53
- }
54
- }
55
17
  let LogWatcher = class LogWatcher {
56
18
  telescope;
57
19
  isRecording = false; // Guard against infinite recursion
@@ -101,39 +63,59 @@ let LogWatcher = class LogWatcher {
101
63
  recordConsoleLog('debug', args);
102
64
  return originalDebug(...args);
103
65
  };
104
- // 2. Intercept NestJS Logger Service logs
66
+ // 2. Intercept NestJS static Logger methods directly
105
67
  try {
106
- const activeLogger = common_1.Logger.logger;
107
- if (activeLogger && !(activeLogger instanceof TelescopeLoggerWrapper)) {
108
- const wrapper = new TelescopeLoggerWrapper(activeLogger, (level, message, ...optionalParams) => {
109
- if (self.isRecording)
110
- return;
111
- let formattedMessage = typeof message === 'object' ? JSON.stringify(message) : String(message);
112
- if (optionalParams.length > 0) {
113
- // Get context (usually the last parameter, e.g. [PurchaseService])
114
- const context = optionalParams[optionalParams.length - 1];
115
- const contextStr = typeof context === 'string' ? `[${context}] ` : '';
116
- formattedMessage = contextStr + formattedMessage;
117
- }
118
- if (formattedMessage.includes('telescope_entries') || formattedMessage.includes('TelescopeModule')) {
119
- return;
120
- }
121
- self.isRecording = true;
122
- try {
123
- self.telescope.record({
124
- type: entry_type_enum_1.EntryType.LOG,
125
- content: { level, message: formattedMessage },
126
- }).catch(() => { });
127
- }
128
- finally {
129
- self.isRecording = false;
130
- }
131
- });
132
- common_1.Logger.overrideLogger(wrapper);
133
- }
68
+ const originalStaticLog = common_1.Logger.log;
69
+ const originalStaticError = common_1.Logger.error;
70
+ const originalStaticWarn = common_1.Logger.warn;
71
+ const originalStaticDebug = common_1.Logger.debug;
72
+ const originalStaticVerbose = common_1.Logger.verbose;
73
+ const recordNestLog = (level, message, optionalParams) => {
74
+ if (self.isRecording)
75
+ return;
76
+ let formattedMessage = typeof message === 'object' ? JSON.stringify(message) : String(message);
77
+ if (optionalParams.length > 0) {
78
+ const context = optionalParams[0];
79
+ const contextStr = typeof context === 'string' ? `[${context}] ` : '';
80
+ formattedMessage = contextStr + formattedMessage;
81
+ }
82
+ if (formattedMessage.includes('telescope_entries') || formattedMessage.includes('TelescopeModule')) {
83
+ return;
84
+ }
85
+ self.isRecording = true;
86
+ try {
87
+ self.telescope.record({
88
+ type: entry_type_enum_1.EntryType.LOG,
89
+ content: { level, message: formattedMessage },
90
+ }).catch(() => { });
91
+ }
92
+ finally {
93
+ self.isRecording = false;
94
+ }
95
+ };
96
+ common_1.Logger.log = function (message, ...optionalParams) {
97
+ recordNestLog('log', message, optionalParams);
98
+ return originalStaticLog.call(common_1.Logger, message, ...optionalParams);
99
+ };
100
+ common_1.Logger.error = function (message, ...optionalParams) {
101
+ recordNestLog('error', message, optionalParams);
102
+ return originalStaticError.call(common_1.Logger, message, ...optionalParams);
103
+ };
104
+ common_1.Logger.warn = function (message, ...optionalParams) {
105
+ recordNestLog('warn', message, optionalParams);
106
+ return originalStaticWarn.call(common_1.Logger, message, ...optionalParams);
107
+ };
108
+ common_1.Logger.debug = function (message, ...optionalParams) {
109
+ recordNestLog('debug', message, optionalParams);
110
+ return originalStaticDebug.call(common_1.Logger, message, ...optionalParams);
111
+ };
112
+ common_1.Logger.verbose = function (message, ...optionalParams) {
113
+ recordNestLog('verbose', message, optionalParams);
114
+ return originalStaticVerbose.call(common_1.Logger, message, ...optionalParams);
115
+ };
134
116
  }
135
117
  catch {
136
- // Ignore errors if overrideLogger doesn't exist or fails
118
+ // Ignore patching errors to protect app stability
137
119
  }
138
120
  }
139
121
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngn-net/nestjs-telescope",
3
- "version": "0.2.10",
3
+ "version": "0.2.11",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },