pino_custom_transport

Custom Pino Transport

Usage no npm install needed!

<script type="module">
  import pinoCustomTransport from 'https://cdn.skypack.dev/pino_custom_transport';
</script>

README

Pino Custom Module.

Error Objects should be the first parameter ** Stringified error object will be '{}''


const MODULENAME = process.env.__MODULENAME || require('../package.json').name;
const logger = require('pino_custom_transport')(MODULENAME);

module.exports = logger;



Sample Outputs:

process.env.NODE_ENV='production';
const logger = require('pino_custom_transport')('module1');


process.on('uncaughtException', logger.fatal.bind(logger));




let err = new Error('error Object');
logger.info(err, 'error message 1', 'error message 2');
/* Sample output 1
{
    "level": 30,
    "time": 1565612382898,
    "pid": 37060,
    "hostname": "macs-iMac-3.local",
    "__module": "module1",
    "msg": "error message 1 error message 2",
    "stack": "Error: error Object\n    at Object.<anonymous> (/Users/asl/Workspace/todel/index.js:10:11)\n    at Module._compile (module.js:653:30)\n    at Object.Module._extensions..js (module.js:664:10)\n    at Module.load (module.js:566:32)\n    at tryModuleLoad (module.js:506:12)\n    at Function.Module._load (module.js:498:3)\n    at Function.Module.runMain (module.js:694:10)\n    at startup (bootstrap_node.js:204:16)\n    at bootstrap_node.js:625:3",
    "type": "Error",
    "v": 1
}

 */

logger.info('error message 1', 'error message 2', err);

/* Sample output 2

{
    "level": 30,
    "time": 1565612447549,
    "pid": 37131,
    "hostname": "macs-iMac-3.local",
    "__module": "module1",
    "msg": "error message 1 error message 2 {}",
    "v": 1
}

*/

logger.info('ok ', 'ok again ', {
    msg: 'custom error object will be fine'
});

/* Sample output 3
{
    "level": 30,
    "time": 1565612595276,
    "pid": 37230,
    "hostname": "macs-iMac-3.local",
    "__module": "module1",
    "msg": "ok  ok again  {\"msg\":\"custom error object will be fine\"}",
    "v": 1
}
*/

logger.info({
    msg: 'this message will be overriden with the next ones',
    thisid: 'will be there'
}, 'hey again ', ' hey thrree');

/* Sample output 4
{
    "level": 30,
    "time": 1565612693667,
    "pid": 37320,
    "hostname": "macs-iMac-3.local",
    "__module": "module1",
    "msg": "hey again   hey thrree",
    "thisid": "will be there",
    "v": 1
}
*/

logger.info('one ', 'two ', 'three ', 'four ', 'five ', 'six ');
/* Sample output 6
{
    "level": 30,
    "time": 1565612721233,
    "pid": 37346,
    "hostname": "macs-iMac-3.local",
    "__module": "module1",
    "msg": "one  two  three  four  five  six ",
    "v": 1
}
 */