Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

devnull

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

devnull - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

91

lib/logger.js

@@ -12,8 +12,8 @@ "use strict";

, util = require('util')
, eventemitter = process.eventemitter;
, EventEmitter = process.EventEmitter;
/**
* detect if can use colors or not.
* Detect if can use colors or not.
*
* @type {boolean}
* @type {Boolean}
* @api private

@@ -25,5 +25,5 @@ */

/**
* the different log levels, in order of importance.
* The different log levels, in order of importance.
*
* @type {array}
* @type {Array}
* @api private

@@ -45,7 +45,7 @@ */

/**
* different log methods and it's output format. it's divided by system env. as
* Different log methods and it's output format. It's divided by system env. as
* you don't want your production log files full of color codes, but you do when
* them during development as they helpful for spotting errors and debug output.
*
* @type {object}
* @type {Object}
* @api private

@@ -80,6 +80,6 @@ */

/**
* a easier to understand logger, designed for readability during development.
* the logs can be stamped and colored based on the evn.
* A easier to understand logger, designed for readablity during development.
* The logs can be stamped and colored based on the evn.
*
* options:
* Options:
* - `env` either development or production, default is based on isatty.

@@ -89,10 +89,10 @@ * - `level` log level, defaults to 8.

* - `timestamp` do the logs needs to stamped, defaults to true.
* - `pattern` pattern for the time stamp, defaults to node's util log format.
* - `pattern` pattern for the timestamp, defaults to node's util log format.
*
* @constructor
* @param {object} options options
* @param {Object} options options
* @api public
*/
var logger = module.exports = function (options) {
var Logger = module.exports = function (options) {
options = options || {};

@@ -103,4 +103,4 @@

this.levels = levels;
this.level = object.keys(this.levels).length;
this.level = options.level || object.keys(this.levels).length;
this.level = Object.keys(this.levels).length;
this.level = options.level || Object.keys(this.levels).length;
this.notification = this.levels.warning;

@@ -110,3 +110,3 @@

this.timestamp = true
this.pattern = '{fullyear}-{month:2}-{date:2} {tolocaletimestring}';
this.pattern = '{FullYear}-{Month:2}-{Date:2} {toLocaleTimeString}';

@@ -120,3 +120,3 @@ // override the defaults

// set the correct prefix
// set the correct prefx
this.prefix = methods[this.env];

@@ -126,18 +126,18 @@ this.transports = [];

logger.prototype.__proto__ = eventemitter.prototype;
Logger.prototype.__proto__ = EventEmitter.prototype;
/**
* add more transport methods to the logger.
* Add more transport methods to the logger.
*
* @param {transport} transport transport constructor
* @param {object} options configuration for the transport
* @returns {logger}
* @param {Transport} Transport Transport constructor
* @param {Object} options configuration for the transport
* @returns {Logger}
* @api public
*/
logger.prototype.use = function (transport, options) {
Logger.prototype.use = function (Transport, options) {
// prevent duplicates
if (this.has(transport)) return this;
if (this.has(Transport)) return this;
this.transports.push(new transport(this, options));
this.transports.push(new Transport(this, options));
return this;

@@ -147,14 +147,14 @@ };

/**
* test if a transport is available.
* Test if a transport is available.
*
* @param {transport} transport transport constructor
* @return {boolean}
* @param {Transport} Transport Transport constructor
* @return {Boolean}
* @api private
*/
logger.prototype.has = function (transport) {
Logger.prototype.has = function (Transport) {
var i = this.transports.length;
while (i--) {
if (this.transports[i] instanceof transport) return this.transports[i];
if (this.transports[i] instanceof Transport) return this.transports[i];
}

@@ -166,11 +166,11 @@

/**
* remove a transport method from the logger.
* Remove a transport method from the logger.
*
* @param {transport} transport transport constructor
* @returns {logger}
* @param {Transport} Transport Transport constructor
* @returns {Logger}
* @api public
*/
logger.prototype.remove = function (transport) {
var transport = this.has(transport)
Logger.prototype.remove = function (Transport) {
var transport = this.has(Transport)
, i = this.transports.length;

@@ -195,3 +195,3 @@

/**
* The actual method that does the logging, in a fancy pancy format of course.
* The actual method that does the logging, in a fancy pancy format ofcourse.
*

@@ -211,3 +211,2 @@ * @param {String} type log type

// iterate of all available transports and give them theh shizzle
// @TODO actually work with transports ;D
console[type in console ? type : 'log'].apply(

@@ -232,3 +231,3 @@ console

/**
* Generates a time stamp based on the pattern. It's based on the 140bytes gist:
* Generates a timestamp based on the pattern. It's based on the 140bytes gist:
* https://gist.github.com/1005948.

@@ -262,3 +261,3 @@ *

*
* But I have optimized the code base, removed pointless JavaScript var
* But I have optimized the code base, removed pointless javascript var
* declarations, loop optimizations and more.

@@ -312,3 +311,3 @@ *

/**
* Parses the stack traces to useful data structures. Simple yet effective.
* Parses the stacktraces to useful data structures. Simple yet effective.
*

@@ -335,6 +334,7 @@ * @param {String} trace the captured stack

// try to detect if we received a user defined namespace argument or
if (args.length > 1 // we should have multiple arguments
&& typeof arg == 'string' // first should be string
&& !~arg.indexOf(' ') // but not a sentence
&& !~arg.indexOf(' ') // but not a sentance
&& !~arg.indexOf('%') // and not a formatting option

@@ -348,3 +348,3 @@ ) {

// use shift to remove the argument from the args array so we won't be
// logging the namespace, as it's already being added here.
// loggin the namespace, as it's already beein added here.
namespace.push(args.shift());

@@ -367,3 +367,3 @@ } else {

// store the filename of the first item in the stack trace as that's the
// the file where the logging occurred the rest is just a bubble down of
// the file where the logging occured the rest is just a bubble down of
// the stack. Just make sure it's a native call..

@@ -374,3 +374,3 @@ if (!filename) {

// ignore anonymous functions, they are completely pointless
// ignore anonymouse functions, they are completely pointless
if (method === '<anonymous>') continue;

@@ -407,3 +407,2 @@

});
/**

@@ -413,2 +412,2 @@ * Versioning.

Logger.version = "0.0.1";
Logger.version = "0.0.2";
{
"name": "devnull"
, "version": "0.0.1"
, "version": "0.0.2"
, "description": "A simple logger with automatic function detection."
, "homepage": "http://observer.no.de"
, "keywords": ["log", "logger", "logging", "dev/null"]
, "author": "Arnout Kazemier <info@3rd-Eden.com>"
, "repository": {

@@ -8,0 +9,0 @@ "type": "git"

@@ -1,7 +0,24 @@

# dev/null
# dev/null (because logging to /dev/null is really fast!)
An advanced logging module for Node.js, it was developed to make your logs more
powerful and easier to understand using smart log namespacing and event event
handling.
**devnull** is an advanced logging module for Node.js it was designed from the
ground up to assist you during development and powerful in production. It works
just like the console.log statements, it uses the same formatter, everything.
This is basically a cherry on top :).
#### namespacing
It automatically adds intelligent name spacing to all your log calls so you can easily
spot where the log messages are coming from, without having to remember all the
locations of your log statements.
#### evented
The logger is build upon the EventEmitter prototype so you can listen when
certain events are fired. You might want to send an e-mail out for every
critical log message you receive. I know I would.
#### customizable
It comes with a ton of options, that could customize. Or not. It's up to you.
### Installation

@@ -15,2 +32,45 @@

#### initializing
```js
var Logger = require('devnull')
, logger = new Logger;
```
This initializes the default logger. You can configure the logger by passing in
a options object.
```js
var Logger = require('devnull')
, logger = new Logger({ timestamp: false });
```
The available options:
- `env` either development or production, default is based on isatty.
- `level` log level, defaults to 8.
- `notification` when do start emitting notification errors, defaults to 1.
- `timestamp` do the logs needs to stamped, defaults to true.
- `pattern` pattern for the time stamp, defaults to node's util log format.
The timestamp pattern is based on the [140bytes
gist](https://gist.github.com/1005948) but it also allows execution of functions
like `{Fullyear} - {toLocaleTimeString}`
#### methods
The logger ships with these methods by default.
- alert
- critical
- error
- warning
- metric
- notice
- info
- log
- debug
```js
logger.critical('omg the server is on fire', { obj: 'works like console.log' });
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc