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

@kirinus-digital/express-logger

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kirinus-digital/express-logger

Implementation of an express.js logger using winston and express-winston.

  • 0.0.16
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
2
Weekly downloads
 
Created
Source

express-logger

Implementation of an express.js logger using winston and express-winston.

Installation

yarn add @kirinus-digital/express-logger

Usage

import {
  createExpressWinstonHandler,
  createWinstonLogger,
  httpContextMiddleware,
  requestIdHandler,
} from '@kirinus-digital/express-logger';

Basic Example

index.ts:

import * as express from 'express';

import { init as loggerInit, logger } from './logger';

const app = express() as express.Application;
loggerInit(app);

const port = 3000;
app.listen(port, () => {
  logger.debug(`App: Listening on port ${port}!`);
});

logger/index.ts:

import { Application } from 'express';

import {
  WinstonLogger,
  createExpressWinstonHandler,
  createWinstonLogger,
  httpContextMiddleware,
  requestIdHandler,
} from '@kirinus-digital/express-logger';

export let logger: WinstonLogger;

export function init(app: Application): void {
  this.logger = createWinstonLogger('app');
  // Use express-winston for logging request information
  const expressWinstonHandler = createExpressWinstonHandler(this.logger);
  app.use(expressWinstonHandler);
  // Use express-http-context for context injection (request id)
  app.use(httpContextMiddleware);
  app.use(requestIdHandler);
}

/middleware/logger.middleware.ts:

import { NextFunction, Request, Response } from 'express';

import { logger } from '../logger';

export function loggerMiddleware(req: Request, _: Response, next: NextFunction): void {
  logger.debug(`${req.method} ${req.path}`);
  next();
}

Keywords

FAQs

Package last updated on 01 Jul 2021

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