Skip to content

Commit

Permalink
Require node >= 12
Browse files Browse the repository at this point in the history
Update dependencies
  • Loading branch information
martinj committed Feb 27, 2021
1 parent d598e7d commit b0f12e1
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 167 deletions.
17 changes: 17 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"plugins": [
"mocha"
],
"extends": "@aptoma/eslint-config",
"rules": {
"object-curly-spacing": ["error", "always"]
},
"parserOptions": {
"ecmaVersion": 9
},
"env": {
"node": true,
"mocha": true,
"es6": true
}
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules
coverage
package-lock.json
.nyc_output
47 changes: 0 additions & 47 deletions .jshintrc

This file was deleted.

6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
language: node_js
node_js:
- 0.10

script:
- npm run ci
- 12
- 14
134 changes: 68 additions & 66 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,70 +28,72 @@ Show specific names & levels

## Examples

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..');

// 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..');

// 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(', ');
}
});

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
```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..

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..

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');

// 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
```

56 changes: 28 additions & 28 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
'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({
error: 'red',
Expand All @@ -28,8 +29,8 @@ function parseFilter(type, keys, enable, skip) {
}
enable.all[type] = false;

var split = keys.split(/[\s,]+/);
split.forEach(function (key) {
const split = keys.split(/[\s,]+/);
split.forEach((key) => {
if (!key) {
return;
}
Expand Down Expand Up @@ -97,7 +98,7 @@ function date() {
* @param {String} msg
*/
function write(msg) {
console.log.apply(console, [msg]);
console.log(msg);
}

/**
Expand All @@ -106,7 +107,7 @@ function write(msg) {
* @return {String}
*/
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) {
return arg.stack;
}
Expand All @@ -117,9 +118,9 @@ function format(data) {
return arg;
});

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)];

if (data.name) {
fmt.push('%s');
Expand Down Expand Up @@ -149,40 +150,40 @@ function format(data) {
* @return {Function}
*/
function log(name, opts) {
if (typeof(name) === 'object') {
if (typeof (name) === 'object') {
opts = name;
name = undefined;
} else {
opts = opts || {};
}

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: {} };

parseFilter('name', opts.nameFilter || process.env.LOGNAMES, enable, skip);
parseFilter('level', opts.levelFilter || process.env.LOGLEVELS, 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
}));
};
};

var fn = logger();
const fn = logger();

levels.forEach(function (level) {
levels.forEach((level) => {
fn[level] = logger(level);
});

Expand All @@ -195,7 +196,6 @@ function log(name, opts) {
return fn;
}


module.exports = function (name, opts) {
return log(name, opts);
};
return log(name, opts);
};
26 changes: 16 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
"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",
"release:minor": "npm test && release-it -n -i minor",
"release:major": "npm test && release-it -n -i major"
Expand All @@ -14,6 +15,9 @@
"type": "git",
"url": "https://github.com/martinj/node-aut"
},
"engines": {
"node": ">=12.0.0"
},
"keywords": [
"log",
"logging"
Expand All @@ -25,14 +29,16 @@
},
"homepage": "https://github.com/martinj/node-aut",
"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"
}
}
}
Loading

0 comments on commit b0f12e1

Please sign in to comment.