New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More β†’
Socket
Sign inDemoInstall
Socket

node-lancer

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-lancer - npm Package Compare versions

Comparing version 1.0.2 to 1.0.4

94

logger.js

@@ -37,2 +37,3 @@ 'use strict';

this.name = options.name || '';
this._groups = null;
var commands = this._commands = (options.commands || Logger.config.commands);

@@ -48,6 +49,56 @@ if(Array.isArray(commands)) {

}
group() {
var _groupMsg = [];
// εˆε§‹εŒ–η¬¬δΈ€δΈͺ
// _groupMsg._space = '─';
_groupMsg._start = "β”Œ";
_groupMsg._split = '|';
_groupMsg._ended = 'β””';
_groupMsg.__deep = 1;
if (this._groupMsg) {
this._groupMsg.push(_groupMsg);
var parent = _groupMsg.parent = this._groupMsg;
_groupMsg.__deep += parent.__deep;
// β”Œβ”€β”¬
// β”œβ”€β”Ό
_groupMsg._start = parent._split + '─┐';
if (parent.length) {
_groupMsg._start = parent._split.substr(0, parent._split.length - 1) + 'β”œβ”€β”';
}
_groupMsg._split = parent._split + ' |';
_groupMsg._ended = parent._split + ' β””';
}
this._groupMsg = _groupMsg;
}
_writeGroup (_groupMsg, parent, isLast) {
_groupMsg.forEach(function (msg, i) {
if (msg.length) {
return this._writeGroup(msg, _groupMsg, i === _groupMsg.length - 1);
}
var p = '';
if ( !i ) {
p = _groupMsg._start;
} else if (i === _groupMsg.length - 1) {
p = _groupMsg._ended;
if (parent && isLast) {
p = 'β””' + new Array(_groupMsg.__deep).join('─┴');
}
} else {
p = _groupMsg._split;
}
this[msg.stream].write(p + msg.line + '\r\n');
}, this);
_groupMsg._start = _groupMsg.__deep = _groupMsg.parent = _groupMsg._ended = null;
}
groupEnd() {
var _groupMsg = this._groupMsg;
if (_groupMsg.parent) {
this._groupMsg = _groupMsg.parent;
return;
}
this._writeGroup(this._groupMsg);
this._groupMsg = null;
}
_write (msg, type) {
if(!msg) {return;}
// msg += '[' + Color.grey(type) + ']';
this.emit('data',{stream: type, line: msg});
if (type !== 'stdout') {

@@ -57,3 +108,7 @@ type = 'stderr';

if (this.disabled) {return;}
this[type].write(msg+'\r\n');
if (this._groupMsg) {
return this._groupMsg.push({stream:type,line:msg});
}
this.emit('data',{stream: type, line: msg});
this[type].write(msg + '\r\n');
}

@@ -153,3 +208,3 @@ _stringify (opt, argv) {

command: {
out: ' ${sep|color:grey} ${time|timestamp:YYYY-MM-DD HH:mm:ss.SSS| color:white} ${sep|color:grey} [${debug}${name|color:white}] ${sep|color:grey} ${message}',
out: ' ${sep|color:grey} ${time|timestamp:HH:mm:ss.SSS| color:white} ${sep|color:grey} [${debug}${name|color:white}] ${sep|color:grey} ${message}',
name: 'log',

@@ -160,3 +215,3 @@ level: 0

{
out: ' ${sep|color:grey} ${time|timestamp:YYYY-MM-DD HH:mm:ss.SSS| color:white} ${sep|color:grey} [${debug}${name|color:white}] ${sep|color:grey} ${message}',
out: ' ${sep|color:grey} ${time|timestamp:HH:mm:ss.SSS| color:white} ${sep|color:grey} [${debug}${name|color:white}] ${sep|color:grey} ${message}',
name: 'log',

@@ -166,3 +221,3 @@ level: 0

{
out: ' ${sep|color:grey} ${time|timestamp:YYYY-MM-DD HH:mm:ss.SSS| color:white} ${sep|color:grey} [${debug}${name|color:cyan}] ${sep|color:grey} ${message|color:cyan}',
out: ' ${sep|color:grey} ${time|timestamp:HH:mm:ss.SSS| color:white} ${sep|color:grey} [${debug}${name|color:cyan}] ${sep|color:grey} ${message|color:cyan}',
name: 'info',

@@ -172,3 +227,3 @@ level: 1

{
out: ' ${sep|color:grey} ${time|timestamp:YYYY-MM-DD HH:mm:ss.SSS| color:white} ${sep|color:grey} [${debug}${name|color:green}] ${sep|color:grey} ${message|color:green}',
out: ' ${sep|color:grey} ${time|timestamp:HH:mm:ss.SSS| color:white} ${sep|color:grey} [${debug}${name|color:green}] ${sep|color:grey} ${message|color:green}',
name: 'done',

@@ -178,3 +233,3 @@ level: 1

{
out: ' ${sep|color:grey} ${time|timestamp:YYYY-MM-DD HH:mm:ss.SSS| color:white} ${sep|color:grey} [${debug}${name|color:blue}] ${sep|color:grey} ${message|color:blue}',
out: ' ${sep|color:grey} ${time|timestamp:HH:mm:ss.SSS| color:white} ${sep|color:grey} [${debug}${name|color:blue}] ${sep|color:grey} ${message|color:blue}',
name: 'finish',

@@ -186,3 +241,3 @@ level: 1

level: 2,
out: ' ${sep|color:grey} ${time|timestamp:YYYY-MM-DD HH:mm:ss.SSS| color:white} ${sep|color:grey} [${debug}${name|color:yellow}] ${sep|color:grey} ${message|color:yellow}'
out: ' ${sep|color:grey} ${time|timestamp:HH:mm:ss.SSS| color:white} ${sep|color:grey} [${debug}${name|color:yellow}] ${sep|color:grey} ${message|color:yellow}'
},

@@ -192,3 +247,3 @@ {

level: 3,
out: ' ${sep|color:grey} ${time|timestamp:YYYY-MM-DD HH:mm:ss.SSS| color:white} ${sep|color:grey} [${debug}${name|color:red}] ${sep|color:grey} ${message|color:red} ${file.pathname|color:grey}:${file.row|color:grey}:${file.col|color:grey}'
out: ' ${sep|color:grey} ${time|timestamp:HH:mm:ss.SSS| color:white} ${sep|color:grey} [${debug}${name|color:red}] ${sep|color:grey} ${message|color:red} ${file.pathname|color:grey}:${file.row|color:grey}:${file.col|color:grey}'
},

@@ -198,7 +253,7 @@ {

name: 'danger',
out: ' ${sep|color:grey} ${time|timestamp:YYYY-MM-DD HH:mm:ss.SSS| color:white} ${sep|color:grey} [${debug}${name|color:magenta}] ${sep|color:grey} ${message|color:magenta}'
out: ' ${sep|color:grey} ${time|timestamp:HH:mm:ss.SSS| color:white} ${sep|color:grey} [${debug}${name|color:magenta}] ${sep|color:grey} ${message|color:magenta}'
}, {
level: 4,
name: 'debug',
out: ' ${sep|color:grey} ${time|timestamp:YYYY-MM-DD HH:mm:ss.SSS| color:white} ${sep|color:grey} [${debug}${name|color:*}] ${sep|color:grey} ${message} ${file.pathname|color:grey}:${file.row|color:grey}:${file.col|color:grey}'
out: ' ${sep|color:grey} ${time|timestamp:HH:mm:ss.SSS| color:white} ${sep|color:grey} [${debug}${name|color:*}] ${sep|color:grey} ${message} ${file.pathname|color:grey}:${file.row|color:grey}:${file.col|color:grey}'
}

@@ -250,11 +305,14 @@ ]

}
_debug._commands.forEach(function (cmd) {
debug[cmd.name] = _debug[cmd.name].bind(_debug);
});
__linkedin(debug, _debug);
return debug;
};
_logger._commands.forEach(function (cmd) {
exports[cmd.name] = _logger[cmd.name].bind(_logger);
});
function __linkedin (f, t) {
t._commands.forEach(function (cmd) {
f[cmd.name] = t[cmd.name].bind(t);
});
f.group = t.group.bind(t);
f.groupEnd = t.groupEnd.bind(t);
}
__linkedin(exports, _logger);
exports.Logger = Logger;
# Logger
γ€δΈη”¨δ»‹ζ„δΊ†γ€‚θΏ™η§δΊ‹ζˆ‘ε·²η»δΉ ζƒ―δΊ†γ€‚ε› δΈΊζ‰€θ°“ηš„θ‹±ι›„ε•ŠοΌŒζ€»ζ˜―δΌšζ­»εœ¨δΈεˆζƒ…η†ηš„ε‘½δ»€δΉ‹δΈ‹γ€‚γ€‘ --- Lancer [Fate/Stay night]
## logger(${name},${opts})
*Create an debug mode logger*
> Only output message when the env.DEBUG is 'true' or '*' or the namespace you created. You can disable this with opts.disabled = true;
## Methods
* log, warn, error, debug, info, done, finish, danger
> All this methods are supported with logger[${method}], output the line info when the command's level is upper than the config.level(@exampe error, debug)
` NOTICE: The method debug is not like logger(${debugName}), this will always output.`
* group, groupEnd
> As your wish, this will group some messages to output with list like style.
```
β”Œ - 22:41:17.901 - [log] - This message is send by log
| - 22:41:17.902 - [info] - This message is send by info
| - 22:41:17.903 - [warn] - This message is send by warn
| - 22:41:17.922 - [error] - This message is send by error /{rootpath}/node-lancer/test.js:18:15
| - 22:41:17.923 - [danger] - This message is send by danger
| - 22:41:17.924 - [debug] - This message is send by debug /{rootpath}/node-lancer/test.js:18:15
β”œβ”€β” - 22:41:17.925 - [log] - test sub group demo
| | - 22:41:17.926 - [warn] - danger
| | - 22:41:17.926 - [error] - error in sub group /{rootpath}/node-lancer/test.js:24:10
| β”œβ”€β” - 22:41:17.927 - [log] - 333 test sub group demo
| | | - 22:41:17.927 - [warn] - 333 danger
| | β”” - 22:41:17.928 - [error] - 333 error in sub group /{rootpath}/node-lancer/test.js:28:12
| | - 22:41:17.928 - [error] - 222 error in sub group /{rootpath}/node-lancer/test.js:30:12
| β”” - 22:41:17.929 - [error] - 222 error in sub group /{rootpath}/node-lancer/test.js:31:12
β”” - 22:41:17.929 - [error] - 111 error in sub group /{rootpath}/node-lancer/test.js:33:10
```
## How to extend this
*Yes, lancer supported to extend the logger with some configs.*
> var Logger = logger.Logger
> Config will merged with the default Logger.config
@example
*Default config*
```javascript
{
"disabled": false,
"stdout": process.stdout,
"stderr": process.stderr,
"level": 2,
"sep": "-",
"name": "",
"command": {
"out": " ${sep|color:grey} ${time|timestamp:HH:mm:ss.SSS| color:white} ${sep|color:grey} [${debug}${name|color:white}] ${sep|color:grey} ${message}",
"name": "log",
"level": 0
},
"commands": [
{
"out": " ${sep|color:grey} ${time|timestamp:HH:mm:ss.SSS| color:white} ${sep|color:grey} [${debug}${name|color:white}] ${sep|color:grey} ${message}",
"name": "log",
"level": 0
},
{
"out": " ${sep|color:grey} ${time|timestamp:HH:mm:ss.SSS| color:white} ${sep|color:grey} [${debug}${name|color:cyan}] ${sep|color:grey} ${message|color:cyan}",
"name": "info",
"level": 1
},
{
"out": " ${sep|color:grey} ${time|timestamp:HH:mm:ss.SSS| color:white} ${sep|color:grey} [${debug}${name|color:green}] ${sep|color:grey} ${message|color:green}",
"name": "done",
"level": 1
},
{
"out": " ${sep|color:grey} ${time|timestamp:HH:mm:ss.SSS| color:white} ${sep|color:grey} [${debug}${name|color:blue}] ${sep|color:grey} ${message|color:blue}",
"name": "finish",
"level": 1
},
{
"name": "warn",
"level": 2,
"out": " ${sep|color:grey} ${time|timestamp:HH:mm:ss.SSS| color:white} ${sep|color:grey} [${debug}${name|color:yellow}] ${sep|color:grey} ${message|color:yellow}"
},
{
"name": "error",
"level": 3,
"out": " ${sep|color:grey} ${time|timestamp:HH:mm:ss.SSS| color:white} ${sep|color:grey} [${debug}${name|color:red}] ${sep|color:grey} ${message|color:red} ${file.pathname|color:grey}:${file.row|color:grey}:${file.col|color:grey}"
},
{
"level": 2,
"name": "danger",
"out": " ${sep|color:grey} ${time|timestamp:HH:mm:ss.SSS| color:white} ${sep|color:grey} [${debug}${name|color:magenta}] ${sep|color:grey} ${message|color:magenta}"
}, {
"level": 4,
"name": "debug",
"out": " ${sep|color:grey} ${time|timestamp:HH:mm:ss.SSS| color:white} ${sep|color:grey} [${debug}${name|color:*}] ${sep|color:grey} ${message} ${file.pathname|color:grey}:${file.row|color:grey}:${file.col|color:grey}"
}
]
}
var logger = new logger.Logger({
// your configs at here.
});
logger[${method}](msg, argv);
```
> Yes, logger config support template with some helpers for parser the output messages. The helper can be used like ${val | helper1: arg0, arg1 | helper2: arg0, arg1}
## Helper assign
*Now supported helpers: 'timestamp','color','IFELSE'*
> Set the helpers understand 'Logger.helper', like 'Logger.helper.rename = function (val, arg0, arg1) {}' and then you can use the 'rename' as an helper.

2

package.json
{
"name": "node-lancer",
"version": "1.0.2",
"version": "1.0.4",
"description": "An node logger for colorful with line info supported.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -16,6 +16,20 @@ var color = require('./color');

debug('This message is send by debug');
logger.group();
['log','info','warn','error','danger','debug'].forEach(function (name) {
logger[name]('This message is send by %s',name);
debug[name]('This message is send by %s',name);
})
});
logger.group();
logger.log('test sub group demo');
logger.warn('danger');
logger.error('error in sub group')
logger.group();
logger.log('333 test sub group demo');
logger.warn('333 danger');
logger.error('333 error in sub group')
logger.groupEnd();
logger.error('222 error in sub group')
logger.error('222 error in sub group')
logger.groupEnd();
logger.error('111 error in sub group')
logger.groupEnd();
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