Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@azure-iot/logging

Package Overview
Dependencies
Maintainers
28
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@azure-iot/logging

Client and server side logging library

  • 1.0.0-rc.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
28
Created
Source

@azure-iot/logging

A wrapper aroung the Bunyan logging library that can be run either in a browser or on a Node.JS server.

Development

Clone and run npm install.

Installation

npm install --save @azure-iot/logging

Usage

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.

Loggers

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 */));

Middleware (server only)

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

Package last updated on 31 May 2016

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc