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

@codedungeon/messenger

v0.14.1

Published

clean node console messaging and logging

Downloads

386

Readme

@codedungeon/messenger

Description

Messenger is a simple node module for displaying pretty console logs (with lots of formatting options) and support for logging messages to .log files (including daily rotation)

Install

npm

> npm install @codedungeon/messenger

yarn

> yarn add @codedungeon/messenger

Usage

Messenger provides a suite of methods which can be used to quickly display appropriately colored messages. Each method can be accessed from the Messenger object, or destructured methods

const Messenger = require('@codedungeon/messenger')
Messenger.success('All tests passed', 'SUCCESS')

or

const {success} = require('@codedungeon/messenger')
success('All tests passed','SUCCESS)

The following demonstrates how each message can be displayed

const msg = require('@codedungeon/messenger')
const pkgInfo = require('./package.json')
msg.initLogger(true, 'logs', pkgInfo.name)

console.log('')
let showIcons = false
let showLabels = false

msg.critical('critical message', showLabels ? 'CRITICAL' : '', showIcons)
msg.danger('critical message', showLabels ? 'DANGER' : '', showIcons)
msg.error('error message', showLabels ? 'ERROR' : '', showIcons)
msg.success('success message', showLabels ? 'SUCCESS' : '', showIcons)
msg.warning('warning message', showLabels ? 'WARNING' : '', showIcons)
msg.important('important message', showLabels ? 'IMPORTANT' : '', showIcons)
msg.warn('warn message', showLabels ? 'WARN' : '', showIcons)
msg.notice('notice message', showLabels ? 'NOTICE' : '', showIcons)
msg.note('note message', showLabels ? 'NOTE' : '', showIcons)
msg.status('status message', showLabels ? 'STATUS' : '', showIcons)
msg.info('info message', showLabels ? 'INFO' : '', showIcons)
msg.debug('debug message', showLabels ? 'DEBUG' : '', showIcons)

If you want to pass a standard JavaScript object or array Messenger will use the dump method to display message, and if you supply label parameter, it will be displayed first and then message will be displayed (see the ./examples/test-messenger-obj.js example method for further information)

let obj = { fname: 'Mike', lname: 'Erickson', kids: ['Joelle', 'Brady', 'Bailey', 'Trevor'] }
Messenger.success(obj, 'FAMILY')

Using alert helper

You can also invoke any of the Messenger methods using the alert helper which accepts an object of options as opposed to passing the 3 separate parameters

Note: This method does not support calling statically

type - default "info"
msg  - notification message
icon - default "false"

alert({ type: 'info', msg: 'hello world', icon: false })
print({ type: 'info', msg: 'hello world', icon: false })
let msg = 'Hello World'
messenger.alert({ msg })
messenger.alert({ type: 'status', msg, label: '', icon: false })
messenger.alert({ type: 'status', msg, label: 'STATUS', icon: false })
messenger.alert({ type: 'status', msg, label: 'STATUS', icon: true })

Using print helper (same options as alert)

Or, if you choose, you can use the print helper

let msg = 'Hello World'
messenger.print({ type: 'success', msg })
messenger.print({ type: 'success', msg, label: 'SUCCESS', icon: false })
messenger.print({ type: 'success', msg, label: 'SUCCESS', icon: true })

Messenger Labels

In addition to displaying a full message with labels, Messenger includes label methods which format the supplied text as label

You can build each of message label only, providing the ability to construct messages with mixed color and backgrounds. Each method can be access off the Messenger object, or destructured.

const Messenger = require('@codedungeon/messenger')
Messenger.lblInfo('INFO')

or

const { lblInfo } = require('@codedungeon/messenger')
lblInfo('INFO')

Example

const m = require('@coddungeon/messenger')

console.log(`${m.lblInfo('INFO')} Hello World`)

will produce the following

Logger

Messenger includes a simple logging interface which log all console logging to persisted log files

Logger Methods

initLogger(logToFile: boolean, path: string, name: string) writeToLog(type: string, args: object, forceLogToFile: boolean) loggerCritical(msg: string) loggerError(msg: string) loggerStatus(msg: string) loggerWarning(msg: string) loggerWarn(msg: string) loggerImportant(msg: string) loggerInfo(msg: string) loggerDebug(msg: string) loggerLog(msg: string) oggerStatus(msg: string) loggerNotice(msg: string) loggerNote(msg: string) disableLog() enableLog()

Using initLogger

Using the initLogger method at the start of your CLI process, you can determine the location of log files

The following is the basic workflow for initializing Messneger Logger.

// get package information to pass along logger name
let pkgInfo = require('./package.json')

const Messenger = require('../src/messenger')

// initialize logger, defining the directory where logs are stored
Messenger.initLogger(true, 'logs', pkgInfo.name)

Log Files

Logger will create a unique log file in the defined log directory (typically either logs or system), each day using the following syntax

<name>-yyyy-mm-dd.log

System Logger

In addition to defining the logs location, you can also use a reserved name system which will create log files using the operating system log directory

...
Messenger.initLogger(true, 'system', pkgInfo.name)
...

This will create a single log file for defined name

Mac OS
<home>/System/Logs/<name>.log
Windows

Windows Log File Locations

License

Copyright © 2019-2022 Mike Erickson Released under the MIT license

Credits

messenger written by Mike Erickson

E-Mail: [email protected]

Twitter: @codedungeon

Website: codedungeon.io