logsentinel-node
v1.0.2
Published
A high-performance, asynchronous logging transport for Node.js.
Downloads
274
Maintainers
Readme
# LogStream Logger 🚀
A high-performance, asynchronous logging transport for Node.js applications.
Designed for speed and reliability, this package automatically batches your logs and sends them to your centralized dashboard without blocking your main event loop. It silently handles network failures to ensure your application never crashes due to logging errors.
## ✨ Features
- **Non-Blocking Architecture:** Logs are queued in memory and flushed asynchronously.
- **Auto-Batching:** Reduces HTTP requests by grouping multiple logs together.
- **Context Enrichment:** Automatically appends system data (`hostname`, `platform`).
- **Fail-Safe Design:** Network errors are caught silently; your app stays up even if the logging server goes down.
- **First-Class TypeScript Support:** Fully typed out of the box.
## 📦 Installation
```bash
npm install logstream-logger
# or
yarn add logstream-logger
🚀 Quick Start
Initialize the logger once in your application and use it anywhere.
import { Logger } from 'logstream-logger';
// 1. Initialize the Logger
const logger = new Logger({
apiKey: 'your_project_api_key_here',
endPoint: 'https://api.logsentinel.com/ingest', // Your SaaS ingestion URL
});
// 2. Send Logs
logger.info('User successfully authenticated', { userId: '12345' });
logger.error('Database connection failed', { code: 'ECONNREFUSED' });
⚙️ Configuration Options
When instantiating the Logger, you can pass the following configuration object:
| Property | Type | Default | Description |
| --- | --- | --- | --- |
| apiKey | string | Required | The API key generated from your project dashboard. |
| endPoint | string | Required | The ingestion URL where logs will be sent. |
| batchSize | number | 10 | The maximum number of logs to hold in memory before forcing a flush. |
| flushInterval | number | 2000 | Time (in milliseconds) to wait before flushing the queue, regardless of batch size. |
Example: Custom Configuration
const logger = new Logger({
apiKey: process.env.LOGSTREAM_API_KEY,
endPoint: 'https://api.logsentinel.com/ingest',
batchSize: 50, // Send in batches of 50
flushInterval: 5000, // Or send every 5 seconds
});
📖 API Reference
All logging methods accept a message (string) and an optional metadata (object) payload.
logger.info(message, [metadata])
Standard informational logs.
logger.info('Payment processed', { amount: 49.99, currency: 'USD' });
logger.error(message, [metadata])
Critical system errors or unhandled exceptions.
logger.error('Failed to charge card', { error: err.message, transactionId: 'txn_987' });
logger.warn(message, [metadata])
Warning messages for unexpected behavior that isn't strictly an error.
logger.warn('Rate limit approaching', { remainingRequests: 5 });
logger.debug(message, [metadata])
Detailed information primarily useful during development.
logger.debug('Cache miss, fetching from DB', { queryTime: '45ms' });
🔒 Security & Privacy
This logger uses standard HTTPS requests via Axios. Ensure that you do not pass highly sensitive information (like plaintext passwords or full credit card numbers) in the metadata object.
