yglogger
TypeScript icon, indicating that this package has built-in type declarations

0.0.6 • Public • Published

YGLogger

Simple library for logging

Install

npm install --save yglogger

Logging

import * as yglogger from "yglogger";

const options: yglogger.LoggerOptions = {
  // Presence enables console logging
  console: {},
  // Presence enables file logging
  file: {}
};

var logger = yglogger.createLogger({ name: "myApp", version: "1.0" }, options);

logger.info("This is just for information");
logger.warn("Something went wrong", {
  duration: 21.12,
  correlationId: "abc123"
});

Express middleware

app.use(telemetry.initExpressMiddleware(logger));

Passing custom log properties

Use res.locals.logProperties to expose custom properties to the telemetry middleware.

const telemetryLogProperties = (req: express.Request, res: express.Response, next: express.NextFunction) => {
  res.locals.logProperties = {
    originalUrl: req.originalUrl
  };
  next();
};
const telemetryMiddleware = yglogger.initExpressMiddleware(logger);

app.use(telemetryLogProperties, telemetryMiddleware);

Utility functions

Use getCorrelationId() to maintain persistent correlation ID inside a single request.

const correlationId = getCorrelationId(req);

Readme

Keywords

none

Package Sidebar

Install

npm i yglogger

Weekly Downloads

0

Version

0.0.6

License

UNLICENSED

Unpacked Size

33 kB

Total Files

50

Last publish

Collaborators

  • andreidubov