edgesync360-edgehub-logbook-nodejs-sdk
v1.0.0
Published
EdgeHub LogHub SDK for Node.js (JavaScript)
Readme
edgesync360-edgehub-logbook-nodejs-sdk
A standardized logging SDK for Node.js, fully aligned with the LogHub Golang implementation. Designed for audit compliance (CRA, IEC 62443) and consistent observability across microservices.
Features
- Standardized Format: Automatic generation of
log_id(UUID),tr_id(TraceID), andv(Version). - Audit Ready: Strictly validated fields for Users, Tenants, Services, and Resources.
- Fluent API: Clean
withXstyle chaining for log building. - Request Context Support: Built-in
AsyncLocalStoragesupport for automatic field propagation across asynchronous operations. - Resource Indexing: Automated updates to MongoDB resource index for better observability.
Installation
npm install edgesync360-edgehub-logbook-nodejs-sdkUsage
Basic Usage
const { LogClient, SERVICE, SOURCE, RESOURCETYPE, RESULT } = require("edgesync360-edgehub-logbook-nodejs-sdk");
const client = new LogClient(mongoAdapter, {
serviceName: SERVICE.DPM,
source: SOURCE.EDGE,
version: "1.0"
});
await client.info("Device connected")
.withTenant("T1", "Tenant Name")
.withUser("[email protected]")
.withAction("DEVICE.CONNECT", "Connect Device")
.withResource(RESOURCETYPE.DEVICE, "D123", "Sensor-01")
.withResult(RESULT.SUCCESS)
.write();Scoped Logging (Recommended)
Use ScopedClient to avoid passing common fields manually.
// In your middleware or request handler
await client.runWithScope({
tenantID: "T1",
userEmail: "[email protected]",
traceID: "..."
}, async () => {
// Inside any downstream service
const logger = client.getScopedClient();
await logger.info("Inherits context automatically").write();
});License
MIT
