Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Winson 3 support - Fixes #12 #14

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

halkeye
Copy link

@halkeye halkeye commented Oct 24, 2018

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

@rmharrison
Copy link

rmharrison commented Oct 31, 2018

Looks like the CI (v8, v10) is failing because updated lock files weren't commited along with the version bumps in package.json

v4 is failing because winston@3 no longer supports v4. Must be >6.4.0.

rmharrison added a commit to rmharrison/winston-console-formatter that referenced this pull request Oct 31, 2018
- v8, v10: Failed because `package-lock.json` wasn't in sync with `package.json`
- v4: Fails because winston@3 is >v6.4.0
@rmharrison
Copy link

rmharrison commented Oct 31, 2018

@halkeye I tried pushing updates to your branch, but it failed

remote: Permission to halkeye/winston-console-formatter.git denied to rmharrison.
fatal: unable to access 'https://github.com/halkeye/winston-console-formatter.git/': The requested URL returned error: 403

I created a PR with the fixes on your fork: halkeye#1

@rmharrison
Copy link

rmharrison commented Oct 31, 2018

@eugeny-dementev: Would you retire node v4 from CI now that winston@3 no longer supports it?

@halkeye
Copy link
Author

halkeye commented Oct 31, 2018

good catch, i didn't even look, i got distracted

@halkeye
Copy link
Author

halkeye commented Oct 31, 2018

yea, 4 is past end of life - https://github.com/nodejs/Release which was 2018-04-30

@BudgieInWA BudgieInWA mentioned this pull request Nov 2, 2018
src/mixin.js Outdated
delete remainingInfo.trace;
delete remainingInfo.message;
delete remainingInfo.timestamp;
delete remainingInfo.label;

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.

Copy link
Author

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?

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'

Copy link
Author

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

@rmharrison
Copy link

@halkeye: Thanks for merging in the formatter vs mixin changes from #12 (comment)

@BudgieInWA: Anything blocking this PR?

Copy link

@BudgieInWA BudgieInWA left a 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"

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.

Copy link
Author

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;

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

Copy link
Author

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.

Copy link
Author

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

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, {

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?

Copy link
Author

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 => {

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.

Copy link
Author

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

@halkeye
Copy link
Author

halkeye commented Nov 5, 2018

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.

if its exported it makes it way harder

@halkeye halkeye closed this Nov 5, 2018
@halkeye halkeye reopened this Nov 5, 2018
@halkeye
Copy link
Author

halkeye commented Nov 5, 2018

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(
{},

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.

Copy link
Author

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

Copy link
Author

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.

@BudgieInWA
Copy link

okay, i think all the issues are handled.

Looks good to me.

maybe it should get migrated to jest or something.

I have had a pretty easy time with Jest, including their snapshot testing (which is what a lot of these tests are).

@ninja-
Copy link

ninja- commented Apr 19, 2019

any update?

@alqu
Copy link

alqu commented Jul 29, 2019

What is the current status of this?

@ninja-
Copy link

ninja- commented Aug 28, 2019

any update?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants