@pedrocid/music-mcp
Version:
MCP server for controlling Apple Music on macOS (v1.0.5)
68 lines (67 loc) • 2.61 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.logger = void 0;
const pino_1 = __importDefault(require("pino"));
const path_1 = require("path");
const os_1 = __importDefault(require("os"));
// Create logger with stderr output (for Claude Desktop) and optional file logging
function createLogger() {
const targets = [];
// Try to add stderr logging with pino-pretty, fallback to basic stderr
try {
targets.push({
target: 'pino-pretty',
options: {
destination: 2, // stderr
colorize: false,
translateTime: true
}
});
}
catch (error) {
// Fallback to basic stderr logging without pino-pretty
targets.push({
target: 'pino/file',
options: { destination: 2 }
});
}
// Only add file logging in development or if explicitly requested
if (process.env.NODE_ENV === 'development' || process.env.MUSIC_MCP_FILE_LOGGING === 'true') {
const logFile = process.env.MUSIC_MCP_LOG_FILE ||
`${os_1.default.homedir()}/Library/Logs/music-mcp.log`;
try {
// Ensure log directory exists synchronously
const logDir = (0, path_1.dirname)(logFile);
require('fs').mkdirSync(logDir, { recursive: true });
targets.push({
target: 'pino/file',
options: { destination: logFile }
});
}
catch (error) {
// If file logging fails, continue with just stderr
console.error(`Warning: Could not setup file logging: ${error instanceof Error ? error.message : String(error)}`);
}
}
try {
return (0, pino_1.default)({
level: (process.env.MUSIC_MCP_LOG_LEVEL || 'info').toLowerCase(),
transport: { targets }
});
}
catch (error) {
// Ultimate fallback to basic console logging
console.error(`Warning: Could not create advanced logger, using console: ${error instanceof Error ? error.message : String(error)}`);
return (0, pino_1.default)({
level: (process.env.MUSIC_MCP_LOG_LEVEL || 'info').toLowerCase()
});
}
}
exports.logger = createLogger();
// Ensure flush on exit
process.on('exit', () => exports.logger.flush());
process.on('SIGINT', () => exports.logger.flush());
process.on('SIGTERM', () => exports.logger.flush());