ms365-mcp-server
Version:
Microsoft 365 MCP Server for managing Microsoft 365 email through natural language interactions with full OAuth2 authentication support
44 lines (43 loc) • 1.43 kB
JavaScript
import * as fs from 'fs';
import * as path from 'path';
import * as os from 'os';
// Debug log file path
const LOG_FILE = path.join(os.tmpdir(), 'ms365-mcp-server.log');
/**
* Simple logging utility for MS365 MCP Server
*/
export class Logger {
constructor() {
this.debugMode = false;
this.debugMode = process.argv.includes('--debug') || process.env.DEBUG === 'true';
}
log(message, ...args) {
const timestamp = new Date().toISOString();
const logMessage = `${timestamp} [INFO] ${message}`;
if (this.debugMode) {
console.error(logMessage, ...args);
}
this.writeToFile(logMessage, ...args);
}
error(message, error) {
const timestamp = new Date().toISOString();
const logMessage = `${timestamp} [ERROR] ${message}`;
if (this.debugMode) {
console.error(logMessage, error);
}
this.writeToFile(logMessage, error);
}
writeToFile(message, ...args) {
try {
let fullMessage = message;
if (args.length > 0) {
fullMessage += ' ' + args.map(arg => typeof arg === 'object' ? JSON.stringify(arg) : String(arg)).join(' ');
}
fs.appendFileSync(LOG_FILE, fullMessage + '\n');
}
catch (err) {
// Silently fail if we can't write to log file
}
}
}
export const logger = new Logger();