npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

apiconnect-cli-logger

v3.0.0

Published

Common logger for API Connect Toolkit CLI

Downloads

256

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.