system_logs
Read system logs from journalctl or log files to monitor infrastructure services and troubleshoot issues in Kubernetes, Docker, and other systems.
Instructions
Read system logs from journalctl or a log file
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| unit | No | Systemd unit name (e.g., 'nginx', 'docker') | |
| lines | No | Number of lines to show (default: 50) | |
| path | No | Path to a log file (alternative to journalctl) |
Implementation Reference
- src/tools/system/logs.ts:7-34 (handler)The handler implementation for the 'system_logs' tool. It either reads a local file or queries journalctl.
export async function systemLogs(args: Record<string, unknown>): Promise<string> { const unit = args.unit as string | undefined; const lines = (args.lines as number) || 50; const path = args.path as string | undefined; // If a file path is given, read from file if (path) { try { const content = await readFile(path, "utf-8"); const allLines = content.trim().split("\n"); const lastN = allLines.slice(-lines); return `Logs from '${path}' (last ${lastN.length} lines):\n\n${lastN.join("\n")}`; } catch (error: any) { throw new Error(`Failed to read log file: ${error.message}`); } } // Otherwise use journalctl try { const jArgs = ["--no-pager", `-n${lines}`]; if (unit) jArgs.push("-u", unit); const { stdout } = await execFileAsync("journalctl", jArgs, { timeout: 15000 }); return `System logs${unit ? ` (${unit})` : ""} (last ${lines} lines):\n\n${stdout.trim()}`; } catch (error: any) { throw new Error(`Failed to read system logs: ${error.message}`); } } - src/tools/system/index.ts:40-50 (schema)Schema definition for 'system_logs' tool.
name: "system_logs", description: "Read system logs from journalctl or a log file", inputSchema: { type: "object" as const, properties: { unit: { type: "string", description: "Systemd unit name (e.g., 'nginx', 'docker')" }, lines: { type: "number", description: "Number of lines to show (default: 50)" }, path: { type: "string", description: "Path to a log file (alternative to journalctl)" }, }, }, }, - src/tools/system/index.ts:63-63 (registration)Routing of the 'system_logs' tool in handleSystemTool.
case "system_logs": return systemLogs(a);