-
-
Notifications
You must be signed in to change notification settings - Fork 431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#249 Add explicit info logger to avoid writing info logs to stderr #313
Conversation
Well the CI tests pass which is a good sign given they run on Linux (Travis) and Windows (AppVeyor) @ThYpHo0n could you tell me what problems you experienced running the integration tests on your mac? Tests ought to work there as well. If the tests don't run on mac then I'd like to fix that as a matter of priority. Would you be able to open a separate issue for that if that is the case? Onto the review: As well as relating to #249 this relates to #95. I've read through #95 and it seems that the choice to use stderr (as presently) or stdout as ts-loader used to is somewhat arbitrary. The advantage of pumping to stderr (as I understand it) is only that when running in But given that this change was introduced to ts-loader purely to satisfy @alexdrel, and that more than one person (@ThYpHo0n and @SteveSandersonMS at least) find it problematic I'm inclined to take this PR and revert the behaviour. I think everyone relevant to this has been included on this comment - please could you get in contact if you have any views on this. cc @jbrantly |
@johnnyreilly thanks for your reply. I've created #314. My cents to the review: |
Great thanks - let's see if anyone has any alternative viewpoints. If no one responds then it looks reasonable to merge this. |
The problem with this is that it would effectively break the scenario reported in #95. That is, running something like |
For anyone else wondering (I was) the
As to having a flag to toggle this; well that sounds fine to me. Probably advisable given there are differing opinions. @ThYpHo0n would you be willing to amend your PR to put this behaviour behind a flag? There's already a mechanism to support this in ts-loader - it's what allows the setting of options |
Yes, will do so today :) |
Awesome! |
Hi @ThYpHo0n, First of all, thanks for putting in the effort on the amend. I really appreciate that. It's not working at present but I imagine you know that. However, I think you've probably taken the change in a direction I didn't expect. My understanding is that we're trying to create a flag that controls whether ts-loader logs info messages to Your change actually introduces a log level which is not what we're trying to achieve. We just want a want to configure where info messages get sent. Would you be able to submit a change that does that instead? (Oh and @jbrantly please do correct me if I've misunderstood anything.) |
Hi @johnnyreilly, |
This is the part that's not universally agreed upon. In the case where the output of the application isn't just logging information but is actually some kind of real output artifact that you're going to pipe to a file or to another program, you don't want a random log to be part of that output. Here's a much deeper discussion about the issue. In actuality, I believe the concept of "any data on stderr means an error" is actually what's wrong. However, that's the world we live in unfortunately with some Microsoft tools (me included) so I think it's reasonable to say that either approach could be preferred depending on their situation. I think which approach is default is a separate matter. My slight leaning is to keep it as-is, both because that would not introduce a breaking change and because I think there are pretty sound reasons for writing diagnostics (which is what this is) to stderr. As an aside, what you've currently implemented with log levels also isn't a bad thing. It certainly gives more granularity than the current "silent" flag. I wonder though if "silent" should go away if log levels is implemented. |
Works for me.
I'm totally up for having log levels but I'd like to deal with that in a later PR if possible. Ideally I'd like to focus for now on providing a flag which controls where info messages are sent. I'd propose calling the flag something along the lines of |
Okay I understand the problem and had another discussion with my colleagues about the best practices about this topic. I also don't want to introduce BC breaking changes, the defaults should represent the current behaviour. I have two possible solutions in my mind right now:
|
Hi @ThYpHo0n, Thanks for bearing with us! I'd favour having another loaderOption which controls whether info is logged to |
if (!loaderOptions.silent) { | ||
console.log.apply(console, messages); | ||
} | ||
} | ||
|
||
function logInfo(...messages: string[]): void { |
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.
To avoid using .toUpperCase()
repeatedly, could we uppercase the value when it's first read from the options in the loader
function? That way we do it once rather than repeatedly (marginal perf gain) and the code reads a little cleaner (which is what I care about more).
##### logLevel *(string) (default=info)* | ||
|
||
Can be `info`, `warn` or `error` which limits the log output to the specified log level. | ||
Beware of the fact that errors are written to stderr and everything else is written to stdout. |
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.
Could we specify details about logInfoToStdOut
before logLevel
in the documentation? Also, instead of:
errors are written to
stderr
and everything else is written tostdout
could we say:
errors are written to
stderr
and everything else is written tostderr
(orstdout
iflogInfoToStdOut
istrue
)
} | ||
|
||
function logInfo(...messages: string[]): void { | ||
if (LogLevel[loaderOptions.logLevel.toUpperCase()] <= LogLevel.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.
Rather than doing .toUpperCase()
repeatedly here could we initialise the value of logLevel
to the uppercase value when it is first read in? That way the code will read a little cleaner and there will be a (super minor) perf gain.
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.
Looks basically good - there's just a couple of points to take care of. See my comments
BTW - never used the "review" features in GitHub before. Hope I'm doing this right! |
@johnnyreilly Thanks for your feedback, will work on that later today. |
No worries - there were 2 releases this weekend as we added support for @types and allowJs. You may find you need to refork (or maybe git will be clever - here's hoping) |
Looks like git has not been kind 😢 Might be work re-forking and re-applying? |
Thats odd, the checks for the merge branch were fine. Maybe I struggle with something else there. Unfortunately the tests are broken on my machine again even being on the current origin master... |
How are the tests failing on your machine? |
It gives an error on es6resolveParent test:
|
That is really weird - I wonder if it's related to this: karma-runner/karma#1545 Looks to be a problem with using PhantomJS on Macs. Was solved. Now unsolved.... Or maybe this: karma-runner/karma-jasmine#127 EIther way - if it passes in CI that's good enough for me. This test used to work for you? |
Looks good - tests seem happy 👍 I'll take a proper look later on but this looks nice - thanks! |
Great, finally good news :) Thanks for your help and the review. First time worked with TypeScript and Mocha. |
This relates to #249 and should fix it BUT I didn't got the integration tests running on my mac so please review and test this before merge!