@universis/access-log
v2.1.0
Published
An express middleware for creating apache-like access logs
Downloads
383
Maintainers
Readme
@universis/access-log
An express middleware for creating apache-like access logs
Install
npm i @universis/access-logUsage
Use accessLog middleware:
import express from 'express';
import {accessLog} from '@universis/access-log';
# create application
app = express()
# register access log middleware
app.use(accessLog({
filename: 'access.log',
format: 'combined',
interval: '1d'
}));The available options are the same as the options of rotating-file-stream package with an additional format property that accepts a string or a function that returns a string. The format property is used to specify the format of the access log. The default value is combined. You can read more about the available formats in the morgan documentation.
or use AccessLogger service when an @themost/common#ApplicationBase instance is available:
import express from 'express';
import {AccessLogger} from '@universis/access-log';
# create application
app = express()
# create an instance of ExpressDataApplication
const dataApplication = new ExpressDataApplication();
# register access log service
dataApplication.useService(AccessLogger);
// register access log middleware
app.use(dataApplication.getService(AccessLogger).middleware());