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
add logging API #9436
add logging API #9436
Conversation
Plugins: Compiler.getInfrastructureLogger(name) Compilation.getLogger(name) Loader: this.getLogger([name]) API equal to console API with these methods: error, warn, info, log, debug, time, timeLog, timeEnd, group, groupCollapsed, groupEnd, profile, profileEnd, clear
For maintainers only:
|
allow more logging options in schema collapse groups in non-verbose logging show number of filtered logging lines update stats presets for logging
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 👍
/cc @hiroppy can you look on this too, it is future logger for webpack-dev-server/webpack-dev-middleare
@evilebottnawi If my understanding is correct, this plugin is only Node Side so we use loglevel(or webpack-log) on browsers in webpack-dev-server? |
@evilebottnawi |
You can use this on client side: const logging = require("webpack/lib/logging/runtime");
// Get a logger
logging.getLogger("Name");
// Apply plugins to the client side logging, i. e. for pretty display or sending log via websocket
new MyLogginPlugin().apply(logging); By default the logger logs to console. EDIT by hiroppy: modify |
We should also change the HMR logging to use the new logger in the next major release. |
You mean we should change the logger of |
The logger of For the runtime logger we also need to add something to set the log level. Maybe like this: const logging = require("webpack/logging/runtime");
logging.configureDefaultLogger({
level: "warn",
debug: /HMR/
}) Similar to the stats options. |
I need to look into if this can also implemented in a non-breaking way for webpack 4... |
Thank you for the explanation! |
What kind of change does this PR introduce?
feature
Did you add tests for your changes?
yes
Does this PR introduce a breaking change?
no
What needs to be documented once your changes are merged?
Plugins should prefer to use
compilation.getLogger("PluginName")
for logging. This kind of logging is stored to the Stats and formatted in this way. It can be filtered and exported by the user.Plugins may use the
compiler.getInfrastructureLogger("PluginName")
for logging to, but logging to this is not stored in the Stats and therefore not formatted this way. Instead it's usually logged to the console/dashboard/gui directly. It can be filtered by the user.Loaders should prefer to use
this.getLogger()
. This is a shortcut tocompilation.getLogger()
with loader path and processed file.Loaders may use
this.getLogger("name")
to get an independent logger with a child name. Loader path and processed file is still added.Plugins may use
compilation.getLogger ? compilation.getLogger("PluginName") : console
to provide a fallback for webpack version not supporting getLogger. Similar for Loaders.Logger API
logger.error(...)
for error messageslogger.warn(...)
for warningslogger.info(...)
for important information messages (they are displayed in the default settings, only use them for things the user really need to know)logger.log(...)
for unimportant information messages (they are only displayed when opt-in into displaying them)logger.debug(...)
for debugging information (they are only displayed when opt-in into debug logging for specific modules)logger.trace()
to display a stack trace (displayed likelogger.debug
)logger.group(...)
to group messages together (displayed likelogger.log
)logger.groupEnd()
to end a grouplogger.groupCollapsed(...)
to group messages together (displayed collapsed likelogger.log
, displayed expanded when verbose logging or debug logging is enabled)logger.clear()
to clear the log (it may only print a horizontal line instead) (displayed likelogger.log
)logger.profile(...)
andlogger.profileEnd(...)
to capture a profile (delegated toconsole.profile
when supported)Logging configuration
stats.logging: "none"|"error"|"warn"|"info"|"log"|"verbose"
to choose displayed log levelstats.logging: false
to disable all log outputstats.logging: true
alias tostats.logging: "log"
stats.loggingDebug: true|false|/regexp/|"string"|(name) => true
to enable debug output for specific items (intended for plugin/loader developer)stats.logging: false
:stats.loggingDebug
is ignored.stats.loggingTrace: true
enable stack traces in log output forerror
s,warning
s andtrace
s.infrastructureLogging.level: "none"|"error"|"warn"|"info"|"log"|"verbose"
stats.logging
but for infrastructure logginginfrastructureLogging.debug: true|false|/regexp/|"string"|(name) => true
stats.loggingDebug
but for infrastructure loggingPlugins
Compiler.hooks.infrastructureLog
andCompilation.hooks.log
for pluginsRuntime Logger API
const logging = require("webpack/logging/runtime")
logging.getLogger("name")
logging.configureDefaultLogger({ level: "log", debug: /something/ })
logging.hooks.log
to apply plugins to the runtime logger