项目作者: IBM

项目描述 :
node-log4js-logmet-appender
高级语言: JavaScript
项目地址: git://github.com/IBM/node-log4js-logmet-appender.git
创建时间: 2017-04-21T14:09:33Z
项目社区:https://github.com/IBM/node-log4js-logmet-appender

开源协议:MIT License

下载


node-log4js-logmet-appender Build Status

Logmet appender for node-log4js

Installation

  1. npm i log4js-logmet-appender --save

Configuration

Set the following environment variables:

  1. export log4js_logmet_enabled=true
  2. export log4js_logmet_component=otc-api-local-test
  3. export log4js_logmet_logging_token=<secureToken>
  4. export log4js_logmet_space_id=<yourSpaceId>
  5. export log4js_logmet_logging_host=logs.stage1.opvis.bluemix.net
  6. export log4js_logmet_logging_port=9091

To get the secure token and space id see the instructions here: https://pages.github.ibm.com/alchemy-logmet/getting-started/authentication.html

Usage

You must be using log4js-node 3.x or 4.x, and must call log4js.configure('/path/to/log4js.json')
somewhere in your code.

You must add the following to the list of appenders in your log4js.json file:

  1. {
  2. "appenders": {
  3. "logmet": {
  4. "type": "log4js-logmet-appender",
  5. }
  6. },
  7. "categories": {
  8. "default": { "appenders": [ "logmet" ], "level": "info" },
  9. }
  10. }

The appender supports custom layouts, the default layout function used is:

  1. let layout = (logEvent) => {
  2. let instanceId = process.env.CF_INSTANCE_INDEX || require('os').hostname().replace(/^.*-([a-zA-Z0-9]+-[a-zA-Z0-9]+)$/g,'$1');
  3. let logmetEvent = {
  4. 'component': process.env.log4js_logmet_component || config.component,
  5. 'host-ip': process.env.CF_INSTANCE_IP,
  6. 'instance-id': instanceId,
  7. 'loglevel': logEvent.level.levelStr,
  8. 'msg_timestamp': logEvent.startTime.toISOString(),
  9. 'message': logEvent.data.join(' | '),
  10. 'type': logEvent.categoryName
  11. };
  12. return logmetEvent;
  13. };

Each key will mapped to a field name in Logmet.

Pending work

No automated tests currently

License

The MIT License (MIT)

Contributing

Contributions are welcome via Pull Requests. Please submit your very first Pull Request against the Developer’s Certificate of Origin, adding a line like the following to the end of the file… using your name and email address of course!

  1. Signed-off-by: John Doe <john.doe@example.org>