@ngn-net/nestjs-telescope 0.2.9 → 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.9",
4
- "builtAt": "2026-06-08T12:45:39.623Z"
3
+ "version": "0.2.11",
4
+ "builtAt": "2026-06-08T12:52:50.170Z"
5
5
  }
@@ -27,38 +27,96 @@ let LogWatcher = class LogWatcher {
27
27
  const originalDebug = console.debug.bind(console);
28
28
  const self = this;
29
29
  const formatArgs = (args) => args.map((a) => (typeof a === 'object' ? JSON.stringify(a) : String(a))).join(' ');
30
- const recordLog = (level, args) => {
31
- // Guard: if we're already recording, skip to prevent infinite recursion
32
- // (recording a log → save to DB → TypeORM logs → recording again → ...)
30
+ const recordConsoleLog = (level, args) => {
33
31
  if (self.isRecording)
34
32
  return;
33
+ const message = formatArgs(args);
34
+ // Skip telescope queries, logs, or dashboard routes to prevent recursion
35
+ if (message.includes('telescope_entries') || message.includes('TelescopeModule')) {
36
+ return;
37
+ }
35
38
  self.isRecording = true;
36
39
  try {
37
40
  self.telescope.record({
38
41
  type: entry_type_enum_1.EntryType.LOG,
39
- content: { level, message: formatArgs(args) },
40
- });
42
+ content: { level, message },
43
+ }).catch(() => { });
41
44
  }
42
45
  finally {
43
46
  self.isRecording = false;
44
47
  }
45
48
  };
49
+ // 1. Intercept raw console logs
46
50
  console.log = function (...args) {
47
- recordLog('log', args);
51
+ recordConsoleLog('log', args);
48
52
  return originalLog(...args);
49
53
  };
50
54
  console.error = function (...args) {
51
- recordLog('error', args);
55
+ recordConsoleLog('error', args);
52
56
  return originalError(...args);
53
57
  };
54
58
  console.warn = function (...args) {
55
- recordLog('warn', args);
59
+ recordConsoleLog('warn', args);
56
60
  return originalWarn(...args);
57
61
  };
58
62
  console.debug = function (...args) {
59
- recordLog('debug', args);
63
+ recordConsoleLog('debug', args);
60
64
  return originalDebug(...args);
61
65
  };
66
+ // 2. Intercept NestJS static Logger methods directly
67
+ try {
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
+ };
116
+ }
117
+ catch {
118
+ // Ignore patching errors to protect app stability
119
+ }
62
120
  }
63
121
  };
64
122
  exports.LogWatcher = LogWatcher;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngn-net/nestjs-telescope",
3
- "version": "0.2.9",
3
+ "version": "0.2.11",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },