MCPcopy Create free account
hub / github.com/PSPDFKit/nutrient-document-engine-mcp-server / writeLog

Method writeLog

src/utils/Logger.ts:72–104  ·  view source on GitHub ↗
(logLevel: MCPLogLevel, mcpServer: McpServer | null, message: string, context?: unknown)

Source from the content-addressed store, hash-verified

70 }
71
72 writeLog(logLevel: MCPLogLevel, mcpServer: McpServer | null, message: string, context?: unknown) {
73 const isServerConnected = mcpServer?.isConnected();
74 const isStdIOMode = this.transportType === 'stdio';
75
76 // Send to server notifications when connected
77 if (isServerConnected) {
78 const params: LoggingMessageNotification['params'] = {
79 level: logLevel,
80 data: `[${this.serviceName}] ${message}`,
81 };
82
83 try {
84 mcpServer!.server.sendLoggingMessage(params);
85 } catch {
86 // Fall through to console fallback if notification fails
87 }
88 }
89
90 if (this.shouldServerLog(logLevel)) {
91 const logLine = this.formatLogEntry(logLevel, message, context);
92 // Console output handling based on mode and connection status
93 if (isStdIOMode) {
94 process.stderr.write(logLine + '\n');
95 } else {
96 // HTTP mode: write to stderr for errors, stdout for other log levels
97 if (['warning', 'error', 'critical', 'alert', 'emergency'].includes(logLevel)) {
98 process.stderr.write(logLine + '\n');
99 } else {
100 process.stdout.write(logLine + '\n');
101 }
102 }
103 }
104 }
105
106 // Tier 1 convenience methods
107 debug(mcpServer: McpServer | null, message: string, context?: unknown) {

Callers 8

debugMethod · 0.95
infoMethod · 0.95
noticeMethod · 0.95
warningMethod · 0.95
errorMethod · 0.95
criticalMethod · 0.95
alertMethod · 0.95
emergencyMethod · 0.95

Calls 2

shouldServerLogMethod · 0.95
formatLogEntryMethod · 0.95

Tested by

no test coverage detected