src/middleware.js
function morganMiddleware(req, res, next) {
    const { ignoreRouteUrls, includeReqHeaders, omitReqProperties } = getConfig('logger');
    const { format } = getConfig('logger.morgan');
    // define custom tokens
    morgan.token('operation-hash', request => get(request, 'body.extensions.persistentQuery.sha256Hash'));
    morgan.token('operation-name', request => get(request, 'body.operationName'));
    morgan.token('user-id', request => get(request, 'locals.user.id'));
    morgan.token('company-id', request => get(request, 'locals.user.companyId'));
    morgan.token('message', request => request.name || '-');
    morgan.token('request-id', request => request.id);
    morgan.token('request-headers', (request) => {
        const headers = includeReqHeaders === true
            ? omit(request.headers, omitReqProperties) : {};
        return JSON.stringify(headers);
    });

    const logger = getContainer('logger');
    const formatFormat = json(format);
    const options = {
        stream: asStream(logger),
        skip: skip(ignoreRouteUrls),
    };
    return morgan(formatFormat, options)(req, res, next);
}
function morganMiddleware(req, res, next) {
    const { ignoreRouteUrls, includeReqHeaders, omitReqProperties } = getConfig('logger');
    const { format } = getConfig('logger.morgan');
    // define custom tokens
    morgan.token('operation-hash', request => get(request, 'body.extensions.persistentQuery.sha256Hash'));
    morgan.token('operation-name', request => get(request, 'body.operationName'));
    morgan.token('user-id', request => get(request, 'locals.user.id'));
    morgan.token('company-id', request => get(request, 'locals.user.companyId'));
    morgan.token('message', request => request.name || '-');
    morgan.token('request-id', request => request.id);
    morgan.token('request-headers', (request) => {
        const headers = includeReqHeaders === true
            ? omit(request.headers, omitReqProperties) : {};
        return JSON.stringify(headers);
    });

    const logger = getContainer('logger');
    const formatFormat = json(format);
    const options = {
        stream: asStream(logger),
        skip: skip(ignoreRouteUrls),
    };
    return morgan(formatFormat, options)(req, res, next);
}
function morganMiddleware ( req , res , next ) { const { ignoreRouteUrls , includeReqHeaders , omitReqProperties } = getConfig ( 'logger' ) ; const { format } = getConfig ( 'logger.morgan' ) ; // define custom tokens morgan . token ( 'operation-hash' , request => get ( request , 'body.extensions.persistentQuery.sha256Hash' ) ) ; morgan . token ( 'operation-name' , request => get ( request , 'body.operationName' ) ) ; morgan . token ( 'user-id' , request => get ( request , 'locals.user.id' ) ) ; morgan . token ( 'company-id' , request => get ( request , 'locals.user.companyId' ) ) ; morgan . token ( 'message' , request => request . name || '-' ) ; morgan . token ( 'request-id' , request => request . id ) ; morgan . token ( 'request-headers' , ( request ) => { const headers = includeReqHeaders === true ? omit ( request . headers , omitReqProperties ) : { } ; return JSON . stringify ( headers ) ; } ) ; const logger = getContainer ( 'logger' ) ; const formatFormat = json ( format ) ; const options = { stream : asStream ( logger ) , skip : skip ( ignoreRouteUrls ) , } ; return morgan ( formatFormat , options ) ( req , res , next ) ; }
Use morgan library to log every HTTP response Also set req._startAt - that is used by the logger
Use morgan library to log every HTTP response Also set req . _startAt - that is used by the logger