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

@studimax/logger

v1.0.1

Published

A simple log system with configurable transporters

Downloads

98

Readme

@studimax/logger

npm Code: TypeScript Made By: StudiMax

A logger system with configurable transporters.

Installation

npm install @studimax/logger
# or
yarn add @studimax/logger

Description

The logger system is a simple and flexible logging system. It is designed to be used in a modular way, so that you can easily add new transports.

2021-12-22 13:23:58.47	<error>	Logger.spec.ts:5	(Object.<anonymous>)    log1 {"hello":"world"}

Usage

import Logger from '@studimax/logger';

const logger = Logger({
    transports: [Logger.TRANSPORTS.CONSOLE_LOG(), Logger.TRANSPORTS.DATED_LOG()],
    levels: {
        extra: {
            color: '#ff0000',
            level: 1,
        },
    },
});
logger.info('Hello World!');
logger.extra('Extra!');

Logger default options

import Logger from '@studimax/logger';
Logger({
    format: '{timestamp}\t<{level.name}>\t{file}:{line}\t({method})\t{message} {metadata}', //see format docs
    dateFormat: 'YYYY-MM-DD HH:mm:ss.SS', // use fecha to format date
    logFolder: 'logs',
    logHistory: 100, // keep 100 logs
    transports: [], // by default, no transports
    transportTimeout: 1000, // timeout for transports
    levels: {}, // by default, use default levels but can be overridden
})

Default Levels

The color is used to display the level name in the console.

| Description | Level | Tag | Color | |:------------|:------|:------|:--------------------------------------------------------------------------| | Trace | 0 | trace | #0099ff #0099ff | | Debug | 1 | debug | #00cc99 #00cc99 | | Info | 2 | info | #00cc30 #00cc30 | | Warn | 3 | warn | #ffcc00 #ffcc00 | | Error | 4 | error | #ff0000 #ff0000 | | Fatal | 5 | fatal | #a70000 #a70000 |

Custom Levels

const levels = {
    myCustomTag: {
        color: '#ff0000',
        level: 1
    }
}

Custom Format

Format is a string that can contain the following placeholders:

  • {timestamp}: the timestamp of the log formatted with the dateFormat option
  • {level}: level object containing name, level and color
  • {file}: the file where the log was called
  • {line}: the line where the log was called
  • {method}: the method where the log was called
  • {message}: the message of the log
  • {metadata}: the metadata object passed to the log

You can use the dot notation . to access nested properties. For example, {metadata.foo} will access the foo property of the metadata object. See @studimax/ts package for more information.

Transporters

This package provides the following transporters:

CONSOLE_LOG

This transporter logs to the console.

DATED_LOG

This transporter logs to a file with a date prefix. The file is created if it doesn't exist. This transporter implements the FIFO strategy, first log is the first to be written.

NAMED_LOG

This transporter logs to a file with a name prefix.

Custom Transporter

You can create your own transporters by creating an async function.

async function MyCustomTransporter(data: Data, options: TransportOptions) {
    if(await options.transportReady){
        // do something when the same previous logs transport has been resolved.
        console.log(data.message);
    }
}

TransportOptions extends LoggerOptions ans add more properties:

  • ready: a promise that is resolved when all previous logs transports have been resolved.
  • transportReady: a promise that is resolved when the same previous logs transport has been resolved.