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

console-stamp

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

console-stamp - npm Package Compare versions

Comparing version 0.2.5 to 0.2.6

4

defaults.json

@@ -8,3 +8,7 @@ {

"extend": {},
"datePrefix": "[",
"dateSuffix": "]",
"label": true,
"labelPrefix": "[",
"labelSuffix": "]",
"colors": {

@@ -11,0 +15,0 @@ "stamp":[],

4

main.js

@@ -125,3 +125,3 @@ /*jshint node:true, bitwise:false */

var prefix = colorTheme.stamp( "[" + dateFormat( pattern ) + "]" ) + " ";
var prefix = colorTheme.stamp( options.datePrefix + dateFormat( pattern ) + options.dateSuffix ) + " ";
var args = slice.call( arguments );

@@ -131,3 +131,3 @@

if ( options.label ) {
prefix += colorTheme.label( "[" + f.toUpperCase() + "]" ) + " ".substr( f.length );
prefix += colorTheme.label( options.labelPrefix + f.toUpperCase() + options.labelSuffix ) + " ".substr( f.length );
}

@@ -134,0 +134,0 @@

{
"name": "console-stamp",
"main": "main",
"version": "0.2.5",
"version": "0.2.6",
"author": {

@@ -34,2 +34,10 @@ "name": "Ståle Raknes",

"url": "https://github.com/sisou"
},
{
"name": "Fkscorpion",
"url": "https://github.com/Fkscorpion"
},
{
"name": "Alexis Tyler",
"url": "https://github.com/OmgImAlexis"
}

@@ -36,0 +44,0 @@ ],

@@ -16,9 +16,11 @@ # console-stamp

### Install
```console
npm install console-stamp
```
npm install console-stamp
### Patching the console
```js
require('console-stamp')(console, [options]);
```
require("console-stamp")(console, [options]);
#### console

@@ -31,3 +33,3 @@ The global console or [custom console](#customconsole).

* **options.pattern** {String}<br>A string with date format based on [Javascript Date Format](http://blog.stevenlevithan.com/archives/date-time-format)<br>**Default**: "ddd mmm dd yyyy HH:MM:ss"
* **options.pattern** {String}<br>A string with date format based on [Javascript Date Format](http://blog.stevenlevithan.com/archives/date-time-format)<br>**Default**: 'ddd mmm dd yyyy HH:MM:ss'

@@ -38,2 +40,6 @@ * **options.formatter** {Function}<br>A custom date formatter that should return a formmatted date string.

* **options.labelPrefix** {String}<br>A custom prefix for the label.<br>For an example see [Custom prefix and suffix example](#custom-pre-and-suffixes)<br>**Default:** "["
* **options.labelSuffix** {String}<br>A custom suffix for the label.<br>For an example see [Custom prefix and suffix example](#custom-pre-and-suffixes)<br>**Default:** "]"
* **options.include** {Array}<br>An array containing the methods to include in the patch<br>**Default**: ["log", "info", "warn", "error", "dir", "assert"]

@@ -45,3 +51,3 @@

* **options.level** {String}<br>A string choosing the most verbose logging function to allow. Ordered/grouped as such: "log dir", "info", "warn assert", "error"<br>**Default**: log
* **options.level** {String}<br>A string choosing the most verbose logging function to allow. Ordered/grouped as such: 'log dir', 'info', 'warn assert', 'error'<br>**Default**: log

@@ -63,68 +69,71 @@ * **options.extend** {Object}<br>An object describing methods and their associated log level, to extend the existing `method <-> log level` pairs.<br>For an example see [Custom methods](#custommethods).

* **options.colors.metadata** {String/Array<String>/Function} <br>**Default:** []
* **options.datePrefix** {String}<br>A custom prefix for the datestamp.<br>For an example see [Custom prefix and suffix example](#custom-pre-and-suffixes)<br>**Default:** "["
* **options.dateSuffix** {String}<br>A custom suffix for the datestamp.<br>For an example see [Custom prefix and suffix example](#custom-pre-and-suffixes)<br>**Default:** "]"
Note: To combine colors, bgColors and style, set them as an array like this:
```js
...
stamp: ['black', 'bgYellow', 'underline']
...
```
...
stamp: ["black", "bgYellow", "underline"]
...
Or chain Chalk functions like this:
```js
...
stamp: require('chalk').red.bgYellow.underline;
...
```
...
stamp: require("chalk").red.bgYellow.underline;
...
Note also that by sending the parameter `--no-color` when you start your node app, will prevent any colors from console.
$ node my-app.js --no-color
```console
$ node my-app.js --no-color
```
### Example
```js
// Patch console.x methods in order to add timestamp information
require('console-stamp')(console, { pattern: 'dd/mm/yyyy HH:MM:ss.l' });
// Patch console.x methods in order to add timestamp information
require( "console-stamp" )( console, { pattern : "dd/mm/yyyy HH:MM:ss.l" } );
console.log('Hello World!');
// -> [26/06/2015 14:02:48.062] [LOG] Hello World!
console.log("Hello World!");
// -> [26/06/2015 14:02:48.062] [LOG] Hello World!
var port = 8080;
console.log("Server running at port %d", port);
// -> [26/06/2015 16:02:35.325] [LOG] Server running at port 8080
const port = 8080;
console.log('Server running at port %d', port);
// -> [26/06/2015 16:02:35.325] [LOG] Server running at port 8080
```
&nbsp;
console.log( "This is a console.log message" );
console.info( "This is a console.info message" );
console.warn( "This is a console.warn message" );
console.error( "This is a console.error message" );
console.dir( {bar: "This is a console.dir message"} );
```js
console.log('This is a console.log message');
console.info('This is a console.info message');
console.warn('This is a console.warn message');
console.error('This is a console.error message');
console.dir({bar: 'This is a console.dir message'});
```
Result:
[26/06/2015 12:44:31.777] [LOG] This is a console.log message
[26/06/2015 12:44:31.777] [INFO] This is a console.info message
[26/06/2015 12:44:31.779] [WARN] This is a console.warn message
[26/06/2015 12:44:31.779] [ERROR] This is a console.error message
[26/06/2015 12:44:31.779] [DIR] { bar: 'This is a console.dir message' }
```console
[26/06/2015 12:44:31.777] [LOG] This is a console.log message
[26/06/2015 12:44:31.777] [INFO] This is a console.info message
[26/06/2015 12:44:31.779] [WARN] This is a console.warn message
[26/06/2015 12:44:31.779] [ERROR] This is a console.error message
[26/06/2015 12:44:31.779] [DIR] { bar: 'This is a console.dir message' }
```
and
```js
require('console-stamp')(console, {
metadata: function () {
return ('[' + process.memoryUsage().rss + ']');
},
colors: {
stamp: 'yellow',
label: 'white',
metadata: 'green'
}
});
require( "console-stamp" )( console, {
metadata: function () {
return ("[" + process.memoryUsage().rss + "]");
},
colors: {
stamp: "yellow",
label: "white",
metadata: "green"
}
} );
console.log( "This is a console.log message" );
console.info( "This is a console.info message" );
console.warn( "This is a console.warn message" );
console.error( "This is a console.error message" );
console.dir( {bar: "This is a console.dir message"} );
console.log('This is a console.log message');
console.info('This is a console.info message');
console.warn('This is a console.warn message');
console.error('This is a console.error message');
console.dir({bar: 'This is a console.dir message'});
```
Result:

@@ -139,15 +148,14 @@

```js
const fs = require('fs');
const output = fs.createWriteStream('./stdout.log');
const errorOutput = fs.createWriteStream('./stderr.log');
const logger = new console.Console(output, errorOutput);
console_stamp(logger, {
stdout: output,
stderr: errorOutput
});
```
var fs = require( 'fs' );
var output = fs.createWriteStream( './stdout.log' );
var errorOutput = fs.createWriteStream( './stderr.log' );
var logger = new console.Console( output, errorOutput );
console_stamp( logger, {
stdout: output,
stderr: errorOutput
} );
```
Everything is then written to the files.

@@ -161,35 +169,36 @@

Custom formatter using moment.js
```js
const moment = require('moment');
moment.locale('ja');
var moment = require('moment');
moment.locale('ja');
require('console-stamp')(console, {
formatter: function() {
return moment().format('LLLL');
}
});
require( "console-stamp" )( console, {
formatter:function(){
return moment().format("LLLL");
}
} );
console.log('This is a console.log message');
console.info('This is a console.info message');
console.warn('This is a console.warn message');
console.error('This is a console.error message');
console.dir({bar: 'This is a console.dir message'});
```
console.log( "This is a console.log message" );
console.info( "This is a console.info message" );
console.warn( "This is a console.warn message" );
console.error( "This is a console.error message" );
console.dir( {bar: "This is a console.dir message"} );
Result:
[2016年5月12日午前11時10分 木曜日] [LOG] This is a console.log message
[2016年5月12日午前11時10分 木曜日] [INFO] This is a console.info message
[2016年5月12日午前11時10分 木曜日] [WARN] This is a console.warn message
[2016年5月12日午前11時10分 木曜日] [ERROR] This is a console.error message
[2016年5月12日午前11時10分 木曜日] [DIR] { bar: 'This is a console.dir message' }
```console
[2016年5月12日午前11時10分 木曜日] [LOG] This is a console.log message
[2016年5月12日午前11時10分 木曜日] [INFO] This is a console.info message
[2016年5月12日午前11時10分 木曜日] [WARN] This is a console.warn message
[2016年5月12日午前11時10分 木曜日] [ERROR] This is a console.error message
[2016年5月12日午前11時10分 木曜日] [DIR] { bar: 'This is a console.dir message' }
```
<a name="custommethods"></a>
### Custom Methods
The **option.extend** option enables the extention or modification of the logging methods and their associated log levels:
The **option.extend** option enables the extension or modification of the logging methods and their associated log levels:
The default logging methods and their log levels are as follows:
```javascript
var levelPriorities = {
```js
const levelPriorities = {
log: 4,

@@ -206,3 +215,3 @@ info: 3,

```javascript
```js
// Extending the console object with custom methods

@@ -219,3 +228,3 @@ console.debug = function(msg) {

require('console-stamp')(console, {
pattern: "HH:MM:ss",
pattern: 'HH:MM:ss',
extend: {

@@ -225,4 +234,4 @@ debug: 5,

},
include: ["debug", "info", "warn", "error", "fatal"],
level: "debug",
include: ['debug', 'info', 'warn', 'error', 'fatal'],
level: 'debug',
});

@@ -239,26 +248,45 @@ ```

#### String example
```js
require('console-stamp')(console, {
pattern: 'HH:MM:ss.l',
metadata: '[' + process.pid + ']'
});
require("console-stamp")(console, {
pattern:"HH:MM:ss.l",
metadata:'[' + process.pid + ']'
});
console.log('Metadata applied.');
```
Result:
```console
[26/06/2015 12:44:31.779] [LOG] [7785] Metadata applied.
```
console.log('Metadata applied.');
#### Function example
```js
const util = require('util');
Result:
require('console-stamp')(console, {
pattern: 'HH:MM:ss.l',
metadata: function(){ return '[' + (process.memoryUsage().rss) + ']'; });
[26/06/2015 12:44:31.779] [LOG] [7785] Metadata applied.
console.log('Metadata applied.');
```
#### Function example
Result:
var util = require("util");
[18:10:30.875] [LOG] [14503936] Metadata applied.
require("console-stamp")(console, {
pattern:"HH:MM:ss.l",
metadata: function(){ return '[' + (process.memoryUsage().rss) + ']'; });
<a name="custom-pre-and-suffixes"></a>
### Custom prefix and suffix example
If you don't want to use the default brackets, you can also define your own custom pre- and suffixes like so:
console.log('Metadata applied.');
require('console-stamp')(console, {
datePrefix: '####',
dateSuffix: '####',
labelPrefix: '{',
labelSuffix: '}'
});
console.log('Custom pre- and suffixed log');
Result:
[18:10:30.875] [LOG] [14503936] Metadata applied.
####Fri Sep 15 2017 16:58:29#### {LOG} Custom pre- and suffixed log

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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