Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

apiconnect-cli-logger

apimesh716SEE LICENSE IN LICENSE.txt3.0.0

Common logger for API Connect Toolkit CLI

readme

API Connect Toolkit logger

Basic usage

The logger supports the following levels:

  • debug
  • info
  • warning
  • error (or severe)
  • fatal

They are exposed as methods on the logger object and can be used as logger.info(...) etc.

Default Logging Streams

By default, logs are streamed to the console and to $APIC_CONFIG_PATH/apic.log. If $APIC_CONFIG_PATH is not set, it is logged to ~/.apiconnect/apic.log.

The console logging stream is prettified by the formatter stream in lib/formatter.js. To change the logging level of the console stream, you can set LOG_LEVEL.

The file logging stream consists of raw JSON logs. To see it in a readable format, you can run cat ~/.apiconnect/apic.log | bunyan. To change the logging level of the file stream, you can set FILE_LOG_LEVEL.

Configuring the logger

The logger can be customized with environment variables or a configuration file. The logger will look for a custom configuration file defined by APIC_LOG_CONFIG_FILE. If it does not exist, it looks in the default configuration directory: ~/.apiconnect/logger-config.js. The configuration file can be JSON or JS (.json/.js).

The default configuration is merged with user specified configuration, but the user specified configuration takes precedence. Default streams (stdout/file logger) cannot be replaced.

Supported Configuration

The configuration file is JSON based. You can configure the bunyan logger as well as the default bunyan filelogger stream.

bunyan: Refer to bunyan README.

filelogger:

key default description
size 50m The max file size of a log before rotation occurs. Supports 1024, 1k, 1m, 1g
keep 10 The number of rotated log files to keep (including the primary log file). Additional logs are deleted no rotation.
file ~/.apiconnect/apic.log The file log file to write data to.
compress false Optionally compress rotated files with gzip.

Sample Config

Sample JSON config file (.json):

{
  "bunyan": {
    "name": "custom logger",
    "src": "false",
    "streams": [{
      "level": "debug",
      "type": "file",
      "path": "custom_file.log"
    }]
  },
  "filelogger": {
    "size": "1K",
    "file": "custom.log",
    "keep": 5
  }
}

Sample JS config file (.js):

module.exports =
{
  bunyan: {
    name: 'userConnect',
    streams: [{
      level: 'debug',
      type: 'file',
      path: 'custom_file.log'
    }]
  },
  filelogger: {
    file: 'custom.log',
    size: '50M',
    keep: 10
  }
};

Note: If you have both logger-config.json and logger-config.js, the JSON file takes priority.

Console Output

The logger provides two methods to write to console logger.writeln and logger.write. Both these methods will write to stdout and log output to the log file.

Flushing logs

The logger provides logger.flush() and logger.exit(exitCode) methods which should be called before the CLI exits in order to ensure that all logs are written to disk. Both methods return a Promise object.

Environment variables

  • LOG_LEVEL specifies the lowest level of messages logged to the console stream.
    • deprecated APIC_LOG_CONSOLE_LEVEL
  • FILE_LOG_LEVEL specifies the lowest level of messages logged to the apic.log log file.
    • deprecated APIC_LOG_FILE_LEVEL
  • APIC_CONFIG_PATH specifies the directory path containing the system logging configuration file logger-config.json.
  • APIC_LOG_CONFIG_FILE specifies the path of the user-level logging configuration.

changelog

2020-12-28, Version 3.0.0

  • porting to node 14 (Hooman Moobed)

2019-05-10, Version 2.0.1

  • upgrade deps. (Ying Lu)

  • Fixing env variable (Hooman Moobed)

  • Fixing the issue with log capture (Hooman Moobed)

  • Support node 10, add jenkins, remove travis (Hooman Moobed)

2018-09-27, Version 1.3.3

  • remove pkglock.json (Hooman Moobed)

  • Adding support for node 8 (Hooman Moobed)

2018-06-11, Version 1.3.1

  • Drop node 4 (Ivy Ho)

  • update version (Ivy Ho)

  • Update engines to node 6 (Ivy Ho)

2017-10-24, Version 1.2.12

  • Delete notices.txt (Ivy Ho)

  • Delete non_ibm_license.txt (Ivy Ho)

2017-10-23, Version 1.2.11

  • Simplify License (Ivy Ho)

  • Update license files for 5080 release (Ryan Graham)

2017-06-27, Version 1.2.10

  • update license notices (Ryan Graham)

2017-06-19, Version 1.2.9

  • update license notices (Ryan Graham)

2017-04-14, Version 1.2.8

  • Fix copyright header in files (#38) (Krishna Raman)

2017-03-09, Version 1.2.7

  • Update license files (Krishna Raman)

2017-01-17, Version 1.2.6

  • Update license files (Ying Lu)

2017-01-13, Version 1.2.5

  • Remove deploy step from travis. (Rick Curtis)

2016-12-11, Version 1.2.4

  • Update license files (Krishna Raman)

2016-11-23, Version 1.2.3

2016-11-23, Version 1.2.2

  • Bulk update of travis.yml. (Rick Curtis)

  • Update travis and pckg.json to remove 012. (Rick Curtis)

2016-10-20, Version 1.2.1

  • Update license files (Krishna Raman)

2016-08-22, Version 1.2.0

  • Use spec reporter for tests. (Ying Lu)

  • Publish to CI registry using travis (Krishna Raman)

  • Remove hard coded config directory (Bosco Li)

2016-07-18, Version 1.1.1

  • Update engines to node >=0.12. (Rick Curtis)

  • Run coverage test on node v6. (Ying Lu)

2016-05-23, Version 1.1.0

  • fix readme bug (Sai Vennam)

  • simplify logger env vars (Sai Vennam)

  • json typo in README (Sai Vennam)

  • Use 'Error:' instead of 'ERROR' (Tetsuo Seto)

  • small readme updates (Sai Vennam)

  • new readme (Sai Vennam)

  • implement new rotating logger, add console output for config (Sai Vennam)

  • handle uncaught exceptions (Sai Vennam)

  • skip colorizing the message, use default instead (Sai Vennam)

  • Move to eslint 2.x (Krishna Raman)

2016-03-21, Version 1.0.1

  • First release!