Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@azure-iot/logging
Advanced tools
A wrapper aroung the Bunyan logging library that can be run either in a browser or on a Node.JS server.
Clone and run npm install
.
npm install --save @azure-iot/logging
This package exposes two different versions of the same interface, one for browser (client) and one for server.
Client Module - '@azure-iot/logging/client'
Server Module - '@azure-iot/logging/server'
The server version can be imported using ES6 or AMD(Node.JS) syntax, such as:
import {BunyanLogger} from '@azure-iot/logging/server';
The client package is bundled using SystemJS syntax and can be included using the following script import:
<script src="node_modules/@azure-iot/logging/client/client.js"></script>
From there, you can import into your SystemJS modules or using ES6 syntax in TypeScript
with the module
compiler flag set to system
.
To use either package, you need to import the BunyanLogger
class and whichever
events you want to be able to log. The BunyanLogger
class accepts the same
object with its constructor as
bunyan.createLogger()
.
See below for an example.
import {BunyanLogger, PageView} from '@azure-iot/logging/server';
let logger = new BunyanLogger({
name: 'my-app',
streams: [{
level: 'trace',
stream: process.stdout
}]
});
logger.informational(new PageView(/* Params */));
The server variant of the module also provides middleware for Express applications
that can be used to automatically log IncomingServiceRequest and Exception events
for server routes. You can access this functionality with the ExpressMiddleware
class using the following methods:
ExpressMiddleware.logISR(logger, operationName, operationVersion);
Applied as middleware on each route you want to log. Accepts the logger to use, as well as the name and version of the operation to be used for logging
ExpressMiddleware.logExceptions(logger);
Applied as error handling middleware at the end of the application, logging all uncaught exceptions. It should be applied on the application after all other middleware and routes but potentially before other error handling middleware.
Example
import {BunyanLogger, ExpressMiddleware} from '@azure-iot/logging/server';
import * as express from 'express';
let logger = new BunyanLogger({
name: 'my-app',
streams: [{
level: 'trace',
stream: process.stdout
}]
});
let app = express();
app.get('/users', ExpressMiddleware.logISR(logger, 'GetUsers', '1.0'));
// IMPORTANT: This must be declared after other middleware and routes
app.use(ExpressMiddleware.logExceptions(logger));
app.listen(3000, () => {
console.log('App is running');
});
FAQs
Client and server side logging library
We found that @azure-iot/logging demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 28 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.