Official SDK for Logzen - Connect your applications to Logzen's AI-powered log analysis platform
Official SDK for Logzen - Your AI-powered log analysis platform. Connect your applications to Logzen's powerful log analysis capabilities.
Logzen is an AI-powered log assistant that helps you connect and control your logs in real-time. This SDK enables you to integrate your applications with Logzen's powerful features:
- 🔍 Structured Logging - Send structured logs with custom fields
- 🤖 AI-Powered Analysis - Get smart insights and recommendations
- 🚨 Proactive Monitoring - Set alerts based on AI-detected patterns
- 🔄 Cursor Integration - Seamlessly connect with Cursor for enhanced log management
- 📝 Simple Integration - Easy-to-use SDK for connecting your applications
- 🔍 Structured Logging - Send structured logs with custom fields
- 🚀 Multiple Log Levels - debug, info, warn, and error levels
- 🛠️ Flexible Configuration - Configure once with sensible defaults
- 🌐 Browser & Node.js Compatible - Works in both environments
- 🧩 TypeScript Support - Full TypeScript type definitions
- 📊 Custom Fields Support - Attach any custom fields to your logs
- Console Interception - Automatically captures console.log calls (can be disabled)
``bash`
npm install @logzen-sdk/core
Add the following line to the .env file in your project:
`bash`Required
LOGZEN_API_KEY=your-api-key-here
Here's all you need to get started:
`typescript
import logzen from '@logzen-sdk/core';
// The API key is automatically picked up from your .env file
logzen.configure({
serviceName: 'my-service' // Required
});
// Start logging
logzen.info('Application started');
`
`typescript
import logzen from '@logzen-sdk/core';
// Configure with optional settings
logzen.configure({
serviceName: 'my-service', // Required
environment: 'production', // Optional
level: 'info', // Optional
endpoint: 'https://api.logzen.dev', // Optional, defaults to Logzen's production endpoint
debugConsole: true // Enable to see friendly status messages
});
// Use the logging methods
logzen.info('User logged in', {
userId: '123456',
role: 'admin'
});
// Log errors with context
logzen.error('Failed to process request', new Error('Network timeout'), {
requestId: 'req-123',
endpoint: '/api/users'
});
`
Add custom fields to your logs for better analysis:
`typescript
// Basic usage with custom fields
logzen.info('User logged in', {
userId: '123456',
role: 'admin',
loginAttempts: 1,
ipAddress: '192.168.1.1'
});
// Performance metrics
logzen.debug('Query executed', {
queryId: 'q-123',
durationMs: 253,
rowsReturned: 42,
cacheHit: false
});
`
`typescript
interface LogzenConfig {
// Required field
serviceName: string;
// Optional fields
environment?: string;
serviceVersion?: string;
level?: 'debug' | 'info' | 'warn' | 'error';
timestamp?: boolean;
prefix?: string;
interceptConsole?: boolean;
endpoint?: string;
apiKey?: string;
debug?: boolean;
debugConsole?: boolean; // Show friendly status messages
}
interface TelemetryConfig {
serviceName: string;
environment?: string;
apiKey?: string;
debugConsole?: boolean; // Show friendly status messages
// ...other options
}
`
Log errors with full context:
`typescript``
try {
throw new Error('Operation failed');
} catch (error) {
logzen.error('Failed to process request', error, {
requestId: '123abc',
userId: 'user_456'
});
}
MIT