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

console-dictation

v2.3.4

Published

A method to dictate console reports to persistent files

Downloads

16

Readme

console-dictation

PROJECT GOALS

The goal of this project was to make a convenient way to have persistent terminal logging.


Installation

npm i console-dictation

Quick Start (CommonJS)

  1. Require the package
const dictator = require('console-dictation')
  1. Use package methods to start logging
dictator.system("Hello, world!")

Quick Start (ESModule)

  1. Require the package
import dictator from 'console-dictator'
  1. Use package methods to start logging
dictator.system("Hello, world!")

Usage

Documentation below, for examples please see examples and demos

Configuration

Paths


By default the paths where the logs are stored are as follows: System log | Error log | Miscellaneous log --- | --- | --- <CWD>/logs/sys/sys.log|<CWD>/logs/error/err.log|<CWD>/logs/misc/misc.log

You can use the config method to overwrite or create new logging paths:

const { config } = require('console-dictation')

config({ 
  paths: { <SOME_PATH_KEY>: string, ... }, 
  log_names: { <SOME_PATH_KEY>: string, ... } 
})

Where paths indicated the log folder path (excluding the file), and the log_names indicate the log filename.

Indexing


console-dictation comes with a disabled indexer out of the box. Enable indexing functionality through the config method:

const { config } = require('console-dictation')

config({ 
  indexing_config: {
    indexing: true
  }
})

Indexing has a built-in dependancy array (i.e., X makes a log whenever a log is made in Y): System log | Error log | Miscellaneous log --- | --- | --- none | [system] | [system]

You can pass a new dependancy array of callable logging methods (i.e., system, error, and misc) to replace the dependancies stored in local memory through the config method:

const { config } = require('console-dictation')

config({
  indexing_config: {
    dependencies: {
      SYS: ['misc', 'error'],
      ERR: []
    }
  }
})

Retrieving Configuration

Dictator configuration is stored in local memory. You can use the following commands to find the local configuration.

const { getPaths, getLogNames, getConfig } = require('console-dictation')

let paths = getPaths()          // { PATH_KEY: PATH, ... }

let log_names = getLogNames()   // { LOG_KEY: LOG_FILENAME, ... }

let config = getConfig()        // {PATHS: { PATH_KEY: PATH, ... }, LOG_NAMES: { LOG_KEY: LOG_FILENAME, ... }}, INDEXING_CONFIG: {indexing: boolean, dependencies: {LOG_KEY: []}}

Logs

System log | Error log | Miscellaneous log --- | --- | --- system( message: string ) | error( message: string ) | misc( message: string ) report({ type: 0, message: string }) | report({ type:1, message: string }) |report({ type:2, message: string }) |

Note: report with missing type parameter or unknown type parameter will default to a miscellaneous log.

Each log type includes an optional path parameter. This can be used to manually change log path of that specific message:

const { system } = require('console-dictation')

system( message: string, path ?: { PATH: string, LOG_NAME: string } )

Examples

Example 1: simple express logging

const dictator = require('console-dictation')
const express = require('express')

const app = express()

app.listen(3000, () => dictator.system(`connected to booking server: port ${port}`))

Example 2: utilize destructuring

const { system } = require('console-dictation')
const express = require('express')

const app = express()

app.listen(3000, () => system(`connected to booking server: port ${port}`))

Demos

This module has two demos prepared for an ESModule/MJS enviroment and a CommonJS enviromment.

ESModule

ESM demo code can be found here.

  1. Clone this repo
git clone https://github.com/spiltbeans/console-dictation.git
  1. CD into demo folder
cd ./demos/mjs
  1. Run start script
npm start
  1. Inspect logs

CommonJS

CJS demo code can be found here.

  1. Clone this repo
git clone https://github.com/spiltbeans/console-dictation.git
  1. CD into demo folder
cd ./demos/cjs
  1. Run start script
npm start
  1. Inspect logs