fix(build): migrate project config to .smartconfig.json and replace smartfile usage with native fs
This commit is contained in:
44
readme.md
44
readme.md
@@ -254,6 +254,48 @@ logger.addLogDestination(receiver);
|
||||
|
||||
Logs are sent as authenticated JSON payloads with SHA-256 hashed passphrases.
|
||||
|
||||
#### 🧠 In-Memory Buffer
|
||||
|
||||
Keep a rolling, queryable window of recent log entries in memory — perfect for diagnostics dashboards, post-mortems, or exposing recent logs through a debug endpoint without writing them to disk:
|
||||
|
||||
```typescript
|
||||
import { SmartlogDestinationBuffer } from '@push.rocks/smartlog/destination-buffer';
|
||||
|
||||
// Default buffer holds 2000 entries (circular: oldest entries are evicted)
|
||||
const buffer = new SmartlogDestinationBuffer({ maxEntries: 5000 });
|
||||
logger.addLogDestination(buffer);
|
||||
|
||||
// Query recent entries (chronological order, oldest-first)
|
||||
const recent = buffer.getEntries({ limit: 100 });
|
||||
|
||||
// Filter by level (single or multiple)
|
||||
const errorsOnly = buffer.getEntries({ level: 'error' });
|
||||
const warningsAndErrors = buffer.getEntries({ level: ['warn', 'error'] });
|
||||
|
||||
// Filter by message content (case-insensitive search)
|
||||
const dbErrors = buffer.getEntries({ search: 'database' });
|
||||
|
||||
// Filter by timestamp (entries since a given moment)
|
||||
const sinceLastMinute = buffer.getEntries({ since: Date.now() - 60_000 });
|
||||
|
||||
// Pagination — limit + offset (offset counts back from the newest entry)
|
||||
const page = buffer.getEntries({ limit: 50, offset: 100 });
|
||||
|
||||
// Inspect or clear the buffer
|
||||
console.log(buffer.getEntryCount()); // current number of stored entries
|
||||
buffer.clear();
|
||||
```
|
||||
|
||||
Use it together with an HTTP endpoint to surface live, in-process logs for debugging:
|
||||
|
||||
```typescript
|
||||
app.get('/_debug/logs', (req, res) => {
|
||||
const level = req.query.level as any;
|
||||
const search = req.query.search as string;
|
||||
res.json(buffer.getEntries({ level, search, limit: 200 }));
|
||||
});
|
||||
```
|
||||
|
||||
### 🛠️ Custom Destinations
|
||||
|
||||
Build your own destination for any logging backend by implementing the `ILogDestination` interface:
|
||||
@@ -684,7 +726,7 @@ interface ILogPackage<T = unknown> {
|
||||
|
||||
## License and Legal Information
|
||||
|
||||
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE](./LICENSE) file.
|
||||
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [license](./license) file.
|
||||
|
||||
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user