feat!: introduce configurable logger#431
Merged
Merged
Conversation
Previously, logs were sent to the browser console or to `MaxLog`, which was inconsistent across the code base. This is now configurable and maxGraph no longer produces logs by default. The logger is configured globally (i.e. it is not specific to a `Graph` instance) and all the examples in the JSDoc have been updated to demonstrate how to use the new logging system (instead of using `MaxLog` directly). It is also possible to provide your own implementation of the logger. Please note that this is a first implementation and may change in the future. This change also improves tree agitation. `MaxLog` is no longer included in applications using maxGraph, and transitively, `MaxWindow` is not included either. Sending logs to `MaxLog` by default also posed a problem in terms of user interface. For example, if an error occurred in `ConnectionHandler`, the `MaxLog` window opened in the application including maxGraph, whereas this was probably not what users wanted. In addition, if maxGraph's CSS rules were not available (for example, by importing the CSS file supplied by maxGraph), the `MaxLog` window was not displayed correctly: its content was added to the bottom of the page without any styling. Notes on `ConsoleLogger` logs By default, only warnings and errors are sent to the browser console to reduce the amount of logs. It is possible to activate info, debug and trace. Remember that traces are produced each time the model is validated. No direct console logs allowed in maxGraph code A new eslint rule has been configured to prohibit the use of console logs, as the global log system must be used instead. Impact on the `Window` story This is the only story that explicitly uses `MaxLog`, so it is configured to direct maxGraph logs to `MaxLog`. To avoid side-effects on other stories because the logger configuration is global, the storybook configuration has been set to reset the logger to its default value before initializing new stories. Break changes - Logs are no longer sent to `MaxLog` by default. To restore the previous behavior, change maxGraph's global configuration with: `GlobalConfig.logger = new MaxLogAsLogger();` - `MaxWindow.activeWindow` is no longer available; it was intended for internal use only, so there's no reason to make it public.
# Conflicts: # CHANGELOG.md # packages/core/tsconfig.json # packages/ts-example/vite.config.js
tbouffard
commented
Jun 4, 2024
# Conflicts: # packages/core/src/types.ts # packages/core/src/view/GraphView.ts # packages/core/tsconfig.json
tbouffard
commented
Jun 6, 2024
[skip ci]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, logs were sent to the browser console or to
MaxLog, which was inconsistent across the code base.This is now configurable and maxGraph no longer produces logs by default.
The logger is configured globally (i.e. it is not specific to a
Graphinstance) and all the examples in the JSDoc have been updated to demonstrate how to use the new logging system (instead of usingMaxLogdirectly).It is also possible to provide your own implementation of the logger.
Please note that this is a first implementation and may change in the future.
This change also improves tree-shaking.
MaxLogis no longer included in applications using maxGraph, and transitively,MaxWindowis not included either.Sending logs to
MaxLogby default also posed a problem in terms of user interface.For example, if an error occurred in
ConnectionHandler, theMaxLogwindow opened in the application including maxGraph, whereas this was probably not what users wanted.In addition, if maxGraph's CSS rules were not available (for example, by importing the CSS file supplied by maxGraph), the
MaxLogwindow was not displayed correctly: its content was added to the bottom of the page without any styling.Notes on
ConsoleLoggerlogsBy default, only warnings and errors are sent to the browser console to reduce the amount of logs. It is possible to activate info, debug and trace. Remember that traces are produced each time the model is validated.
No direct console logs allowed in maxGraph code
A new eslint rule has been configured to prohibit the use of console logs, as the global log system must be used instead.
Impact on the
WindowstoryThis is the only story that explicitly uses
MaxLog, so it is configured to direct maxGraph logs toMaxLog. To avoid side-effects on other stories because the logger configuration is global, the storybook configuration has been set to reset the logger to its default value before initializing new stories.BREAKING CHANGES:
MaxLogby default. To restore the previous behavior, change maxGraph's global configuration with:GlobalConfig.logger = new MaxLogAsLogger();MaxWindow.activeWindowis no longer available; it was intended for internal use only, so there's no reason to make it public.Notes
Tree-shaking improvements
MaxWindowimprovement includes removing a static property as done in #401In ts-example, here are the size of the maxGraph chunk (built with Vite/esbuild):
Notice that I haven't seen any change in the bundle size of js-example (built with webpack), which is probably more conservative (remember that maxGraph is currently declared as "not side effects free", so tree-shaking is not optimal).
Example of UI issues when errors occured in ConnectionHandler without applying maxGraph CSS
Seen while implementing #413