npm.io
1.2.7 • Published 1 month ago

hapi-smart-logs

Licence
ISC
Version
1.2.7
Deps
2
Size
30 kB
Vulns
0
Weekly
0

hapi-smart-logs

Enables smart logging for a hapijs app based on config.

Default Options:

{
    reverseProxyIPHeaders: ['x-real-ip'],
    timestamp: false,
    logSlowRequests: false,
    requestLevel: 'short'
}

Example:

'use strict'

const Hapi = require('hapi');

const server = Hapi.server({
    host: 'localhost',
    port: 3000
});

server.route({
    method: 'GET',
    path: '/hello',
    handler: function(request, h) {
        return h.response({greeting: "Hello there!"});
    }
});

const start = async function() {
    try {
        await server.register({
            plugin: require('hapi-smart-logs'),
            options: {
                reverseProxyIPHeaders: 'X-Forwarded-For'
            }
        })

        await server.start();
    } catch(err) {
        console.log(err);
        process.exit(1);
    }
};

start();

Keywords