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

de-logger

v0.4.0

Published

Log functions, debug, info, events, warnings and errors in the console (with colors and alignment) and / or into a file.

Downloads

136

Readme

Build Status   Join the chat at https://gitter.im/hawkerboy7/de-logger

de-logger

Getting Started

Install de-logger using npm install

npm install de-logger --save

Require de-logger in your project and you're ready to go!

var log = require('de-logger');

Usage

It basically works the same way as console.log() only it ads colors and alignment to the messages. The first agument is assumed to be the name of the data you want to log. The rest of the arguments should be the data you want to log. You may also provide one argument containing data. This way the log will be nameless. As of version 0.2.0 it's also possible to store log messages into a log file.

Example 1

The examples are written in coffeescript. For an example in javascript check the examples folder.

log = require 'de-logger'

#  Method  Name    Data
log.func  'Func' , 'These'
log.debug 'Debug', 'are'
log.info  'Info' , 'all the'
log.event 'Event', 'basic'
log.warn  'Warn' , 'log'
log.error 'Error', 'commands'

basics

API

clear()

Clears the console. Based on your config your console scroll history will be wiped too.

func(*)

Identifing which function is triggered. Only the function name is required but more arguments may be given.

debug(*)

Display debug information.

info(*)

Display general information like which port your webserver is running on.

event(*)

Keep track of specific (socket) events.

warn(*)

Show warnings.

error(*)

Show errors.

* The arguments that should be provided are explained in Usage.

set({config})

Change the default configuration by providing a config object (example 2). This can be done at any time during you project and multiple times (which is shown in example 4). This way data in your project can be logged differently at any point in your project.

# Example 2 - Default config
log = require 'de-logger'

config =
  ms:       false
  file:
    enabled : false
    path: 'logs'
    name: 'project-name'
  date:     false
  time:     false
  align:    true
  space:    0
  whipe:    false
  terminal: true

log.set config

ms true / false Add miliseconds to time (only works if time is true).

file object

  • enabled true / false Turn logging messages to a file on or off.

  • path string Directory path to store log files into. It will be relative from the root of your project.

  • name string Name of the log file.

Example_1's output in a file

2015-03-27 01:05:57.20  func  Func → These
2015-03-27 01:05:57.20  debug Debug → are
2015-03-27 01:05:57.20  info  Info  → all the
2015-03-27 01:05:57.20  event Event → basic
2015-03-27 01:05:57.20  warn  Warn  → log
2015-03-27 01:05:57.20  error Error → commands

date true / false Show the current date.

time true / false Show the current time.

align true / false Will make sure the data logged after the name is in alignment with the largest name provided.

[green] info  Name_short → First value          // space = 10
[green] info  Name_normal → Second value        // space = 11
[green] info  Name        → Third value         // space = 11
[green] info  Name_even_lager → Fourth value    // space = 15
[green] info  name_short      → Fifth value     // space = 15
[green] info  hi              → Sixth value     // space = 15

space int The amount of characters the name area should contain. Default is 0 and grows whenever a name with a bigger length is provided (as is shown in the example above) but you can choose to start with another number.

whipe true / false This will also clear the console history.

terminal true / false Show messages in the terminal.

Do not show messages from a specific function You can also turn of a specific log function. Remember they will stay turned off untill you swich them on again somewhere in your code (example 3).

# Example 3
log = require 'de-logger'

log.set
  func:
    display: false
  event:
    display: false

Example 4

This example shows you can easily switch your logging type during your project.

log = require 'de-logger'

# Set config to also whipe the history of the console
log.set
  whipe: true

# Clear the console (and whipe it's history)
log.clear()

# Set some data variables
data1 = a: 1, b: 2, c: 3
data2 = a: 4, b: 5, c: 6

# Log a function and a debug message
log.func 'First function'
log.debug 'Debugging', 'Debug message', data1

# (Re)set config
log.set

  # Show time
  time: true

  # Turn off func and debug messages
  func:
    display: false
  debug:
    display: false

# Log a function, debug, info and event message
log.func 'First function'                       # This will not be displayed
log.debug 'Debugging', 'Debug message', data1   # This will not be displayed
log.info 'Webserver', 'Running at port: 8000'
log.event 'Gui input', data2

# (Re)set config
log.set

  # Show date
  date: true

# Log a warning and an error
log.warn 'Usermodel', 'Cannot find a user id'
log.error 'Mongodb', 'Connection couldn\'t be established'

example 4

Example 5

You can still provide your data as the only argument.

log = require 'de-logger'

log.info a:1,b:2,c:3

# (Re)Set config
log.set time:true,ms:true

log.event a:4,b:5,c:6

example5

Planned Features

Log-to-file

  • Make the messagesBuffer a multi-object so it will support example 6 as if all commands where executed synchronously.

Individual config

  • Configure methodes individually (with regard to time, date, ms and file).