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

@taikai/scribal

v1.0.4

Published

Write logs in a file/console or a custom output

Downloads

33

Readme

Scribal

Fast and easily write your logs into files and on console, it works with Ts as well with Js projects.

import Scribal, { InitialConfig } from '@taikai/scribal';

/*
 * Create the configs for your initializing loggers (console and file)
 * */
const initConfig: InitialConfig = {
  appName: 'My App',
  hostname: 'localhost',
  version: '1.0',
  console: {
    silent: false, // log on console
  },
  file: {
    silent: true, // doesn't log on file
  },
};

const blackListKeys = ['password', 'phoneNumber', 'address'];

const scribal = new Scribal(blackListKeys, '*');
scribal.init(initConfig);
scribal.i('Log something funny 🚀');

...

:memo: Where do I start?

Step 1: Installation

This is a Node.js module available through the npm registry.

Before installing, download and install Node.js. prefer the LTS version.

If this is a brand new project, make sure to create a package.json first with the npm init command.

Installation is done using the npm install command:

$ npm i @taikai/scribal

Step 2: Log something with your logger

import the library into your file

use the import statement (in case of a typescript project):

import Scribal, { InitialConfig } from '@taikai/scribal';

or require (if you are working in a js project):

const { default: Scribal } = require('@taikai/scribal');

create a new instance of your Logger

prepare your config object and your blacklist elements (the elements which the info appearing after this should be masked):

...
const initConfig: InitialConfig = {
  appName: 'My App',
  hostname: 'localhost',
  version: '1.0',
  console: {
    silent: false,
  },
  file: {
    silent: true,
  },
};

const blackListKeys = ['password', 'phoneNumber', 'address'];
const scribal = new Scribal(blackListKeys, '*');
scribal.init(initConfig);

:bulb: Hint: If you are using a js project, you don't need to specify the types of variables :wink:.

start logging

After initiated the logger calling the method .init() you can start writing log messages into your files and/or your console depending on the values you set on the initConfig variable:

scribal.i('Log something funny 🚀');
scribal.d('I am being debugged 🚫🐞');
scribal.w('You are about to love this lib ⚠');
scribal.e('Oh no! Something went wrong 😱');

plugin a custom logger

Lets say you wish stream your log messages to a different output, maybe storing them in a database or sending them to a different service, you can achieve this by using the addLogger method:

const dataStorage = {
  create: async (_level, _body) => {
    console.log('dataStorage.create was called');
  },
};

/**
 *
 * @param config the configuration passed on init method
 * @returns an object that must contain the log method
 */
const customLoggerMaker = (config: InitialConfig) => ({
  // It will be called in sync with the log methods i(), d(), w(), e(),...
  log: (level: string, content: any) => {
    dataStorage
      .create(`${level}-log`, {
        message: content,
        createdAt: new Date().toISOString(),
        appName: config.appName,
        version: config.version,
      })
      .then();
  },
});

const customLoggerConfig = {
  silent: false,
  level: 'debug',
};

scribal.addLogger(customLoggerMaker, customLoggerConfig);

:ice_cream: BONUS: More cool ways to use the Scribal library!

Find the API docs references on the following link: API Docs

Contributing

The way you can contribute to this project is submitting new features or fixing bugs.

To get started you have to clone this repo to your machine or fork to your personal account; open your terminal on the folder you want to clone into, and enter the following commands:

$ git clone https://github.com/taikai/scribal.git
$ cd scribal
$ npm install

Now you can create a new branch containing the new feature or bugfix, e.g.: git checkout -b feature/my_new_feature. This will make it easier for you to submit a pull request and get your feature merged.

Test Options

Before submitting, you must pass all the unit tests and syntax checks by running the two commands below:

npm run test run all the unit test cases in tests folder

There're also a syntax check commands for you: npm run lint

There is a nested project called lib-tester where you can play and see how would work your new feature or bugfix. But first you need to run the build script on the root project, then install the dependencies on the nested project using the npm install command. It should install the local package NOT the published one:

...
"@taikai/scribal": "file:../taikai-scribal-<VERSION>.tgz"
...