@tenonhq/sincronia-core 0.0.65 → 0.0.66

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,3 +1,4 @@
1
+ "use strict";
1
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
2
3
  if (k2 === undefined) k2 = k;
3
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -34,171 +35,67 @@ var __importStar = (this && this.__importStar) || (function () {
34
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
35
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
36
37
  };
37
- (function (factory) {
38
- if (typeof module === "object" && typeof module.exports === "object") {
39
- var v = factory(require, exports);
40
- if (v !== undefined) module.exports = v;
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.fileLogger = void 0;
40
+ exports.enableFileLogging = enableFileLogging;
41
+ const fs = __importStar(require("fs"));
42
+ const path = __importStar(require("path"));
43
+ const chalk_1 = __importDefault(require("chalk"));
44
+ class FileLogger {
45
+ logFilePath;
46
+ logStream = null;
47
+ initialized = false;
48
+ constructor() {
49
+ // Initialize on first use
50
+ this.logFilePath = "";
41
51
  }
42
- else if (typeof define === "function" && define.amd) {
43
- define(["require", "exports", "fs", "path", "chalk"], factory);
44
- }
45
- })(function (require, exports) {
46
- "use strict";
47
- Object.defineProperty(exports, "__esModule", { value: true });
48
- exports.fileLogger = void 0;
49
- exports.enableFileLogging = enableFileLogging;
50
- const fs = __importStar(require("fs"));
51
- const path = __importStar(require("path"));
52
- const chalk_1 = __importDefault(require("chalk"));
53
- class FileLogger {
54
- logFilePath;
55
- logStream = null;
56
- initialized = false;
57
- constructor() {
58
- // Initialize on first use
59
- this.logFilePath = "";
52
+ /**
53
+ * Initialize the file logger in the current working directory
54
+ */
55
+ initialize() {
56
+ if (this.initialized)
57
+ return;
58
+ const timestamp = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
59
+ const logFileName = `sincronia-debug-${timestamp}.log`;
60
+ // Create log file in the current working directory (ServiceNow folder)
61
+ this.logFilePath = path.join(process.cwd(), logFileName);
62
+ try {
63
+ // Create or append to the log file
64
+ this.logStream = fs.createWriteStream(this.logFilePath, { flags: 'a' });
65
+ this.initialized = true;
66
+ // Write header to log file
67
+ this.writeToFile(`\n${"=".repeat(80)}`);
68
+ this.writeToFile(`Sincronia Debug Log - Started at ${new Date().toISOString()}`);
69
+ this.writeToFile(`Log file: ${this.logFilePath}`);
70
+ this.writeToFile(`Working directory: ${process.cwd()}`);
71
+ this.writeToFile(`${"=".repeat(80)}\n`);
72
+ // Also log to console
73
+ console.log(chalk_1.default.cyan(`📝 Debug logging enabled: ${this.logFilePath}`));
60
74
  }
61
- /**
62
- * Initialize the file logger in the current working directory
63
- */
64
- initialize() {
65
- if (this.initialized)
66
- return;
67
- const timestamp = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
68
- const logFileName = `sincronia-debug-${timestamp}.log`;
69
- // Create log file in the current working directory (ServiceNow folder)
70
- this.logFilePath = path.join(process.cwd(), logFileName);
71
- try {
72
- // Create or append to the log file
73
- this.logStream = fs.createWriteStream(this.logFilePath, { flags: 'a' });
74
- this.initialized = true;
75
- // Write header to log file
76
- this.writeToFile(`\n${"=".repeat(80)}`);
77
- this.writeToFile(`Sincronia Debug Log - Started at ${new Date().toISOString()}`);
78
- this.writeToFile(`Log file: ${this.logFilePath}`);
79
- this.writeToFile(`Working directory: ${process.cwd()}`);
80
- this.writeToFile(`${"=".repeat(80)}\n`);
81
- // Also log to console
82
- console.log(chalk_1.default.cyan(`📝 Debug logging enabled: ${this.logFilePath}`));
83
- }
84
- catch (error) {
85
- console.error(chalk_1.default.red(`Failed to create log file: ${error}`));
86
- }
75
+ catch (error) {
76
+ console.error(chalk_1.default.red(`Failed to create log file: ${error}`));
87
77
  }
88
- /**
89
- * Write a message to the log file
90
- */
91
- writeToFile(message) {
92
- if (!this.initialized) {
93
- this.initialize();
94
- }
95
- if (this.logStream && this.logStream.writable) {
96
- const timestamp = new Date().toISOString();
97
- this.logStream.write(`[${timestamp}] ${message}\n`);
98
- }
99
- }
100
- /**
101
- * Format a message for both console and file output
102
- */
103
- formatMessage(level, message, ...args) {
104
- let fullMessage = message;
105
- // If there are additional arguments, stringify them
106
- if (args.length > 0) {
107
- const additionalInfo = args.map(arg => {
108
- if (typeof arg === 'object') {
109
- try {
110
- return JSON.stringify(arg, null, 2);
111
- }
112
- catch {
113
- return String(arg);
114
- }
115
- }
116
- return String(arg);
117
- }).join(' ');
118
- fullMessage = `${message} ${additionalInfo}`;
119
- }
120
- return fullMessage;
121
- }
122
- /**
123
- * Debug level logging - file only, no console output
124
- */
125
- debug(message, ...args) {
126
- const formattedMessage = this.formatMessage('DEBUG', message, ...args);
127
- this.writeToFile(`[DEBUG] ${formattedMessage}`);
128
- }
129
- /**
130
- * Info level logging
131
- */
132
- info(message, ...args) {
133
- const formattedMessage = this.formatMessage('INFO', message, ...args);
134
- // Write to console with color
135
- console.log(chalk_1.default.blue(message), ...args);
136
- // Write to file
137
- this.writeToFile(`[INFO] ${formattedMessage}`);
138
- }
139
- /**
140
- * Warning level logging
141
- */
142
- warn(message, ...args) {
143
- const formattedMessage = this.formatMessage('WARN', message, ...args);
144
- // Write to console with color
145
- console.log(chalk_1.default.yellow(message), ...args);
146
- // Write to file
147
- this.writeToFile(`[WARN] ${formattedMessage}`);
148
- }
149
- /**
150
- * Error level logging
151
- */
152
- error(message, ...args) {
153
- const formattedMessage = this.formatMessage('ERROR', message, ...args);
154
- // Write to console with color
155
- console.error(chalk_1.default.red(message), ...args);
156
- // Write to file
157
- this.writeToFile(`[ERROR] ${formattedMessage}`);
158
- }
159
- /**
160
- * Success level logging
161
- */
162
- success(message, ...args) {
163
- const formattedMessage = this.formatMessage('SUCCESS', message, ...args);
164
- // Write to console with color
165
- console.log(chalk_1.default.green(message), ...args);
166
- // Write to file
167
- this.writeToFile(`[SUCCESS] ${formattedMessage}`);
168
- }
169
- /**
170
- * Close the log file stream
171
- */
172
- close() {
173
- if (this.logStream) {
174
- this.writeToFile(`\n${"=".repeat(80)}`);
175
- this.writeToFile(`Log session ended at ${new Date().toISOString()}`);
176
- this.writeToFile(`${"=".repeat(80)}\n`);
177
- this.logStream.end();
178
- this.logStream = null;
179
- this.initialized = false;
180
- }
78
+ }
79
+ /**
80
+ * Write a message to the log file
81
+ */
82
+ writeToFile(message) {
83
+ if (!this.initialized) {
84
+ this.initialize();
181
85
  }
182
- /**
183
- * Get the path to the current log file
184
- */
185
- getLogFilePath() {
186
- return this.logFilePath;
86
+ if (this.logStream && this.logStream.writable) {
87
+ const timestamp = new Date().toISOString();
88
+ this.logStream.write(`[${timestamp}] ${message}\n`);
187
89
  }
188
90
  }
189
- // Create singleton instance
190
- const fileLogger = new FileLogger();
191
- exports.fileLogger = fileLogger;
192
- // Also export a function to replace console.log globally
193
- function enableFileLogging() {
194
- // Store original console.log
195
- const originalConsoleLog = console.log;
196
- // Override console.log to also write to file
197
- console.log = function (...args) {
198
- // Call original console.log
199
- originalConsoleLog.apply(console, args);
200
- // Also write to file
201
- const message = args.map(arg => {
91
+ /**
92
+ * Format a message for both console and file output
93
+ */
94
+ formatMessage(level, message, ...args) {
95
+ let fullMessage = message;
96
+ // If there are additional arguments, stringify them
97
+ if (args.length > 0) {
98
+ const additionalInfo = args.map(arg => {
202
99
  if (typeof arg === 'object') {
203
100
  try {
204
101
  return JSON.stringify(arg, null, 2);
@@ -209,9 +106,102 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
209
106
  }
210
107
  return String(arg);
211
108
  }).join(' ');
212
- fileLogger.debug(message);
213
- };
214
- // Log that file logging is enabled
215
- fileLogger.info('File logging has been enabled for this session');
109
+ fullMessage = `${message} ${additionalInfo}`;
110
+ }
111
+ return fullMessage;
216
112
  }
217
- });
113
+ /**
114
+ * Debug level logging - file only, no console output
115
+ */
116
+ debug(message, ...args) {
117
+ const formattedMessage = this.formatMessage('DEBUG', message, ...args);
118
+ this.writeToFile(`[DEBUG] ${formattedMessage}`);
119
+ }
120
+ /**
121
+ * Info level logging
122
+ */
123
+ info(message, ...args) {
124
+ const formattedMessage = this.formatMessage('INFO', message, ...args);
125
+ // Write to console with color
126
+ console.log(chalk_1.default.blue(message), ...args);
127
+ // Write to file
128
+ this.writeToFile(`[INFO] ${formattedMessage}`);
129
+ }
130
+ /**
131
+ * Warning level logging
132
+ */
133
+ warn(message, ...args) {
134
+ const formattedMessage = this.formatMessage('WARN', message, ...args);
135
+ // Write to console with color
136
+ console.log(chalk_1.default.yellow(message), ...args);
137
+ // Write to file
138
+ this.writeToFile(`[WARN] ${formattedMessage}`);
139
+ }
140
+ /**
141
+ * Error level logging
142
+ */
143
+ error(message, ...args) {
144
+ const formattedMessage = this.formatMessage('ERROR', message, ...args);
145
+ // Write to console with color
146
+ console.error(chalk_1.default.red(message), ...args);
147
+ // Write to file
148
+ this.writeToFile(`[ERROR] ${formattedMessage}`);
149
+ }
150
+ /**
151
+ * Success level logging
152
+ */
153
+ success(message, ...args) {
154
+ const formattedMessage = this.formatMessage('SUCCESS', message, ...args);
155
+ // Write to console with color
156
+ console.log(chalk_1.default.green(message), ...args);
157
+ // Write to file
158
+ this.writeToFile(`[SUCCESS] ${formattedMessage}`);
159
+ }
160
+ /**
161
+ * Close the log file stream
162
+ */
163
+ close() {
164
+ if (this.logStream) {
165
+ this.writeToFile(`\n${"=".repeat(80)}`);
166
+ this.writeToFile(`Log session ended at ${new Date().toISOString()}`);
167
+ this.writeToFile(`${"=".repeat(80)}\n`);
168
+ this.logStream.end();
169
+ this.logStream = null;
170
+ this.initialized = false;
171
+ }
172
+ }
173
+ /**
174
+ * Get the path to the current log file
175
+ */
176
+ getLogFilePath() {
177
+ return this.logFilePath;
178
+ }
179
+ }
180
+ // Create singleton instance
181
+ const fileLogger = new FileLogger();
182
+ exports.fileLogger = fileLogger;
183
+ // Also export a function to replace console.log globally
184
+ function enableFileLogging() {
185
+ // Store original console.log
186
+ const originalConsoleLog = console.log;
187
+ // Override console.log to also write to file
188
+ console.log = function (...args) {
189
+ // Call original console.log
190
+ originalConsoleLog.apply(console, args);
191
+ // Also write to file
192
+ const message = args.map(arg => {
193
+ if (typeof arg === 'object') {
194
+ try {
195
+ return JSON.stringify(arg, null, 2);
196
+ }
197
+ catch {
198
+ return String(arg);
199
+ }
200
+ }
201
+ return String(arg);
202
+ }).join(' ');
203
+ fileLogger.debug(message);
204
+ };
205
+ // Log that file logging is enabled
206
+ fileLogger.info('File logging has been enabled for this session');
207
+ }