Skip to content

Latest commit

 

History

History
50 lines (38 loc) · 1022 Bytes

README.md

File metadata and controls

50 lines (38 loc) · 1022 Bytes

GoatLogger

Simple logging library

Install

npm
    $ npm install goatlogger

yarn

    $ yarn add goatlogger

How to use

Directly in controllers or routes handlers

    import { BasicLogger } from 'goatlogger';

    app.get('/foo', (req, res) => {
        BasicLogger.info('foo', { someKey: 'SomeValue' }) // the object is optional
        res.send('from foo)
    })

Namespace logging

Middleware

    import { Request, Response, NextFunction} from 'express';
    import { BasicLogger } from 'goatlogger';

    const loggerMiddleware = ((req: Request, res: Response, next: NextFunction) => {
    /** Log the request */
    const method = request.method;
    const IP = req.socket.remoteAddress;
    const statusCode = res.statusCode;
    const url = req.protocol + '://' + req.get('host') + req.originalUrl;
    response.on('finish', () => {
        BasicLogger.log(method , IP, url);
    });

    next();

    })
    export default loggerMiddleware;