@cn-npm/logtrace
TypeScript icon, indicating that this package has built-in type declarations

1.0.9 • Public • Published

Charity Navigator Logging and Tracing library

This NPM module exposes common logging and tracing support used by Charity Navigator apps and services. The source is written in Typescript, but it produces both Typescript and CommonJS modules in the lib directory when published to NPM.

Installation

After cloning the repo, run:

npm install

You will need to define the following environment variables to run the honeycomb tests:

HONEYCOMB_API_KEY=<YOUR_API_KEY>
HONEYCOMB_SERVICE_NAME="logtrace"
HONEYCOMB_DATASET="TEST-logtrace"

Building and publishing the library

To compile the project locally run:

npm run tsc

This will compile the typescript modules and place them in the \lib directory.

To run the tests, run:

npm run test

This should run test scripts for logging and honeycomb tracing.

To publish the library to NPM, do the following:

Bump the version in package.json. If you don't do this, the publish will fail because that version has been published prior.

npm publish

Internally this will call the prePublish command in package.json which will build both Typescript and CommonJS (to support plain Javascript) versions of the library, then publish the package to NPM.

Usage

To use the module in your application, do the following:

npm install @cn-npm/logtrace --save

Then in your code, import the logging module:

Typescript:

import { LogProvider } from '@cn-npm/logtrace';

const logger = LogProvider.getLogger("test");

logger.log("hello world");

logger.error("hello error");

logger.debug("hello debug");

Javascript:

const { LogProvider } = require("@cn-npm/logtrace");

const logger = LogProvider.getLogger("test");

logger.log("hello world");

logger.error("hello error");

logger.debug("hello debug");

Or import the tracing module:

Typescript:

import { Trace } from '@cn-npm/logtrace';

Trace.start(
  process.env.HONEYCOMB_API_KEY || "",
  process.env.HONEYCOMB_SERVICE_NAME || "",
  process.env.HONEYCOMB_DATASET || "",
  process.env.HONEYCOMB_DATASET_METRICS || "",
);

Javascript:

const { Trace } = require("@cn-npm/logtrace");

Trace.start(
  process.env.HONEYCOMB_API_KEY || "",
  process.env.HONEYCOMB_SERVICE_NAME || "",
  process.env.HONEYCOMB_DATASET || "",
  process.env.HONEYCOMB_DATASET_METRICS || "",
);

Readme

Keywords

none

Package Sidebar

Install

npm i @cn-npm/logtrace

Weekly Downloads

31

Version

1.0.9

License

ISC

Unpacked Size

55 kB

Total Files

51

Last publish

Collaborators

  • ha7ka1
  • melshaabiny
  • djboulia-cn