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

typescript-logging

v2.2.0

Published

TypeScript Logging core written in and to be used by TypeScript (this is the core project, you need to install a flavor too).

Downloads

140,468

Readme

TypeScript Logging

TypeScript logging can be used to add logging to your web or node project.

Version 2 of typescript-logging has been written from scratch and is not compatible with version 1 (see migration).

There are two different flavors available to use. Please visit the documentation of the links below and pick the one you prefer.

Node Channel (NEW)

Supports logging to files and file rollover. Please see typescript-logging-node-channel for details.

Documentation

The following sections are available:

Using typescript-logging version 1?

Please visit https://github.com/vauxite-org/typescript-logging/tree/release-1.x for more details. Consider upgrading to the latest version.

Version 2 of typescript-logging is not compatible with version 1

Please check the migration guide for more information.

Getting started

For all details and documentation please visit the links above. The following sections provide a quick start only for both flavors.

Category style flavor

To install the category-style flavor use the following npm commands:

npm install --save typescript-logging  # Core is required for any style
npm install --save typescript-logging-category-style

Usage

The following section configures a provider and exposes a getLogger function for other modules to use. The getLogger in this example is used to create root categories.

/*--- LogConfig.ts ---*/
import {CategoryProvider, Category} from "typescript-logging-category-style";

const provider = CategoryProvider.createProvider("ExampleProvider");

export function getLogger(name: string): Category {
  return provider.getCategory(name);
}

/*--- Person.ts ---*/
import {getLogger} from "./LogConfig";

/* Root categories can and probably will be defined elsewhere, this is just an example */
const logModel = getLogger("model");

/* Create child categories based on a parent category, effectively allowing you to create a tree of loggers when needed */
const logPerson = logModel.getChildCategory("Person");

function example(value: string) {
  logPerson.debug(() => `Example function called with value ${value}`);
  try {
    // Awesome code here...
    logPerson.getChildCategory("example()").debug(() => "Child category again");
  }
  catch (e) {
    logPerson.error(() => "Awesome code failed unexpectedly", e);
  }
  finally {
    logPerson.debug(() => "Example function completed");
  }
}

Log4ts flavor

To install the log4ts-style flavor use the following npm commands:

npm install --save typescript-logging  # Core is required for any style
npm install --save typescript-logging-log4ts-style

Usage

The following section configures a provider and exposes a getLogger function for other modules to use.

/*--- LogConfig.ts ---*/
import {LogLevel} from "typescript-logging";
import {Log4TSProvider, Logger} from "typescript-logging-log4ts-style";

const provider = Log4TSProvider.createProvider("ExampleProvider", {
  /* Specify the various group expressions to match against */
  groups: [{
    expression: new RegExp("model.+"),
    level: LogLevel.Debug, /* This group will log on debug instead */
  }, {
    expression: new RegExp("service.+"),
  }],
});

export function getLogger(name: string): Logger {
  return provider.getLogger(name);
}

/*--- Person.ts ---*/
import {getLogger} from "./LogConfig";

const log = getLogger("model.Person")

function example(value: string) {
  log.debug(() => `Example function called with value ${value}`);
  try {
    // Awesome code here...
  }
  catch (e) {
    log.error(() => "Awesome code failed unexpectedly", e);
  }
  finally {
    log.debug(() => "Example function completed");
  }
}

Build

Please make sure to have node 18 LTS installed.

To locally build the logging flavors. The easiest is to run the ./initialize.sh script:

./initialize.sh # Clean, install and build everything.

This will cleanly install and build your branch from scratch.

You can also manually install things, by going into the respective directories and manually type:

# If not installed yet
npm run ci
# or for the test projects
npm install

Any project when you're in the respective directory can be built with:

npm run build

That will clean, build and test the project.

Tests

To locally run the tests, in the respective directories:

npm run test

Integration tests

If you're on linux or mac-os, it's easiest to run initialize.sh first. Otherwise, skip that and run npm run install manually as shown below.

# Linux/MacOS only - Cleans everything and re-installs packages, including those for the integration projects.
./initialize.sh

# If not using ./initialize.sh, note that the dependent projects must be built first (core and the various styles, see above)
npm run install # Run inside respective test-integration project, e.g. tests-integration/rollup
npm run build   # Run inside respective test-integration project. Builds test webapp and runs cypress tests.

Bugs

If you encounter a bug please log it in the issue tracker of this repository and make sure to specify what flavor (style) you are using.

Contributing

Feel free to contribute or come up with great ideas, please use the issue tracker for that.

If you add/change new functionality and want it merged in a later release, please open a pull request. Also add tests for it (see various "test" directories).

Please keep in mind that things may not fit the library and in such case will be rejected, so if you are unsure please ask first before wasting your valuable time.

Migration

Please check the migration guide if you are on an old version and wish to use the latest version available.

Changelog

Please check the changelog