YGLogger
Simple library for logging
Install
npm install --save yglogger
Logging
import * as yglogger from "yglogger";
const options: yglogger.LoggerOptions = {
console: {},
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);