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

logscribe

v2.0.5

Published

A speedy log to file utility.

Downloads

758

Readme

What and why?

LogScribe aims to be as straigtforward, fast and robust log-to-file/terminal utility as possible.

The log file is automatically split into smaller files and each message will automatically have a timestamp attached. For more advanced usage, you can add tags to your messages and even color them.

Quick examples

log('Hello World!');

Logs "Hello World!" into a log file called application-2019_01_22.log:

Tue Jan 22 2019 20:16:43 GMT+0200 (Eastern European Standard Time)
Hello World!

print('Hello World!');

The application console prints out "Hello World!".

[12.20.04] - Hello World!

logprint('Hello World!);

Both features with a one command.

l('Hello World!'); p('Hello World!'); lp('Hello World!');

And here are aliases for the functions above if you feel like typing extra letters is slowing you down.

Treats

  • Fully asynchronous
  • No other dependencies
  • Written in TypeScript
  • Automatic log file splitting
  • Automatic timestamps on everything
  • Message tags
  • Custom log folders
  • Custom log prefixes
  • Tag colors

Install

npm

npm install logscribe

Yarn

yarn add logscribe

Basic Usage

log(...value: any): void

Logs a message into a log file.

import { log } from 'logscribe';
log('Hello World');
log('Hello World', 'This will take a new line', '3rd line');

Even though log accepts anything, you should mainly use strings, numbers, lists and booleans as some other types may not render anything useful. For example objects end up being [Object object] due to how JavaScript is.

Alias: l()

print(...value: any): void

Prints a message.

import { print } from 'logscribe';
print('Hello World');
print('Hello World', '2nd part');

Unlike in log(), with print() you can also print out objects.

You can disable printing with setPrintDisabled(boolean). This may be useful in production environments.

Alias: p()

logprint(...value: any): void

Combines log() and print().

import { logprint } from 'logscribe';
logprint('Hello World');
logprint('Hello World', 'This will take a new line', '3rd line');

Alias: lp()

Advanced Usage

Logging, printing and logprinting with tags

To execute basic functionality with a tag or a custom color you need to initialize the log(), print() or logprint() functions with a logscribe(tag: string, color?: string) wrapper.

With this wrapper you can define what tag or color is being used. You can also create multiple wrappers for different needs.

import logscribe from 'logscribe';
const { log, print, logprint } = logscribe('myTag');
// The following examples will have a "myTag" attached.
log('Hello World!')
print('Hello World!);
logprint('Hello World!);

Here we add a tag and a custom color:

import logscribe from 'logscribe';
const { print } = logscribe('myTag', '\x1b[32m');
print('myTag now has a custom color.');

Let's dive deeper. Two printing commands, one for regular prints and one for error events:

import logscribe from 'logscribe';
const { print } = logscribe('General');
const warningPrint = logscribe('WARNING', '\x1b[31m').print;
try {
  print('All good.');
} catch(e) {
  warningPrint('Oh no, an error.', e);
}

The ES5 syntax is slightly different:

// Logging without tags.
const { log } = require('logscribe');
// Printing with tags.
const { print } = require('logscribe').default('General');
...

Settings

These are the optional global settings for LogScribe. Set them as your project initializes.

setLogDirPath(value: string): void

Sets a directory path for the log files. The application must have a writing permission to the path and the path must exist.

Default: <app root>

setLogMaxSize(value: number): void

The maximum filesize of a log before a new log file is created. Value is in bytes (1000 = 1KB).

Default: 1024000

setLogPrefix(value: string): void

A prefix for the filenames. For example a value "custom" would produce: "custom_2019-22-01.log".

Default: "application"

setPrintDisabled(value: boolean): void

Disables console printing. Useful in production environments where you may not want to print out everything.

Default: false

Colors

A cheatsheet for console colors.

FgBlack = "\x1b[30m"
FgRed = "\x1b[31m"
FgGreen = "\x1b[32m"
FgYellow = "\x1b[33m"
FgBlue = "\x1b[34m"
FgMagenta = "\x1b[35m"
FgCyan = "\x1b[36m"
FgWhite = "\x1b[37m"

BgBlack = "\x1b[40m"
BgRed = "\x1b[41m"
BgGreen = "\x1b[42m"
BgYellow = "\x1b[43m"
BgBlue = "\x1b[44m"
BgMagenta = "\x1b[45m"
BgCyan = "\x1b[46m"
BgWhite = "\x1b[47m"