Fix jwt-token
This commit is contained in:
@@ -1,37 +1,57 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
|
// Singleton instance
|
||||||
|
let loggerInstance = null;
|
||||||
|
|
||||||
class ApiDebugLogger {
|
class ApiDebugLogger {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
// Return existing instance if already created
|
||||||
|
if (loggerInstance) {
|
||||||
|
return loggerInstance;
|
||||||
|
}
|
||||||
|
|
||||||
// Use mounted volume directory that's accessible from host
|
// Use mounted volume directory that's accessible from host
|
||||||
this.logFile = '/app/debug_logs/api_debug.log';
|
this.logFile = '/app/debug_logs/api_debug.log';
|
||||||
this.enabled = process.env.NODE_ENV === 'development' || process.env.API_DEBUG === 'true';
|
this.enabled = process.env.NODE_ENV === 'development' || process.env.API_DEBUG === 'true';
|
||||||
this.fileLoggingEnabled = false;
|
this.fileLoggingEnabled = false;
|
||||||
|
this.initialized = false;
|
||||||
|
|
||||||
// Debug logging setup
|
// Debug logging setup (only run once)
|
||||||
if (this.enabled) {
|
if (this.enabled && !this.initialized) {
|
||||||
console.log(`🐛 ApiDebugLogger: Enabled (NODE_ENV=${process.env.NODE_ENV}, API_DEBUG=${process.env.API_DEBUG})`);
|
console.log(`🐛 ApiDebugLogger: Enabled (NODE_ENV=${process.env.NODE_ENV}, API_DEBUG=${process.env.API_DEBUG})`);
|
||||||
console.log(`🐛 ApiDebugLogger: Log file path: ${this.logFile}`);
|
console.log(`🐛 ApiDebugLogger: Log file path: ${this.logFile}`);
|
||||||
|
|
||||||
// Ensure the debug_logs directory exists
|
// Ensure the debug_logs directory exists
|
||||||
try {
|
try {
|
||||||
const fs = require('fs');
|
|
||||||
const debugDir = '/app/debug_logs';
|
const debugDir = '/app/debug_logs';
|
||||||
if (!fs.existsSync(debugDir)) {
|
if (!fs.existsSync(debugDir)) {
|
||||||
fs.mkdirSync(debugDir, { recursive: true });
|
fs.mkdirSync(debugDir, { recursive: true });
|
||||||
console.log(`🐛 ApiDebugLogger: Created debug logs directory at ${debugDir}`);
|
console.log(`🐛 ApiDebugLogger: Created debug logs directory at ${debugDir}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only create the file if it doesn't exist, otherwise just append
|
||||||
|
if (!fs.existsSync(this.logFile)) {
|
||||||
fs.writeFileSync(this.logFile, `# API Debug Log Started at ${new Date().toISOString()}\n`);
|
fs.writeFileSync(this.logFile, `# API Debug Log Started at ${new Date().toISOString()}\n`);
|
||||||
|
console.log(`🐛 ApiDebugLogger: Created new log file`);
|
||||||
|
} else {
|
||||||
|
fs.appendFileSync(this.logFile, `\n# API Debug Log Session Started at ${new Date().toISOString()}\n`);
|
||||||
|
console.log(`🐛 ApiDebugLogger: Appending to existing log file`);
|
||||||
|
}
|
||||||
|
|
||||||
this.fileLoggingEnabled = true;
|
this.fileLoggingEnabled = true;
|
||||||
|
this.initialized = true;
|
||||||
console.log(`🐛 ApiDebugLogger: File logging enabled at ${this.logFile} (mounted to host: ./debug_logs/)`);
|
console.log(`🐛 ApiDebugLogger: File logging enabled at ${this.logFile} (mounted to host: ./debug_logs/)`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn(`⚠️ ApiDebugLogger: File logging disabled - using console only. Error: ${error.message}`);
|
console.warn(`⚠️ ApiDebugLogger: File logging disabled - using console only. Error: ${error.message}`);
|
||||||
this.fileLoggingEnabled = false;
|
this.fileLoggingEnabled = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else if (!this.enabled) {
|
||||||
console.log(`🐛 ApiDebugLogger: Disabled (NODE_ENV=${process.env.NODE_ENV}, API_DEBUG=${process.env.API_DEBUG})`);
|
console.log(`🐛 ApiDebugLogger: Disabled (NODE_ENV=${process.env.NODE_ENV}, API_DEBUG=${process.env.API_DEBUG})`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Store the singleton instance
|
||||||
|
loggerInstance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
log(method, url, statusCode, requestBody = {}, responseBody = {}, headers = {}) {
|
log(method, url, statusCode, requestBody = {}, responseBody = {}, headers = {}) {
|
||||||
|
|||||||
Reference in New Issue
Block a user