-
Notifications
You must be signed in to change notification settings - Fork 10
Winson 3 support - Fixes #12 #14
base: master
Are you sure you want to change the base?
Conversation
Looks like the CI (v8, v10) is failing because updated lock files weren't commited along with the version bumps in v4 is failing because winston@3 no longer supports v4. Must be >6.4.0. |
- v8, v10: Failed because `package-lock.json` wasn't in sync with `package.json` - v4: Fails because winston@3 is >v6.4.0
@halkeye I tried pushing updates to your branch, but it failed
I created a PR with the fixes on your fork: halkeye#1 |
@eugeny-dementev: Would you retire node v4 from CI now that winston@3 no longer supports it? |
good catch, i didn't even look, i got distracted |
yea, 4 is past end of life - https://github.com/nodejs/Release which was 2018-04-30 |
src/mixin.js
Outdated
delete remainingInfo.trace; | ||
delete remainingInfo.message; | ||
delete remainingInfo.timestamp; | ||
delete remainingInfo.label; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think level
needs to be removed, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Easy to change. Can you tell me what behavior is happening so I can write a test for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Winston logs made with logger.info('blah')
render as something like:
[INFO] blah
- level: 'info'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I totally noticed after commenting and forgot to comment again
Its fixed in the new formatter, and the test is updated
@halkeye: Thanks for merging in the formatter vs mixin changes from #12 (comment) @BudgieInWA: Anything blocking this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Someone needs to decide where to export this winston@3 formatter, but I like hiding it away in winston-console-formatter/dist/formatter
until a decision about the post-winston-3 API is made.
package.json
Outdated
@@ -12,7 +15,8 @@ | |||
"lab": "^13.1.0", | |||
"pre-commit": "^1.2.2", | |||
"prettier": "^1.8.2", | |||
"sinon": "^4.1.3" | |||
"sinon": "^4.1.3", | |||
"winston": "^3.1.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure winston
is a regular dependency here, not a dev dependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yea.. when I first added it, it was purely for the tests, but now its the formatter, i'll get it fixed.
src/formatter.js
Outdated
delete remainingInfo.message; | ||
delete remainingInfo.timestamp; | ||
delete remainingInfo.label; | ||
delete remainingInfo.level; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this project uses the spread syntax, so this file can too. e.g. this can be expressed as:
module.exports = function ConsoleFormatter({
postfix = '',
prefix = '',
stackTrace = true,
colors = defaultErrorColors,
types = yamlifyColors,
}) {
return format(info => {
const { level, label, message, timestamp, from, stack, trace, ...remainingInfo } = info;
//...
})
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I originally had it that way, but something broke, I feel like tests or something, I'll certainly try it again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
> [email protected] test /home/halkeye/go/src/github.com/halkeye/winston-console-formatter
> lab -T node_modules/babel-lab test/suites/*.js -l
/home/halkeye/go/src/github.com/halkeye/winston-console-formatter/node_modules/babel-core/lib/transformation/file/index.js:590
throw err;
^
SyntaxError: unknown: Unexpected token (24:66)
22 | }, options);
23 |
> 24 | const { level, label, message, timestamp, from, stack, trace, ...remainingInfo } = info;
| ^
Yea, the tests don't run though babel, so it doesn't transpile them, and I think Object explode is only in 10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh well, someone can solve that in the future of they want to :)
src/formatter.js
Outdated
const { format } = require('winston'); | ||
|
||
module.exports = function WinstonConsoleFormatter(options = {}) { | ||
options = Object.assign({}, options, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this assign override any caller-provided options?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, must have been tired when i wrote it, I'll get it updated and add some tests
src/formatter.js
Outdated
colors: defaultErrorColors, | ||
types: yamlifyColors, | ||
}); | ||
return format(info => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This API is a little bit different to the logform API. I think we should aim to blend in with the logform loggers. For example, this is format.json
:
module.exports = format((info, opts = {}) => {
info[MESSAGE] = jsonStringify(info, opts.replacer || replacer, opts.space);
return info;
});
The object that is passed to the formatter when it is created (e.g. new transports.Console({ formatter: format.json({ space: true }) })
) is passed as the second argument to all calls to your format fn.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I like that a lot
I'll make sure to refer back to https://github.com/winstonjs/logform#understanding-formats when I do it, I don't think i reviewed the docs, just copied an example
if its exported it makes it way harder |
okay, i think all the issues are handled. site note, when formatter.js test was crashing, all tests stopped running, with no errors in CI hopefully codecov will fix it, or maybe it should get migrated to jest or something. |
|
||
module.exports = format((info, options = {}) => { | ||
options = Object.assign( | ||
{}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the defaults below are in an object literal, we don't need to have an empty object literal here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, but this is safer, there's no way for us to modify the object passed in.
First parameter is what everything is merged into, and since it's passed by reference I always err on the side of caution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh shit you mean because the second one w literal. Yea yea. Could do. I didn't look at the diff close enough. I'll change it I change anything else.
Looks good to me.
I have had a pretty easy time with Jest, including their snapshot testing (which is what a lot of these tests are). |
any update? |
What is the current status of this? |
any update? |
I created a new file called mixin, which wrapps around a transport and does all the formatting just for that transport
This way it can be used for console logging, or file logging, or anything else the old one did.
Totally open to feedback