
Security News
npm ‘is’ Package Hijacked in Expanding Supply Chain Attack
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
@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
The npm package @azure-iot/logging receives a total of 1 weekly downloads. As such, @azure-iot/logging popularity was classified as not popular.
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
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
Security News
A critical flaw in the popular npm form-data package could allow HTTP parameter pollution, affecting millions of projects until patched versions are adopted.
Security News
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.