-
-
Notifications
You must be signed in to change notification settings - Fork 59
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
feat: add logging facilities #486
feat: add logging facilities #486
Conversation
🦋 Changeset detectedLatest commit: 473f3a8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codecov Report
@@ Coverage Diff @@
## main #486 +/- ##
==========================================
+ Coverage 96.75% 96.94% +0.18%
==========================================
Files 31 32 +1
Lines 1109 1145 +36
Branches 222 235 +13
==========================================
+ Hits 1073 1110 +37
+ Misses 36 35 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
dirCtx = { useParam: vi.fn, warn: vi.fn } | ||
}) | ||
let dirCtx: TransformFactoryContext | ||
beforeAll(() => { |
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 had to extract this to the top level, because I got interference between the different describe
blocks. Not sure what was causing this, but perhaps parallel test running or something similar?
This was the simplest way I found of adressing the issue.
I noticed prettier was reformatting some files in your PR. The whole repo should have been formatted, but the enforcement for it accidentally got turned off. I re-enabled it and formatted the repo, so you'll have to rebase this PR now |
dead22e
to
94aa59f
Compare
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 not entirely sure we need a new option as much as just lowering the level of the newly added log message. If we were to add a new option maybe it'd make sense to align it with Vite? https://vitejs.dev/config/shared-options.html#loglevel
@@ -91,8 +91,8 @@ export const resize: TransformFactory<ResizeOptions> = (config) => { | |||
finalWidth = originalWidth | |||
finalAspect = originalAspect | |||
|
|||
console.warn( | |||
'[vite-imagetools] withoutEnlargement or withoutReduction enabled. Image width, height and aspect ratio reverted to original values' | |||
context.warn( |
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 warning doesn't seem very useful. E.g. it doesn't tell you what image it encountered
I also wonder if this should even be a warning? This doesn't seem like an error condition, but just regular functioning. Maybe it should be something more like debug
or info
. I'm not that familiar with the feature though. @sawyerclick can you provide some more details?
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.
@JonasKruckenberg recommended the warning as a part of his review in the original pr #461
Now that I'm looking at it again, I don't believe the warning is needed. It's redundant as it's sole purpose is to indicate that the flags are working.
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.
Ah, I see: #461 (comment)
@JonasKruckenberg it seems this warning has been a bit noisy. Do you mind if we either remove it or demote it to an info
or debug
? I think if users need to figure out whether it was triggered they can always compare the dimensions on the filesystem to the rendered dimensions
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.
My concern was that the whole idea of without*
is to not do anything when the conditions are met. To the uninitiated (or tired) this might seem like the whole plugin not doing it's job though. Also in all cases I can imagine without*
is a safeguard that trips when you made an error while specifying your image dimensions. That's why I originally recommended the warning, but I guess info
makes sense too (since it technically works as intended)
Edit: And yes I agree the message itself also isn't that helpful yet
I would like to add more logs to this plugin to make issues easier to debug, but the specifics really don't matter here. Respecting the vite config value (when we're in the vite plugin) makes total sense to me, but we need a way to pass this on to the core crate. Maybe we can use an existing logger library |
I won't get into the discussion of whether to log when Looking into the logging capabilities of vite and rollup, I have found that:
Based on this, I think it makes sense that the imagetools rollup and vite plugins provides an object with |
I think this makes sense, when used in a Vite context we can just proxy the log functions provided by Vite and in a the rollup case we just use the functions we're provided and maybe make the rest no-ops |
Yes, no-op or I can implement this tomorrow if there are no concerns from Ben or others. Edit: Since Rollup doesn't provide logging levels, I propose both info and warn are forwarded to Rollup's warn. It can be silenced with a cli flag or with an |
ef40720
to
29f3629
Compare
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 good! Thanks for taking the time to fix this 👍🏻 One last thing though: I would argue this should be a patch
fix too, since it doesn't introduce any new user-facing features, and instead fixes some weird behaviour
Haha, I originally had it as a major (because I completely removed the config option at first, instead of deprecating), so now we've been through the whole spectrum. I'll make the change to patch. And thank you for creating this great library in the first place 🙌 |
Deprecates the silent option and delegates that functionality to the bundlers. Vite has log level controls, and Rollup let's the users manage the logging with the `onwarn` hook.
29f3629
to
473f3a8
Compare
Uses thecontext.warn
function to issue errors from the transformers and prints these from the vite and rollup plugins. If thesilent
option is set, the warnings are not printed.Logs messages through Rollup and Vite so message verbosity can be tuned.
I have tested this in a Vite project, but had no Rollup project to test in.
Feature
Transforms now get access to a
logger
object through the context, which allows for logging at different levels (info
,warn
,error
).Removes the existing
silent
functionality.Does this PR introduce a breaking change? (What changes might users need to make in their application due to this
PR?)
The way in which the warning is logged has changed. There might be a tiny chance that someone relies on parsing the plugin output to detect this, but this seems unlikely.
Other information:
Output from vite before this PR:
Output from vite after this PR: