Wondering what’s next for npm?Check out our public roadmap! »

    architect-log4js

    4.0.0 • Public • Published

    architect-log4js

    Expose log4js as architect service.

    Installation

    npm install --save architect-log4js

    Config Format

    {
      "packagePath": "architect-log4js",
      "config": {
        appenders: {
          out: { type: 'console' }
        },
        categories: {
          default: { appenders: [ 'out' ], level: 'info' }
        }
      }
    }
     
    }

    Usage

    Boot Architect :

    var path = require('path');
    var architect = require("architect");
     
    var configPath = path.join(__dirname, "config.js");
    var config = architect.loadConfig(configPath);
     
    architect.createApp(config, function (err, app) {
        if (err) {
            throw err;
        }
        //app.services.log is avaliable now
        var log = app.services.log.getLogger('app');
        log.info('application started');
    });

    Configure Log4js Architect service with config.js :

    module.exports = [{
        packagePath: "architect-log4js",
        config: {
          appenders: [
            { type: "console" }
          ],
          replaceConsole: true
        }
    }, './routes'];

    config object is passed to log4js.configure method. See log4js configuration for more options.

    Consume log service in your application :

    {
      "name": "routes",
      "version": "0.0.1",
      "main": "index.js",
      "private": true,
     
      "plugin": {
        "consumes": ["log"]
      }
    }

    Eventually use the log service in your app :

    module.exports = function setup(options, imports, register) {
        var logger = imports.log.getLogger(); //get default logger
        log.info('plugin initialized.');
        register();
    };

    request logger

    This module provides a log request feature that is not available in log4js itself.

    Example :

        rest.get('/', function(req, res) {
            var logger = imports.log.requestLogger(req).getLogger(); //get default logger
            log.info('plugin initialized.');
        });

    This will produce :

    [2015-02-06 16:03:54.329] [INFO] - [/] plugin initialized.
    

    options

    • request.property : request property to log defaults to 'url'.
    • request.format : {string} message format defaults to '[%s] %s', where first placeholder is the request property and the second is the actual message.

    Install

    npm i architect-log4js

    DownloadsWeekly Downloads

    1

    Version

    4.0.0

    License

    Apache License Version 2.0

    Unpacked Size

    18.8 kB

    Total Files

    6

    Last publish

    Collaborators

    • avatar