enhance security and performance: add rate limiting, session validation, and logging; update environment variables
Some checks failed
Build Images and Deploy / Update-PROD-Stack (push) Failing after 8s
Some checks failed
Build Images and Deploy / Update-PROD-Stack (push) Failing after 8s
This commit is contained in:
42
src/utils/logger.js
Normal file
42
src/utils/logger.js
Normal file
@@ -0,0 +1,42 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const logsDir = path.join(process.env.DATA_PATH || './data', 'logs');
|
||||
if (!fs.existsSync(logsDir)) {
|
||||
fs.mkdirSync(logsDir, { recursive: true });
|
||||
}
|
||||
|
||||
const logger = {
|
||||
info: (message, meta = {}) => {
|
||||
const logEntry = {
|
||||
timestamp: new Date().toISOString(),
|
||||
level: 'info',
|
||||
message,
|
||||
...meta
|
||||
};
|
||||
console.log(JSON.stringify(logEntry));
|
||||
},
|
||||
|
||||
error: (message, error = null, meta = {}) => {
|
||||
const logEntry = {
|
||||
timestamp: new Date().toISOString(),
|
||||
level: 'error',
|
||||
message,
|
||||
error: error ? { message: error.message, stack: error.stack } : null,
|
||||
...meta
|
||||
};
|
||||
console.error(JSON.stringify(logEntry));
|
||||
},
|
||||
|
||||
warn: (message, meta = {}) => {
|
||||
const logEntry = {
|
||||
timestamp: new Date().toISOString(),
|
||||
level: 'warn',
|
||||
message,
|
||||
...meta
|
||||
};
|
||||
console.warn(JSON.stringify(logEntry));
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = logger;
|
||||
Reference in New Issue
Block a user