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

loggerpro

v1.5.2

Published

Logging with colors, file output, timestamps, and object pretty-printing.

Downloads

2

Readme

LoggerPro

Better logging in Node.1

Features

❗️ Message Types: In addition to the regular ones, you can log success, error, info, and warning messages.

Emoji Log Symbols: 👁💖 Emoji.

🔕 Disable Logging: Just call .disable() and messages will stop being logged.

🌎 Environmentally Conscious: Logging can be enabled or disabled based on the value of an environment variable.

🗄Log to File: Messages can be sent to a logfile and/or stdout.

⌚️ Timestamps: Logged messages can include timestamps to let you know when they were sent.

🎨 Colors: Timestamps are colored when sent to the console.

💄Pretty-Printed Objects: JSON objects and arrays are printed in a much more readable way than with plain old console.log.

Preview

Installation

You know the drill. npm install loggerpro --save installs logger-pro and adds it as a dependency to your project.

The Basics

Before you do anything else, import the LoggerPro module:

var log = require('./loggerpro')

By default, logging is enabled.

You can disable logging in four(!!!) different ways:

  1. log.disable()
  2. log.config({log:false})
  3. log.toggle() // Only if logging is enabled.
  4. By setting setting ENABLE_LOGGING=false as an environment variable.

You can reenable logging by doing the opposite of the above.

Every option in LoggerPro can be customized by the object that you pass when calling .config(), here's a sample that includes every property:

log.config({
  log:true,
  showTimestamp:true,
  stdout:true,
  fileout:true,
  useEmoji: true
})

Logging Messages

Here's how you log a message:

log.message('Hello World!')

10x programmers can use this shorthand, which does the same thing:

log.msg('Hello World!')

LoggerPro includes a special function for logging the value of variables:

var foo = 12
log.val(foo,'foo') // 1st param is the var, 2nd is its name.

var bar = 'Hello!'
log.val(bar,'bar')

That example would log:

number x = 12
string bar = Hello!

Message Types

Custom styling is provided for success, error, info, and warning messages.

Here's how you call each, respectively:

log.err('This is an error. ') // log.error also works.
log.suc('Something succeeded!') //log.success works, too!
log.info('Something neither good nor bad happened.')
log.warn('This could be a problem in the future, but isn\'t now.')

The same output can also be achieved by providing an extra argument to a basic message. For example:

log.msg('This is an error.','error')

By default, these messages are prefixed with a corresponding emoji. If you're on a PC or just aren't any fun, this can be disabled with the following:

log.config({useEmoji:false})

Output to a File

LoggerPro will log to a file if fileout is set to true in your config object. That file is called debug.log and it will be created in the directory where your app lives.

By default, the output from LoggerPro will just keep appending itself to that file. If you want to delete that file and start fresh, you can do so by calling log.delete().

Because it's just a plaintext file, colors aren't shown in debug.log.

Using Environment Variables

Logging can be enabled or disabled based on the value of an environment variable.

If you're new to environment variables, here are two really easy ways to set them:

  1. If your app's start command is something like this: node app.js, you can pass it an environment variable that will enable logging like this: ENABLE_LOGGING=true node app.js.

  2. Use dotenv.

Example

Putting it all together now, let's say we declared the following variables:

var x = 12
var bar = 'Hello!'
var obj = {"make":"Bentley","model":"Continental GT","color":"Blue"}

Here's how we might print that plus an obligatory hello world message using just console.log:

console.log('Hello World')
console.log(typeof(x) + ' x = ' + x)
console.log(typeof(bar) + ' bar = ' + bar)
console.log(obj)

Which would output:

Hello World
number x = 12
string bar = Hello
{ make: 'Bentley', model: 'Continental GT', color: 'Blue' }

Here's how we'd do it using LoggerPro:

log.msg('Hello World')
log.val(x,'x')
log.val(bar,'bar')
log.msg(obj)

Which would output:

[23:19:57] Hello World
[23:19:57] number x = 12
[23:19:57] string bar = Hello!
[23:19:57] {
              "make": "Bentley",
              "model": "Continental GT",
              "color": "Blue"
           }

Prettier and quicker!


1: Better = better for the needs of the author. Your desire/need for this module will vary. For lots of people, console.log will work just fine, in which case, don't use this module!