Skip to content

Commit

Permalink
[[CHORE]] Update some things to ES6
Browse files Browse the repository at this point in the history
  • Loading branch information
jmendiara committed May 6, 2017
1 parent a2db9aa commit e8bd06e
Show file tree
Hide file tree
Showing 5 changed files with 561 additions and 230 deletions.
5 changes: 3 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"env": {
"node": true
"node": true,
"es6": true
},
"rules": {
"no-use-before-define": [2, "nofunc"], //latedef in jshint
"quotes": [2, "single"]
}
}
}
29 changes: 10 additions & 19 deletions lib/formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,8 @@ function formatDevTrace(level, context, message, args, err) {

if (isErrorLoggingWithoutMessage) {
str += colorize(colors.gray, serializeErr(err).toString(printStack).substr(mainMessage.length));
} else {
if (err) {
str += '\n' + colorize(colors.gray, serializeErr(err).toString(printStack));
}
} else if (err) {
str += '\n' + colorize(colors.gray, serializeErr(err).toString(printStack));
}

var localContext = omit(context, formatDevTrace.omit);
Expand All @@ -116,9 +114,7 @@ formatDevTrace.omit = [];
function colorize(color, str) {
return str
.split('\n')
.map(function(part) {
return color(part);
})
.map(part => color(part))
.join('\n');
}

Expand Down Expand Up @@ -194,17 +190,12 @@ function formatJsonTrace(level, context, message, args, err) {

formatJsonTrace.stringify = stringify;
formatJsonTrace.toObject = function toObject(level, context, message, args, err) {
var log = {},
printStack = API.stacktracesWith.indexOf(level) > -1;

for (var attrname in context) {
log[attrname] = context[attrname];
}

log.time = new Date();
log.lvl = level;
log.err = err && serializeErr(err).toObject(printStack);
log.msg = util.format.apply(global, [message].concat(args));
const printStack = API.stacktracesWith.indexOf(level) > -1;

return log;
return Object.assign({}, context, {
time: new Date().toISOString(),
lvl: level,
err: err && serializeErr(err).toObject(printStack),
msg: util.format(message, ...args)
});
};
21 changes: 1 addition & 20 deletions lib/logops.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function logWrap(level) {
args = Array.prototype.slice.call(arguments, 2);
} else {
// log.<level>(fields, msg, ...)
context = merge(API.getContext(), arguments[1]);
context = Object.assign({}, API.getContext(), arguments[1]);
message = arguments[2];
args = Array.prototype.slice.call(arguments, 3);
}
Expand All @@ -73,25 +73,6 @@ function logWrap(level) {
API.stream.write(trace + '\n');
}

/**
* Merges accesible properties in two objects.
* obj2 takes precedence when common properties are found
*
* @param {Object} obj1
* @param {Object} obj2
* @returns {{}} The merged, new, object
*/
function merge(obj1, obj2) {
var res = {}, attrname;
for (attrname in obj1) {
res[attrname] = obj1[attrname];
}
for (attrname in obj2) {
res[attrname] = obj2[attrname];
}
return res;
}

/**
* Sets the enabled logging level.
* All the disabled logging methods are replaced by a noop,
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
"chai": "^3.0.0",
"conventional-changelog-cli": "^1.1.0",
"coveralls": "^2.11.2",
"eslint": "^2.2.0",
"eslint": "^3.19.0",
"istanbul": "^0.4.0",
"jscs": "^3.0.3",
"mocha": "^2.2.5",
"mocha": "^3.3.0",
"release-it": "^2.3.1",
"sinon": "^1.15.0",
"sinon": "^2.2.0",
"sinon-chai": "^2.8.0",
"tslint": "^3.14.0",
"tslint-config-typings": "^0.2.3",
"tslint": "^5.2.0",
"tslint-config-typings": "^0.3.1",
"typescript": "^2.0.3"
},
"keywords": [
Expand Down
Loading

0 comments on commit e8bd06e

Please sign in to comment.