Comparing version 0.1.0 to 1.0.0
56
index.js
'use strict'; | ||
var moment = require('moment'), | ||
inspect = require('util').inspect, | ||
printf = require('util').format, | ||
colors = require('colors'); | ||
var emptyFn = function () {}, | ||
useColor = Boolean(process.stdout.isTTY); | ||
const moment = require('moment'); | ||
const inspect = require('util').inspect; | ||
const printf = require('util').format; | ||
const colors = require('colors'); | ||
const emptyFn = function () {}; | ||
const useColor = Boolean(process.stdout.isTTY); | ||
colors.setTheme({ | ||
@@ -31,4 +32,4 @@ error: 'red', | ||
var split = keys.split(/[\s,]+/); | ||
split.forEach(function (key) { | ||
const split = keys.split(/[\s,]+/); | ||
split.forEach((key) => { | ||
if (!key) { | ||
@@ -101,3 +102,3 @@ return; | ||
function write(msg) { | ||
console.log.apply(console, [msg]); | ||
console.log(msg); | ||
} | ||
@@ -111,3 +112,3 @@ | ||
function format(data) { | ||
var args = Array.prototype.slice.call(data.args, 0).map(function (arg) { | ||
const args = data.args.map((arg) => { | ||
if (arg instanceof Error) { | ||
@@ -123,5 +124,5 @@ return arg.stack; | ||
var msg = printf.apply(printf, args), | ||
fmt = ['%s'], | ||
vals = [colorize('grey', data.date)]; | ||
const msg = printf.apply(printf, args); | ||
const fmt = ['%s']; | ||
const vals = [colorize('grey', data.date)]; | ||
@@ -156,3 +157,3 @@ if (data.name) { | ||
function log(name, opts) { | ||
if (typeof(name) === 'object') { | ||
if (typeof (name) === 'object') { | ||
opts = name; | ||
@@ -164,8 +165,8 @@ name = undefined; | ||
var dateFn = opts.date || date, | ||
formatFn = opts.format || format, | ||
writeFn = opts.write || write, | ||
levels = ['error', 'warn', 'info', 'debug'].concat(opts.levels || []), | ||
enable = { all: {}, name: {}, level: {} }, | ||
skip = { name: {}, level: {} }; | ||
const dateFn = opts.date || date; | ||
const formatFn = opts.format || format; | ||
const writeFn = opts.write || write; | ||
const levels = ['error', 'warn', 'info', 'debug'].concat(opts.levels || []); | ||
const enable = { all: {}, name: {}, level: {} }; | ||
const skip = { name: {}, level: {} }; | ||
@@ -175,11 +176,11 @@ parseFilter('name', opts.nameFilter || process.env.LOGNAMES, enable, skip); | ||
var logger = function (level) { | ||
const logger = function (level) { | ||
if (!enabled(name, level, enable, skip)) { | ||
return emptyFn; | ||
} | ||
return function () { | ||
return (...args) => { | ||
writeFn(formatFn({ | ||
date: dateFn(), | ||
name: name, | ||
args: arguments, | ||
args: args || [], | ||
level: level | ||
@@ -190,5 +191,5 @@ })); | ||
var fn = logger(); | ||
const fn = logger(); | ||
levels.forEach(function (level) { | ||
levels.forEach((level) => { | ||
fn[level] = logger(level); | ||
@@ -206,5 +207,4 @@ }); | ||
module.exports = function (name, opts) { | ||
return log(name, opts); | ||
}; | ||
return log(name, opts); | ||
}; |
{ | ||
"name": "aut", | ||
"version": "0.1.0", | ||
"version": "1.0.0", | ||
"description": "Simple logging library with filtering using environment variables", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "jshint test/ index.js && istanbul test --preload-sources _mocha -- -u exports -R spec 'test/**/*.test.js'", | ||
"ci": "npm test --coverage && istanbul report cobertura", | ||
"lint": "eslint --ext '.js' index.js test", | ||
"watch": "mocha --watch 'test/**/*.js' 'index.js' --timeout 500", | ||
"test": "npm run lint && nyc --reporter=text-summary --reporter=lcov mocha", | ||
"release": "npm test && release-it -n -i patch", | ||
@@ -17,2 +18,5 @@ "release:minor": "npm test && release-it -n -i minor", | ||
}, | ||
"engines": { | ||
"node": ">=12.0.0" | ||
}, | ||
"keywords": [ | ||
@@ -29,12 +33,14 @@ "log", | ||
"dependencies": { | ||
"colors": "^1.0.3", | ||
"moment": "^2.8.3" | ||
"colors": "^1.4.0", | ||
"moment": "^2.29.1" | ||
}, | ||
"devDependencies": { | ||
"istanbul": "^0.3.2", | ||
"jshint": "^2.5.6", | ||
"mocha": "^1.21.4", | ||
"release-it": "0.0.11", | ||
"should": "^4.0.4" | ||
"@aptoma/eslint-config": "^7.0.1", | ||
"eslint": "^7.20.0", | ||
"eslint-plugin-mocha": "^8.0.0", | ||
"mocha": "^8.3.0", | ||
"nyc": "^15.1.0", | ||
"release-it": "^14.4.1", | ||
"should": "^13.2.3" | ||
} | ||
} | ||
} |
122
README.md
@@ -31,68 +31,70 @@ [](https://travis-ci.org/martinj/node-aut) | ||
var log = require('aut')(); | ||
log('foo bar'); | ||
log('foo bar', { a: 'b' }); | ||
log.error(new Error('Shit')); | ||
log.debug('hmm %s thats cool', 'wow'); | ||
log.warn('oh my'); | ||
log.info('aha..'); | ||
```javascript | ||
const log = require('aut')(); | ||
log('foo bar'); | ||
log('foo bar', { a: 'b' }); | ||
log.error(new Error('Shit')); | ||
log.debug('hmm %s thats cool', 'wow'); | ||
log.warn('oh my'); | ||
log.info('aha..'); | ||
// 13 Nov 16:41:53 - foo bar | ||
// 13 Nov 16:41:53 - foo bar { a: 'b' } | ||
// 13 Nov 16:41:53 [error] - Error: Shit | ||
// at Object.<anonymous> (/Users/martin/foo/test.js:4:11) | ||
// at Module._compile (module.js:456:26) | ||
// at Object.Module._extensions..js (module.js:474:10) | ||
// at Module.load (module.js:356:32) | ||
// at Function.Module._load (module.js:312:12) | ||
// at Function.Module.runMain (module.js:497:10) | ||
// at startup (node.js:119:16) | ||
// at node.js:906:3 | ||
// 13 Nov 16:41:53 [debug] - hmm wow thats cool | ||
// 13 Nov 16:41:53 [warn] - oh my | ||
// 13 Nov 16:41:53 [info] - aha.. | ||
// 13 Nov 16:41:53 - foo bar | ||
// 13 Nov 16:41:53 - foo bar { a: 'b' } | ||
// 13 Nov 16:41:53 [error] - Error: Shit | ||
// at Object.<anonymous> (/Users/martin/foo/test.js:4:11) | ||
// at Module._compile (module.js:456:26) | ||
// at Object.Module._extensions..js (module.js:474:10) | ||
// at Module.load (module.js:356:32) | ||
// at Function.Module._load (module.js:312:12) | ||
// at Function.Module.runMain (module.js:497:10) | ||
// at startup (node.js:119:16) | ||
// at node.js:906:3 | ||
// 13 Nov 16:41:53 [debug] - hmm wow thats cool | ||
// 13 Nov 16:41:53 [warn] - oh my | ||
// 13 Nov 16:41:53 [info] - aha.. | ||
var log2 = require('aut')('log2'); | ||
log2('foo bar'); | ||
log2('foo bar', { a: 'b' }); | ||
log2.error(new Error('Shit')); | ||
log2.debug('hmm %s thats cool', 'wow'); | ||
log2.warn('oh my'); | ||
log2.info('aha..'); | ||
const log2 = require('aut')('log2'); | ||
log2('foo bar'); | ||
log2('foo bar', { a: 'b' }); | ||
log2.error(new Error('Shit')); | ||
log2.debug('hmm %s thats cool', 'wow'); | ||
log2.warn('oh my'); | ||
log2.info('aha..'); | ||
// 13 Nov 16:41:53 log2 - foo bar | ||
// 13 Nov 16:41:53 log2 - foo bar { a: 'b' } | ||
// 13 Nov 16:41:53 log2 [error] - Error: Shit | ||
// at Object.<anonymous> (/Users/martin/foo/test.js:27:12) | ||
// at Module._compile (module.js:456:26) | ||
// at Object.Module._extensions..js (module.js:474:10) | ||
// at Module.load (module.js:356:32) | ||
// at Function.Module._load (module.js:312:12) | ||
// at Function.Module.runMain (module.js:497:10) | ||
// at startup (node.js:119:16) | ||
// at node.js:906:3 | ||
// 13 Nov 16:41:53 log2 [debug] - hmm wow thats cool | ||
// 13 Nov 16:41:53 log2 [warn] - oh my | ||
// 13 Nov 16:41:53 log2 [info] - aha.. | ||
// 13 Nov 16:41:53 log2 - foo bar | ||
// 13 Nov 16:41:53 log2 - foo bar { a: 'b' } | ||
// 13 Nov 16:41:53 log2 [error] - Error: Shit | ||
// at Object.<anonymous> (/Users/martin/foo/test.js:27:12) | ||
// at Module._compile (module.js:456:26) | ||
// at Object.Module._extensions..js (module.js:474:10) | ||
// at Module.load (module.js:356:32) | ||
// at Function.Module._load (module.js:312:12) | ||
// at Function.Module.runMain (module.js:497:10) | ||
// at startup (node.js:119:16) | ||
// at node.js:906:3 | ||
// 13 Nov 16:41:53 log2 [debug] - hmm wow thats cool | ||
// 13 Nov 16:41:53 log2 [warn] - oh my | ||
// 13 Nov 16:41:53 log2 [info] - aha.. | ||
var log3 = require('aut')('custom', { | ||
date: function () { return 'My Custom Date'; }, | ||
write: function (msg) { console.log(msg); }, | ||
levels: ['mega', 'alpha'], | ||
format: function (data) { | ||
return Object.keys(data).map(function (k) { | ||
return k + ': ' + data[k]; | ||
}).join(', '); | ||
} | ||
}); | ||
const log3 = require('aut')('custom', { | ||
date: function () { return 'My Custom Date'; }, | ||
write: function (msg) { console.log(msg); }, | ||
levels: ['mega', 'alpha'], | ||
format: function (data) { | ||
return Object.keys(data).map(function (k) { | ||
return k + ': ' + data[k]; | ||
}).join(', '); | ||
} | ||
}); | ||
log3('foo bar'); | ||
log3('foo bar', { a: 'b' }); | ||
log3.mega(new Error('Shit')); | ||
log3.alpha('hmm'); | ||
log3('foo bar'); | ||
log3('foo bar', { a: 'b' }); | ||
log3.mega(new Error('Shit')); | ||
log3.alpha('hmm'); | ||
// date: My Custom Date, prefix: custom, args: [object Arguments] | ||
// date: My Custom Date, prefix: custom, args: [object Arguments] | ||
// date: My Custom Date, prefix: custom, args: [object Arguments], level: mega | ||
// date: My Custom Date, prefix: custom, args: [object Arguments], level: alpha | ||
// date: My Custom Date, prefix: custom, args: [object Arguments] | ||
// date: My Custom Date, prefix: custom, args: [object Arguments] | ||
// date: My Custom Date, prefix: custom, args: [object Arguments], level: mega | ||
// date: My Custom Date, prefix: custom, args: [object Arguments], level: alpha | ||
``` | ||
@@ -5,5 +5,5 @@ 'use strict'; | ||
describe('aut', function () { | ||
it('should add custom levels', function () { | ||
var log = require('../')({ | ||
describe('aut', () => { | ||
it('should add custom levels', () => { | ||
const log = require('../')({ | ||
levels: ['foo'] | ||
@@ -15,6 +15,6 @@ }); | ||
it('should format output', function (done) { | ||
var log = require('../')('test', { | ||
date: function () { return 'Date'; }, | ||
write: function (str) { | ||
it('should format output', (done) => { | ||
const log = require('../')('test', { | ||
date: () => 'Date', | ||
write(str) { | ||
str.should.equal('\u001b[90mDate\u001b[39m test - foobar'); | ||
@@ -28,4 +28,4 @@ done(); | ||
it('should filter names', function () { | ||
var log = require('../')({ | ||
it('should filter names', () => { | ||
let log = require('../')({ | ||
nameFilter: '*,-log2' | ||
@@ -46,4 +46,4 @@ }); | ||
it('should filter levels', function () { | ||
var log = require('../')({ | ||
it('should filter levels', () => { | ||
let log = require('../')({ | ||
levelFilter: '*,-warn' | ||
@@ -62,2 +62,2 @@ }); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
8
226
0
100
9901
7
Updatedcolors@^1.4.0
Updatedmoment@^2.29.1