Writing own adapters

Acconut edited this page Aug 1, 2013 · 3 revisions
Clone this wiki locally

Writing an own adapter for Scrib is very easy. If you want an example have a look at scrib-local.

Each adapter itself is an own module which exports one function. This function is going to be called when Scrib is initialized with following arguments:

  • logger: A fresh Scrib instance to listen for events
  • options: A object containing options
  • callback: A function to call when you're done or when an error appears

When your adapter is initialized you want to check if all options are set and then add your listeners onto logger. When you finished you should call the callback.

Important: Make sure your callback is called async else we can't access the logger in your parent:

function Adapter(logger, options, callback) {
    // BAD
    callback();

    // GOOD
    fs.createWriteStream().on("open", callback);
    process.nextTick(callback);
}

Example

This adapter will print the logs into process.stdout using console.log:

function Adapter(logger, options, callback) {

    logger.on("log", function(m) {
        console.log(
            "%s [%s]: %s",
            m.id,
            m.category,
            m.message);
        console.log(m.data);

    process.nextTick(callback);
}

module.exports = Adapter;

When you're finished you can open a pull request to add your adapter to our list.