Comparing version 2.0.21 to 3.0.0
@@ -0,118 +1,141 @@ | ||
'use strict'; | ||
var Util = require('util'), | ||
Style = require('./style'), | ||
NiceTime = require('./niceTime'), | ||
Cluster = require('cluster'); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var isWorker = Cluster.isWorker && Cluster.worker; | ||
var _chalk = require('chalk'); | ||
var clusterCPU = isWorker ? Cluster.worker.id | ||
: 'CLUSTER_UNIQUE_ID' in process.env ? process.env.CLUSTER_UNIQUE_ID | ||
: 'NODE_WORKER_ID' in process.env ? process.env.NODE_WORKER_ID | ||
: 'CLUSTER_WORKER' in process.env ? process.env.CLUSTER_WORKER | ||
: ''; | ||
var _prettyFormat = require('@ava/pretty-format'); | ||
clusterCPU = clusterCPU ? Style(Style.GREEN, clusterCPU + '.') : ''; | ||
var _prettyFormat2 = _interopRequireDefault(_prettyFormat); | ||
var TIMEZONE_OFFSET = (240 - (new Date).getTimezoneOffset()) * 60000; | ||
var _debug = require('debug'); | ||
var _debug2 = _interopRequireDefault(_debug); | ||
function stdTimezoneOffset() { | ||
var fullYear = (new Date()).getFullYear(); | ||
var jan = new Date(fullYear, 0, 1); | ||
var jul = new Date(fullYear, 6, 1); | ||
return Math.min(jan.getTimezoneOffset(), jul.getTimezoneOffset()) * 60000; | ||
} | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
TIMEZONE_OFFSET = TIMEZONE_OFFSET < stdTimezoneOffset() ? TIMEZONE_OFFSET + 3600000 : TIMEZONE_OFFSET; | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
function writeLog(d) { | ||
var time = function time() { | ||
var now = new Date(); | ||
var date = new Date(now.getTime() - now.getTimezoneOffset() * 60000); | ||
return date.toISOString().replace(/.*T(.*)Z/, '$1'); | ||
}; | ||
var res = process.stdout.write(d + '\n'); | ||
var logger = function logger(_ref) { | ||
var title = _ref.title, | ||
messages = _ref.messages, | ||
logFunction = _ref.logFunction; | ||
// this is the first time stdout got backed up | ||
if (!res && !process.stdout.pendingWrite) { | ||
process.stdout.pendingWrite = true; | ||
var formattedMessages = messages.map(function (message) { | ||
if (typeof message === 'string') { | ||
return message; | ||
} | ||
return (0, _prettyFormat2.default)(message, { | ||
highlight: true, | ||
min: true, | ||
theme: { | ||
tag: 'cyan', | ||
content: 'reset', | ||
prop: 'yellow', | ||
value: 'green', | ||
number: 'green', | ||
string: 'reset', | ||
date: 'green', | ||
symbol: 'red', | ||
regex: 'red', | ||
function: 'blue', | ||
error: 'red', | ||
boolean: 'yellow', | ||
label: 'blue', | ||
bracket: 'grey', | ||
comma: 'grey', | ||
misc: 'grey', | ||
key: 'cyan' | ||
} | ||
}); | ||
}); | ||
logFunction.apply(undefined, [(0, _chalk.gray)(time()), `[${title}]`].concat(_toConsumableArray(formattedMessages))); | ||
}; | ||
// magic sauce: keep node alive until stdout has flushed | ||
process.stdout.once('drain', function () { | ||
process.stdout.draining = false; | ||
}); | ||
} | ||
} | ||
var createLogger = function createLogger(title) { | ||
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
_ref2$debugFunction = _ref2.debugFunction, | ||
debugFunction = _ref2$debugFunction === undefined ? (0, _debug2.default)(title) : _ref2$debugFunction, | ||
_ref2$logFunction = _ref2.logFunction, | ||
logFunction = _ref2$logFunction === undefined ? console.log : _ref2$logFunction; | ||
function record(messages, file) { | ||
return { | ||
debug() { | ||
for (var _len = arguments.length, messages = Array(_len), _key = 0; _key < _len; _key++) { | ||
messages[_key] = arguments[_key]; | ||
} | ||
var date = new Date(); | ||
date.setTime(date - TIMEZONE_OFFSET); | ||
var niceTime = NiceTime(date); | ||
logger({ | ||
title: (0, _chalk.yellow)(`DEBUG ${title}`), | ||
messages, | ||
logFunction: debugFunction | ||
}); | ||
}, | ||
info() { | ||
for (var _len2 = arguments.length, messages = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
messages[_key2] = arguments[_key2]; | ||
} | ||
var output = [], | ||
keys = Object.keys(messages); | ||
logger({ | ||
title: (0, _chalk.blue)(title), | ||
messages, | ||
logFunction | ||
}); | ||
}, | ||
warn() { | ||
for (var _len3 = arguments.length, messages = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { | ||
messages[_key3] = arguments[_key3]; | ||
} | ||
keys.forEach(function(key) { | ||
logger({ | ||
title: (0, _chalk.yellow)(`WARNING ${title}`), | ||
messages, | ||
logFunction | ||
}); | ||
}, | ||
error() { | ||
for (var _len4 = arguments.length, messages = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { | ||
messages[_key4] = arguments[_key4]; | ||
} | ||
var msg = messages[key]; | ||
switch (typeof msg) { | ||
case 'string': | ||
var length = msg.length; | ||
if (length && msg[0] === '(' && msg[length - 1] === ')') { | ||
output.push(Style(Style.CYAN, msg.substring(1, length - 1))); | ||
} else if (length && msg[0] === '[' && msg[length - 1] === ']') { | ||
output.push(Style(Style.BLUE, msg.substring(1, length - 1))); | ||
} else if (length && msg[0] === '{' && msg[length - 1] === '}') { | ||
output.push(Style(Style.MAGENTA, msg.substring(1, length - 1))); | ||
} else if (length && msg[0] === '*' && msg[length - 1] === '*') { | ||
output.push(Style(Style.RED_BOLD, msg)); | ||
logger({ | ||
title: (0, _chalk.red)(`ERROR ${title}`), | ||
messages, | ||
logFunction | ||
}); | ||
}, | ||
fatal() { | ||
for (var _len5 = arguments.length, messages = Array(_len5), _key5 = 0; _key5 < _len5; _key5++) { | ||
messages[_key5] = arguments[_key5]; | ||
} | ||
// for error or Error | ||
} else if (length && msg.substr(1, 4) === 'rror') { | ||
output.push(Style(Style.RED, msg)); | ||
logger({ | ||
title: (0, _chalk.red)(`========= FATAL ${title} =========`), | ||
messages, | ||
logFunction | ||
}); | ||
}, | ||
trace() { | ||
for (var _len6 = arguments.length, messages = Array(_len6), _key6 = 0; _key6 < _len6; _key6++) { | ||
messages[_key6] = arguments[_key6]; | ||
} | ||
} else if (length && msg.substr(0, 4) === 'fail') { | ||
output.push(Style(Style.RED, msg)); | ||
} else if (length && msg.substr(0, 7) === 'http://') { | ||
output.push(Style(Style.UNDERLINE, msg)); | ||
} else { | ||
output.push(Style(Style.WHITE, msg)); | ||
} | ||
break; | ||
case 'number': | ||
output.push(Style(Style.YELLOW, msg)); | ||
break; | ||
case 'function': | ||
output.push(Style(Style.YELLOW_BOLD, msg.toString())); | ||
break; | ||
default: | ||
msg = Util.inspect(msg, false, 6, true); | ||
if (msg.length > 80) { | ||
msg = ("\n" + msg).split(/\n/).join("\n "); | ||
} | ||
output.push(msg); | ||
break; | ||
logger({ | ||
title: (0, _chalk.red)(`TRACE ${title}`), | ||
messages, | ||
logFunction | ||
}); | ||
} | ||
}); | ||
writeLog(niceTime + ' - ' | ||
+ (file ? '[' : '') | ||
+ clusterCPU | ||
+ (file ? Style(Style.GREEN, file) : '') | ||
+ (file ? '] - ' : '') | ||
+ output.join(' ').replace(/\n/g, '\n' + ' ')); | ||
} | ||
var Log = exports = module.exports = function Log() { | ||
return record(arguments); | ||
}; | ||
}; | ||
Log.from = function(path) { | ||
var file = path.split('/').pop().split('.')[0]; | ||
var log_function = function() { record(arguments, file); }; | ||
log_function.array = function(array) { record(array, file);}; | ||
return log_function; | ||
}; | ||
exports.default = createLogger; |
{ | ||
"name": "logging", | ||
"version": "2.0.21", | ||
"description": "Super sexy color console logging with cluster support.", | ||
"homepage": "http://github.com/dylang/logging", | ||
"author": "Dylan Greene <dylang@gmail.com>", | ||
"contributors": [ | ||
"Dylan Greene <dylang@gmail.com>" | ||
], | ||
"repository": | ||
{ | ||
"type": "git", | ||
"url": "http://github.com/dylang/logging" | ||
}, | ||
"bugs": | ||
{ | ||
"mail": "dylang@gmail.com", | ||
"url": "http://github.com/dylang/logging/issues" | ||
}, | ||
"main": "index", | ||
"scripts": { | ||
"test": "nodeunit test" | ||
}, | ||
"devDependencies": { | ||
"nodeunit": "*" | ||
}, | ||
"engines": { "node": ">=0.4.0" }, | ||
"licenses" : | ||
[ | ||
{ "type" : "MIT", "url" : "http://github.com/isaacs/npm/raw/master/LICENSE" } | ||
"name": "logging", | ||
"version": "3.0.0", | ||
"description": "Lightweight informative modern console logging.", | ||
"main": "lib", | ||
"module": "src", | ||
"files": [ | ||
"lib", | ||
"src" | ||
], | ||
"scripts": { | ||
"start": "babel-node src", | ||
"test": "npm -s run lint && ava --verbose && npm -s run example", | ||
"update-snapshots": "ava --verbose --update-snapshots", | ||
"lint": "eslint -c .eslintrc.js . --fix", | ||
"build": "babel src --out-dir=lib", | ||
"outdated": "npm-check -s", | ||
"example": "babel-node examples/simple.js", | ||
"prepublish": "npm -s run build", | ||
"precommit": "npm -s run test", | ||
"publish": "np" | ||
}, | ||
"repository": "http://github.com/dylang/logging", | ||
"author": "Dylan Greene <dylang@gmail.com>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@ava/pretty-format": "^1.1.0", | ||
"chalk": "^1.1.3", | ||
"debug": "^2.6.1" | ||
}, | ||
"devDependencies": { | ||
"ava": "^0.18.2", | ||
"babel-cli": "^6.23.0", | ||
"babel-core": "^6.23.1", | ||
"babel-polyfill": "^6.23.0", | ||
"babel-preset-env": "^1.1.6", | ||
"babel-runtime": "^6.23.0", | ||
"eslint": "^3.15.0", | ||
"eslint-config-xo": "^0.17.0", | ||
"eslint-loader": "^1.6.0", | ||
"eslint-plugin-ava": "^4.2.0", | ||
"eslint-plugin-import": "^2.0.1", | ||
"eslint-plugin-no-use-extend-native": "^0.3.11", | ||
"eslint-plugin-promise": "^3.4.2", | ||
"eslint-plugin-unicorn": "^2.0.1", | ||
"husky": "^0.13.1", | ||
"mockdate": "^2.0.1", | ||
"nodemon": "^1.11.0", | ||
"np": "^2.12.0", | ||
"npm": "^4.2.0", | ||
"npm-check": "^5.4.0", | ||
"sinon": "^2.0.0-pre.4" | ||
}, | ||
"engines": { | ||
"node": ">= 4" | ||
}, | ||
"ava": { | ||
"require": [ | ||
"babel-register" | ||
] | ||
} | ||
} | ||
} |
@@ -0,73 +1,37 @@ | ||
# Logging [![Build Status](https://secure.travis-ci.org/dylang/logging.png)](https://travis-ci.org/dylang/logging) | ||
# Logging [![Build Status](https://secure.travis-ci.org/dylang/logging.png)](http://travis-ci.org/dylang/logging) | ||
Lightweight informative modern console logging. | ||
Super sexy color console logging with cluster support. | ||
## Install | ||
npm install logging | ||
```sh | ||
yarn add logging | ||
``` | ||
## Features | ||
* Simple. | ||
* Log levels. | ||
* Nice coloring. | ||
* Works in the browser. | ||
## Usage | ||
var log = require('logging').from(__filename); | ||
```js | ||
// or const createLogger = require('logging'); | ||
import createLogger from 'logging'; | ||
log('hello world'); | ||
const logger = createLogger('FeatureName'); | ||
log('counter', 123); | ||
logger.info('Interesting'); | ||
// -> [ Feature ] Interesting | ||
log('global variables', global); | ||
logger.warn('Hmmm...', { details }); | ||
// -> [ WARNING Feature ] Hmmm... { details object } | ||
log(1, "2", [ 3, 4 ], { 5: 6 }, function() { return 7; }); | ||
logger.error('Not good.', 'Not good at all.', { err }, { context }, { etc }); | ||
// -> [ ERROR Feature ] Not good. Not good at all. { err } { context } ... | ||
## Features | ||
* Color | ||
* Timestamp | ||
* Filename | ||
* Cluster Worker id | ||
* Inspects arrays, objects, functions - all in color. | ||
* Fast | ||
* Easy | ||
* Used in production on Node Knockout winner [Doodle or Die](http://DoodleOrDie.com). | ||
## Todo | ||
* Timezone, 24/12-hour options. | ||
* Wire up the tests. | ||
* More colors/effects. | ||
* warn/error. | ||
## Contributors | ||
* Dylan Greene [dylang](http://github.com/dylang) | ||
## External Dependencies | ||
* Node | ||
## License | ||
(The MIT License) | ||
Copyright (c) 2009-2010 Dylan Greene <dylang@gmail.com> | ||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
'Software'), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
// uses the debug module, use DEBUG=* or DEBUG=FeatureName to see these items. | ||
logger.debug('Interesting'); | ||
// -> [ Feature ] Interesting | ||
``` |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 4 instances in 1 package
230
1
11233
3
21
7
1
1
38
1
+ Added@ava/pretty-format@^1.1.0
+ Addedchalk@^1.1.3
+ Addeddebug@^2.6.1
+ Added@ava/pretty-format@1.1.0(transitive)
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@2.2.1(transitive)
+ Addedchalk@1.1.3(transitive)
+ Addeddebug@2.6.9(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedesutils@2.0.3(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedms@2.0.0(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)