hapi-smart-logs

Smart Logger for HapiJs latest version

Usage no npm install needed!

<script type="module">
  import hapiSmartLogs from 'https://cdn.skypack.dev/hapi-smart-logs';
</script>

README

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();