@lognitor/browser
v1.0.2
Published
Lognitor SDK for browsers — log management, error tracking, and monitoring
Maintainers
Readme
@lognitor/browser
Official Lognitor SDK for browsers — log management, error tracking, and monitoring for web apps.
Install
npm install @lognitor/browserOr use the CDN:
<script src="https://unpkg.com/@lognitor/[email protected]/dist/umd/lognitor.min.js"></script>Quick Start
import Lognitor from '@lognitor/browser';
Lognitor.init({
apiKey: 'your-api-key',
service: 'my-website',
environment: 'production',
});
Lognitor.info('Page loaded', { metadata: { page: window.location.pathname } });CDN usage:
<script>
Lognitor.init({ apiKey: 'your-api-key', service: 'my-website' });
Lognitor.info('Page loaded');
</script>What's Captured Automatically
- Unhandled errors and promise rejections (
captureErrors: true) - Console errors/warnings (
captureConsole: true) - HTTP request breadcrumbs from
fetch()andXMLHttpRequest(captureFetch: true) - Session tracking with auto-generated session IDs
Log Levels
Lognitor.debug('Component rendered');
Lognitor.info('User signed in', { tags: ['auth'] });
Lognitor.warn('API response slow', { metadata: { duration: 3200 } });
Lognitor.error('Form submission failed', { error: new Error('Network error') });
Lognitor.fatal('App crashed');Error Tracking
try {
await riskyOperation();
} catch (err) {
Lognitor.captureException(err, { metadata: { context: 'checkout' } });
}User Context
Lognitor.setUser({ id: 'user_123', email: '[email protected]' });
Lognitor.clearUser();Configuration
| Option | Default | Description |
|---|---|---|
| apiKey | required | Project API key |
| service | — | Service name |
| environment | — | Environment |
| captureErrors | true | Capture unhandled errors |
| captureConsole | true | Capture console.error/warn |
| captureFetch | true | Add HTTP breadcrumbs |
| sessionTracking | true | Auto-generate session IDs |
| ignoreErrors | [] | Error patterns to ignore |
| batchSize | 25 | Logs per batch |
| flushInterval | 5000 | Auto-flush interval (ms) |
| maxRetries | 3 | Retry count |
| minLevel | null | Minimum level to send |
| redactPatterns | [] | PII patterns to redact |
| beforeSend | — | Transform/filter callback |
More
- Child loggers:
Lognitor.child({ service: 'checkout' }) - Timers:
const t = Lognitor.startTimer(); t.end('Done'); - Heartbeat:
Lognitor.heartbeat('token').ping() - Feedback dialog:
Lognitor.showReportDialog({ eventId: logId }) - Releases:
Lognitor.registerRelease({ version: '2.0' })
Full documentation: docs.lognitor.com
Compatibility
All modern browsers (Chrome, Firefox, Safari, Edge). IE11 not supported.
