yglogger
v0.0.6
Published
Simple library for logging
Downloads
4
Readme
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);