0

Do you have an idea on how to monkey patch the node js bunyan methods like info, debug by using shimmer(https://www.npmjs.com/package/shimmer) ?

For example, this is my bunyan configuration:

let bunyanLog = require('bunyan')
let bunyanOpts = {
  name : "bunyan-logging",
  level : "debug"
}

let bunyanLogger = bunyanLog.createLogger(bunyanOpts)

So, in my app I can call

bunyanLogger.info('info message') // output: info message

I want to monkey patch this bunyanLogger.info() by adding another functionality. So when executing the bunyanLogger.info() we also send a Facebook/Slack notifications.

I could not find articles or tutorials in the net about monkey patching the bunyan. Thanks!

Arman Ortega
  • 3,003
  • 1
  • 30
  • 28
  • Try [this](https://www.npmjs.com/package/bunyan-sql-stream). You can configure bunyan to log to a database using streams. – Carlo Corradini Jul 02 '20 at 13:27
  • @CarloCorradini I'm sorry but I don't want to use any 3rd party libraries. I want to have a solution by using monkey patching for **flexibility reason**. Thanks. – Arman Ortega Jul 02 '20 at 13:29
  • 1
    The code is very simple, you can copy and make your changes to it. See the source(one file | 50 lines) at [this](https://github.com/fdesjardins/bunyan-sql-stream/blob/master/index.js) link. – Carlo Corradini Jul 02 '20 at 13:37
  • 1
    Looks like the bunyan module itself does not expose an `info()` method, but you always have to instantiate a logger. Can you modify the `bunyan.createLogger()` call? If you can, then it's easy to sneak in a custom stream class that does things. – AKX Jul 02 '20 at 13:39

0 Answers0