import { appendFile } from 'fs/promises';
import { homedir } from 'os';
import { join } from 'path';
import type { NotificationOptions } from '../types/index.js';
const LOG_FILE = join(homedir(), '.mcp-notifications.log');
export async function logNotification(
options: NotificationOptions,
projectName: string,
error?: Error
): Promise<void> {
const timestamp = new Date().toISOString();
const logEntry = {
timestamp,
project: projectName,
type: options.type || 'info',
title: options.title,
message: options.message,
subtitle: options.subtitle,
error: error?.message,
};
const logLine = JSON.stringify(logEntry) + '\n';
try {
await appendFile(LOG_FILE, logLine, 'utf8');
} catch (err) {
console.error('Failed to write to log file:', err);
}
}
export function getLogPath(): string {
return LOG_FILE;
}