Skip to content
nomiddlename edited this page Jun 1, 2012 · 2 revisions

The hook.io appender was added to log4js by dbrain. This allows multiple worker processes to log through a single master process, avoiding issues with rolling etc. in a clustered environment. This was mainly created for cluster, but you can adapt the example to match your needs, you know, if it fits them.

    // log4js-master.json
    {
      "appenders": [{
        "type": "logLevelFilter",
        "level": "DEBUG",
        "appender": {
          "type": "hookio",
          "name": "hookio-logger",
          "mode": "master",
          "debug": false,
          "appender": {
            "type": "file",
            "filename": "muffin.log",
            "maxLogSize": 104857600,
            "backups": 10,
            "pollInterval": 15
          }
        }
      }]
    }

    // log4js-worker.json
    {
      "appenders": [{
        "type": "logLevelFilter",
        "level": "DEBUG",
        "appender": {
          "type": "hookio",
          "name": "hookio-logger",
          "mode": "worker",
          "debug": false
        }
      }]
    }

    // ilikebeans.js 
    var cluster = require('cluster');
    var hookCluster = cluster('./doyoulikebeans');

    // Perform the once off configuration depending on type of cluster
    if (hookCluster.isMaster) {
      require('log4js').configure('log4js-master.json');
    } else {
      require('log4js').configure('log4js-worker.json');
    }

    // Standard cluster startup
    hookCluster
      .use(cluster.logger('run/logs'))
      .use(cluster.pidfiles('run/pids'))
      .listen(3000);

log4js-master/worker.json hookio appender parameters will be passed into the Hook constructor directly, so you can specify hook-port, hook-host etc.

NOTE: hook.io appender will currently (and probably indefinitely) explode if you enable hook.io debug because of the way log4js overrides console.log (if you have that feature enabled)

Clone this wiki locally