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

@ts-awesome/logger

v1.1.1

Published

TypeScript logger and error reporter

Downloads

359

Readme

@ts-awesome/logger

TypeScript logger and error reporter

Key features:

  • console and/or file logs
  • colorful console logs
  • sentry/slack error reporters
  • configurable log level

Logger

library provides a convenient Logger class to make things easier.

import {getLoggerFactory, Logger} from '@ts-awesome/logger';

const driverCfg = {
  type: 'CONSOLE', // or 'FILE" or 'NOOP'
}

const reporterCfg = {
  type: 'SENTRY', // or 'SLACK' or 'NOOP'
  dsn: 'dsn-1' // required for sentry
}

const loggerFactory = getLoggerFactory(driverCfg, reporterCfg);

const logger = loggerFactory('app');

logger.trace('something trivial');
logger.debug('something trivial');
logger.info('something usefull');
logger.warn('something to pay attantion to');
logger.error('something to be alerted with');
logger.error(new Error('something wrong'));

Please note that console can be used a replacement for Logger.

Use with IoC container and @ts-awesome/config

import {Config} from '@ts-awesome/config';
import {Container} from "inversify";
import {getLoggerFactory, LoggerFactorySymbol} from "@ts-awesome/logger";

const container: Container;
const config: Config;

const driverCfg = config.get<ILoggerConfig>('logger');
const reporterCfg = config.has('reporter') ? config.get<ILoggerConfig>('reporter') : undefined;

const loggerFactory = getLoggerFactory(driverCfg, reporterCfg);

container.bind<ILoggerFactory>(LoggerFactorySymbol).toConstantValue(loggerFactory);

Console logger

import driverFactory from '@ts-awesome/logger/dist/loggers/console';

const logger = driverFactory(
  'log', // min log level
  true, // add colors, true by default
);

logger('log', 'something trivial');
logger('info', 'something usefull');
logger('warn', 'something to pay attantion to');
logger('error', 'something to be alerted with');

File logger

import driverFactory from '@ts-awesome/logger/dist/loggers/file';

const logger = driverFactory(
  'info', // min log level
  'logs-%date%.log', // files pattern, default is `%date%.log`
  /* alternative Writer, default is `require('fs').appendFileSync` */
);

logger('log', 'something trivial');
logger('info', 'something usefull');
logger('warn', 'something to pay attantion to');
logger('error', 'something to be alerted with');

Composite logger

import consoleDriverFactory from '@ts-awesome/logger/dist/loggers/console';
import fileDriverFactory from '@ts-awesome/logger/dist/loggers/console';
import compositeDriverFactory from '@ts-awesome/logger/dist/loggers/composite';

const logger = compositeDriverFactory(
  fileDriverFactory('error', 'errors-%date%.log'),
  fileDriverFactory('info', 'logs-%date%.log'),
  consoleDriverFactory('log'),
);

logger('log', 'something trivial');
logger('info', 'something usefull');
logger('warn', 'something to pay attantion to');
logger('error', 'something to be alerted with');

Sentry reporter

// sentry has to be installed separatly
import reporterFactory from '@ts-awesome/logger/dist/reporters/sentry';

const config = {
  dsn: 'dns-1', // your destination,
  // rest is added to report
  some: 'extra'
}

const reporter = reporterFactory(config);

const error = new Error('Test case');
const data = {
  user: 'some-id',
  tags: ['tag1', 'tag2'],
  other: 'extra'
}

reporter(error, data);

Slack reporter

// cross-fetch has to be installed separatly
import reporterFactory from '@ts-awesome/logger/dist/reporters/slack';

const config = {
  webhook: 'https://example.org', // obtaine url from Slack
  username: 'ErrorReporterBot', 
  // rest is added to report
  some: 'extra'
}

const reporter = reporterFactory(config);

const error = new Error('Test case');
const data = {
  user: 'some-id',
  tags: ['tag1', 'tag2'],
  other: 'extra'
}

reporter(error, data);

License

May be freely distributed under the MIT license.

Copyright (c) 2022 Volodymyr Iatsyshyn and other contributors