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

@tycrek/log

v0.7.5

Published

tycrek's custom logger library

Downloads

100

Readme

tlog

NPMCBT badge

My custom logger library

Features

  • 🌈 Colours, timestamps, & labels
  • 🔧 Easily configurable
  • 🔗 Method chaining
  • Utility logs
  • 📝 Comments
  • 🔌 Express.js middleware
  • 🚀 No console wrapping

Installation

Install using npm i @tycrek/log, then load it into your project:

// Import TLog
import { TLog } from '@tycrek/log';
// or
const TLog = require('@tycrek/log');

// Set up a new instance
const logger = new TLog();

// or, set a level
const logger = new TLog('info');

Prints an info log:

logger.info('Hello, hell!');

Methods return the logger instance, allowing for method chaining:

logger
    .warn('Wait, why are we in hell?')
    .debug('Because we\'re not using industry standard logging libs!');

You can configure TLog options with the following methods:

| Method | Description | | --- | --- | | .setLevel(level) | Sets the minimum log level to print. | | .setTimestamp({}) | Enables or disables the timestamp, or configures colour, preset, & format. | | .setLabel({}) | Enables or disables the label, or configures padding, case, & alignment. | | .setTitle({}) | Sets the title delimiter. | | .setExtra({}) | Sets the extra prefix & suffix. | | .setComments({}) | Sets the comment character & colour. |

Timestamps use Luxon. To see what options are available for timestamp.preset & timestamp.format, review the Luxon documentation:

General log methods

logger.[level](title, message?, extra?)

Prints a log with the specified level. The title is printed in bold & colour, followed by the message in normal text. If extra is provided, it is printed in italics after the message.

You may pass 1, 2, or 3 parameters to these methods (message; title & message; title, message, & extra).

Possible levels are:

| Level | Severity | | --- | --- | | debug | 100 | | info | 200 | | warn | 300 | | error | 400 | | fatal | 500 |

Additional log levels are available for your convenience:

| Level | Severity | | --- | --- | | utils | 100 | | success | 200 | | express | 200 |

Utility logs

| Method | Description | | --- | --- | | .pid() | Prints the current process ID. | | .cwd() | Prints the current working directory. | | .epoch() | Prints the current Unix epoch in milliseconds. | | .uptime() | Prints the process uptime in seconds. | | .comment(message) | Prints a comment-like log. Useful for demoing outputs. | | .basic(message) | Prints a basic log with a timestamp (if enabled). |

Invisible utility logs

| Method | Description | | --- | --- | | .blank() | Prints a blank line. | | .clear() | Clears the console using Unicode escape sequences. May behave differently on different platforms. | | .callback(cb) | Calls the provided cb function. |

Express.js middleware

TLog comes with an included Express middleware. To use it, simply import it & add it to your Express app:

import { TLog } from '@tycrek/log';
import express from 'express';

const logger = new TLog();
const app = express();

app.use(logger.express());
app.get('/', (req, res) => res.send('Hello, world!'));
app.listen(3000);

The middleware is still a bit of a work-in-progress following the TypeScript rewrite, but it should work fine for most use cases.

You can configure the middleware with the following options:

| Option | Description | | --- | --- | | excludePaths | An array of paths to exclude from logging. | | excludeMethods | An array of HTTP methods to exclude from logging. | | trimPaths | Must be either false or an Object. | | trimPaths.maxLength | Any paths longer than this will be trimmed. | | trimPaths.delimiter | The character to use to replace trimmed path segments. | | morganMode | Mimics the behaviour of morgan. Not yet implemented. |

🍁 Colours.

Colours. I am Canadian. It is colours. If you don't like it, go fork yourself.