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

@noravel/logger

v1.1.0

Published

Noravel logger

Downloads

61

Readme

Noravel logger

This is a support library for Nam's projects.

Content

Installation

npm i @noravel/logger

Quick start

const { Logger } = require('@noravel/logger');
// OR
import { Logger } from '@noravel/logger';
Logger.emergency('Emergency');
Logger.alert('Alert');
Logger.critical('Critical');
Logger.error('Whoop! Something went wrong.');
Logger.warning('Warning');
Logger.notice('Notice');
Logger.info('Hello world!');
Logger.debug('Debug');

Log storage path

By default, the log file is stored in the outermost directory of the project.

projects/
└── single_log.log

You can configure the path of the log file to store by following.

Logger.configure({
  path: path.join(__dirname, 'storage/logs'),
});
mkdir -p ./storage/logs

Logger does not create directories automatically, so you must make sure your directories are created beforehand. After configuration, the directory structure will look like this.

projects/
└── storage/
    └── logs/
        └── single.log

Channel

We supported 2 drivers and 2 channels as single and daily.

The single driver stores the log file as single.log. It will store all in a file.

[2024-01-01 00:00:00] [EMERGENCY] Emergency
[2024-01-01 00:00:01] [ALERT] Alert
[2024-01-01 00:00:02] [CRITICAL] Critical
[2024-01-01 00:00:03] [ERROR] Whoop! Something went wrong.
[2024-01-01 00:00:04] [WARNING] Warning
[2024-01-01 00:00:05] [NOTICE] Notice
[2024-01-01 00:00:06] [INFO] Hello world!
[2024-01-01 00:00:07] [DEBUG] Debug

The daily driver stores the log file as daily-{YYYY-MM-DD}.log. The log will be saved by day for each respective file.

Logger.configure({
  channel: 'daily', // By default single
});
projects/
└── storage/
    └── logs/
        └── daily-2024-01-01.log
[00:00:00] [EMERGENCY] Emergency
[00:00:01] [ALERT] Alert
[00:00:02] [CRITICAL] Critical
[00:00:03] [ERROR] Whoop! Something went wrong.
[00:00:04] [WARNING] Warning
[00:00:05] [NOTICE] Notice
[00:00:06] [INFO] Hello world!
[00:00:07] [DEBUG] Debug

Add the custom channel

const { LOG_LEVEL } = require('@noravel/logger');
// OR
import { LOG_LEVEL } from '@noravel/logger';

Logger.addChannel({
  name: 'error',
  driver: 'single',
  path: 'custom',
  level: LOG_LEVEL.ERROR,
});

Logger.configure({
  channel: 'error',
  path: join(__dirname, 'storage/logs'),
});

Logger.emergency('Emergency');
Logger.alert('Alert');
Logger.critical('Critical');
Logger.error('Whoop! Something went wrong.');
Logger.warning('Warning');
Logger.notice('Notice');
Logger.info('Hello world!');
Logger.debug('debug');

Check the content log in path storage/logs/custom/error.log. You will only see logs with levels equal to or higher than errors.

[00:00:00] [EMERGENCY] Emergency
[00:00:01] [ALERT] Alert
[00:00:02] [CRITICAL] Critical
[00:00:03] [ERROR] Whoop! Something went wrong.

Use channels flexibly

You can use channels flexibly instead of just using the initially installed channel.

Logger.channel('single').info('Hello');
Logger.channel('daily').info('Good morning');
Logger.info('Default');

The folder structure will look like this.

projects/
└── storage/
    └── logs/
        ├── custom
        |   └── error.log
        ├── daily-2024-01-01.log
        └── single.log

Set file name prefix

Logger.configure({
  prefix: 'noravel',
});

With the single driver

projects/
└── storage/
    └── logs/
        └── noravel-single.log

With the daily driver

projects/
└── storage/
    └── logs/
        └── noravel-2024-01-01.log