log4js-node-extension-autoreload

1.0.2 • Public • Published

log4js-node-extension-autoreload

A simple function to make log4js file configuration auto-reload work again

Install

npm install --save log4js-node-extension-autoreload

How to Use

Example:

var log4js = require('log4js');
var log4jsAutoreload = require('log4js-node-extension-autoreload');

log4jsAutoreload(log4js, 'log4jsconf.json', { reloadSecs: 5 });

var log = log4js.getLogger();

setInterval(function() {
  log.debug('this is debug');
  log.info('this is info');
}, 1000);

Support javascript template configuration

{
  "appenders": {
    "cheese": {
      "type": "file",
      "filename": "${process.cwd()}/logs/app.log",
      "maxLogSize": 10485760,
      "backups": 10
    },
    "out": {
      "type": "stdout"
    }
  },
  "categories": {
    "default": { "appenders": ["cheese", "out"], "level": "debug" }
  }
}

The Cause

From log4js 2, the autoreload support have been removed. Refer to here.

This package implement a simple wrapper function to use watchr to provide the support of autoreload when configuration file be updated.

Note:

If you are using file appender, you'd better set the filename to be a absolute path, because if you use relative path, it will relative to the CWD(current work directory). In some case, especially when develop, it will be the path of this package(under the node_modules) which invoke the log4js.configure.

Package Sidebar

Install

npm i log4js-node-extension-autoreload

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

15.1 kB

Total Files

6

Last publish

Collaborators

  • imhazige