Skip to content

feat!: introduce configurable logger#431

Merged
tbouffard merged 11 commits into
mainfrom
feat/configure_log_in_view_components
Jun 6, 2024
Merged

feat!: introduce configurable logger#431
tbouffard merged 11 commits into
mainfrom
feat/configure_log_in_view_components

Conversation

@tbouffard

@tbouffard tbouffard commented May 30, 2024

Copy link
Copy Markdown
Member

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-shaking. 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.

BREAKING 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.

Notes

Tree-shaking improvements

MaxWindow improvement includes removing a static property as done in #401

In ts-example, here are the size of the maxGraph chunk (built with Vite/esbuild):

  • commit 84f492f: 468.63 kB │ gzip: 123.54 kB
  • now: 452.30 kB │ gzip: 119.86 kB

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

maxLog_without_styling

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.
@tbouffard tbouffard added the enhancement New feature or request label May 30, 2024
Comment thread packages/core/tsconfig.json Outdated
tbouffard added 2 commits June 4, 2024 07:14
# Conflicts:
#	packages/core/src/types.ts
#	packages/core/src/view/GraphView.ts
#	packages/core/tsconfig.json
@tbouffard tbouffard marked this pull request as ready for review June 5, 2024 16:59
Comment thread packages/website/docs/usage/global-configuration.md Outdated
@tbouffard tbouffard merged commit 3cd5229 into main Jun 6, 2024
@tbouffard tbouffard deleted the feat/configure_log_in_view_components branch June 6, 2024 05:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant