Skip to content

Northern-Breeze/GoatLogger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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;

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published