logpilot-ai
v1.0.32
Published
LogPilot: Instantly watch, analyze, and explain your Node.js app errors with AI. Real-time log monitoring, LLM-powered insights, and a dashboard—zero code changes required.
Readme
logpilot-ai
logpilot-ai is an intuitive Node.js tool that watches your application logs, detects errors in real time, and generates insightful, human-readable explanations using LLMs (Claude via AWS Bedrock or OpenAI). It also provides a dashboard and alerting system for seamless monitoring.
Features
- Real-time log watching and error detection
- LLM-powered explanations and suggested fixes
- Dashboard for incident review
- Email alerting (optional)
- Plug-and-play: no code changes required
- Configurable via
.envfile
Installation
npm install logpilot-aiQuick Start
- Add a
.envfile to your project root:
# For Bedrock (default)
AWS_ACCESS_KEY_ID=your-access-key
AWS_SECRET_ACCESS_KEY=your-secret-key
AWS_REGION=your-aws-region # e.g., ap-south-1
BEDROCK_MODEL_ID=your-bedrock-model-id # e.g., apac.anthropic.claude-3-5-sonnet-20240620-v1:0
# For OpenAI
# OPENAI_API_KEY=your-openai-api-key
# OPENAI_MODEL=gpt-4o # or gpt-3.5-turbo, etc.
INCIDENTS_MAX_MB=5 # (optional, default 5MB)
DELETE_INCIDENTS_ON_EXIT=true # (optional, default is not set; set to true to auto-delete incidents.json on exit)- Update your
package.jsonscripts:
If your app entry point is app.js:
"scripts": {
"start": "npx logpilot-ai --auto --run \"node app.js\""
}- Start your app as usual:
npm start- logpilot-ai will run your app, watch its output, analyze errors, and start the dashboard automatically.
Configuration
All configuration is via environment variables in your .env file:
| Variable | Description | |-------------------------|---------------------------------------------| | AWS_ACCESS_KEY_ID | Your AWS access key (Bedrock only) | | AWS_SECRET_ACCESS_KEY | Your AWS secret key (Bedrock only) | | AWS_REGION | AWS region (Bedrock only) | | BEDROCK_MODEL_ID | Bedrock Claude model ID (Bedrock only) | | OPENAI_API_KEY | OpenAI API key (OpenAI only) | | OPENAI_MODEL | OpenAI model name (OpenAI only) | | INCIDENTS_MAX_MB | Max incidents file size in MB (default: 5) | | DASHBOARD_PORT | Dashboard port (default: 3001) | | DELETE_INCIDENTS_ON_EXIT| If true, incidents.json is deleted when you stop logpilot-ai |
AI Provider Selection and Installation
After installing, run the following command to select your AI provider (AWS Bedrock or OpenAI):
npx logpilot-ai-setupNote: Both AI provider dependencies (
openaiand@aws-sdk/client-bedrock-runtime) are installed with logpilot-ai, but only the one you select will be used at runtime. You do not need to install them manually or worry about extra dependencies in your own project.
Switching AI Providers
You can switch your AI provider at any time by running:
npx logpilot-ai-setupFollow the prompt and then update your .env file with the credentials for your new provider.
Dashboard
- The dashboard runs on a separate port (default: 3001). If port 3001 is in use, set
DASHBOARD_PORTin your.envfile to change it. Visithttp://localhost:<your-port>to view incidents and explanations.
Programmatic Error Capture
If you want to log errors directly from your code (for example, in a catch block), you can use logpilot-ai's capture API:
const { capture } = require('logpilot-ai/api');
try {
// some code that may throw
} catch (err) {
console.log('Error caught:', err);
capture(err, 'Critical'); // or 'Error', 'Exception', 'Fail', etc.
}This will print the error and stack to the terminal, allowing logpilot-ai to detect and explain it in real time.
Advanced Usage
- Watch a log file instead of process output:
npx logpilot-ai --auto --watch path/to/your.log - Start only the dashboard:
npx logpilot-ai --dashboard
Security
- Do NOT commit your
.envfile to version control. - Credentials are only read from your local
.envfile.
Troubleshooting
- If incidents are not being recorded, check your
.envvalues and ensure your app outputs errors to stdout/stderr. - If the incidents file grows too large, it will be auto-cleared when it exceeds the configured size.
- If you set
DELETE_INCIDENTS_ON_EXIT=truein your.env, the incidents file (incidents.json) will be automatically deleted when you stop logpilot-ai (Ctrl+C or process exit).
License
ISC
For more details, see the source code or open an issue.
Keywords
log monitoring, error analysis, AI, LLM, Claude, Bedrock, OpenAI, dashboard, Node.js, logpilot-ai, observability, incident response, developer tools
