@lognitor/node
v1.0.2
Published
Lognitor SDK for Node.js — log management, error tracking, and monitoring
Maintainers
Readme
@lognitor/node
Official Lognitor SDK for Node.js — log management, error tracking, and monitoring.
Install
npm install @lognitor/nodeQuick Start
import Lognitor from '@lognitor/node';
Lognitor.init({
apiKey: 'your-api-key', // Get from https://dashboard.lognitor.com
service: 'my-api',
environment: 'production',
version: '1.0.0',
});
Lognitor.info('Server started', { metadata: { port: 3000 } });Also works with namespace and destructured imports:
import * as Lognitor from '@lognitor/node';
import { init, info, error } from '@lognitor/node';Log Levels
Lognitor.debug('Cache hit', { metadata: { key: 'users:123' } });
Lognitor.info('User signed in', { tags: ['auth'] });
Lognitor.warn('Slow query', { perf: { duration_ms: 3200 } });
Lognitor.error('Payment failed', { error: new Error('Card declined'), notify: true });
Lognitor.fatal('Database unreachable');Every log method returns a log ID (UUID) for feedback linking.
Error Tracking
try {
await processOrder(order);
} catch (err) {
Lognitor.captureException(err, {
metadata: { orderId: order.id },
tags: ['critical'],
});
}Errors are automatically deduplicated and fingerprinted.
User Context
Lognitor.setUser({ id: 'user_123', email: '[email protected]', name: 'Alice' });
Lognitor.clearUser();Breadcrumbs
Lognitor.addBreadcrumb({
type: 'http',
category: 'api',
message: 'GET /api/users 200',
level: 'info',
data: { duration_ms: 45 },
});Breadcrumbs auto-attach to error and fatal logs.
Framework Integrations
Express
import { createExpressMiddleware } from '@lognitor/node';
app.use(createExpressMiddleware(client, { ignoreRoutes: ['/health'] }));Fastify
import { createFastifyPlugin } from '@lognitor/node';
fastify.register(createFastifyPlugin(client));Hono
import { createHonoMiddleware } from '@lognitor/node';
app.use('*', createHonoMiddleware(client));Next.js
import { createNextjsWrapper } from '@lognitor/node';
const withLognitor = createNextjsWrapper(client);
export const GET = withLognitor(async (req) => Response.json({ ok: true }));NestJS
import { LognitorModule } from '@lognitor/node';
@Module({ imports: [LognitorModule.forRoot({ apiKey: '...' })] })
export class AppModule {}Configuration
| Option | Default | Description |
|---|---|---|
| apiKey | required | Project API key |
| service | — | Service name |
| environment | — | Environment (production, staging, etc) |
| version | — | App version |
| batchSize | 25 | Logs per batch |
| flushInterval | 5000 | Auto-flush interval (ms) |
| maxRetries | 3 | Retry count for failed requests |
| maxQueueSize | 1000 | Max buffered logs |
| minLevel | null | Minimum level to send |
| enabled | true | Master switch |
| debug | false | Print SDK debug messages |
| autoTruncate | false | Truncate oversized payloads |
| maxBreadcrumbs | 100 | Breadcrumb buffer size |
| redactPatterns | [] | PII patterns: 'email', 'creditCard', 'ssn', 'bearer', or custom RegExp |
| scrubUrlParams | [...] | URL query params to scrub |
| beforeSend | — | (log) => log or return null to drop |
More
- Child loggers:
Lognitor.child({ service: 'payments', tags: ['billing'] }) - Timers:
const t = Lognitor.startTimer(); t.end('Done'); - Heartbeat:
Lognitor.heartbeat('token').wrap(async () => { ... }) - Releases:
Lognitor.registerRelease({ version: '2.0', commitHash: 'abc' }) - Feedback:
Lognitor.submitFeedback({ eventId: logId, comments: '...' })
Full documentation: docs.lognitor.com
Compatibility
Node.js 16+. Uses native fetch on Node 18+, node:http fallback on Node 16.
