Skip to content
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

register teal.logger handlers; replace few loggers with base #1081

Merged
merged 6 commits into from
Mar 20, 2024

Conversation

pawelru
Copy link
Contributor

@pawelru pawelru commented Feb 1, 2024

close https://github.com/insightsengineering/coredev-tasks/issues/502
test with insightsengineering/teal.logger#73

I will keep it as a draft for the time being because this requires (currently) development version of teal.logger. This has impact on our release plan as teal.logger would have to be released first

R/modules.R Show resolved Hide resolved
Copy link
Contributor

github-actions bot commented Mar 11, 2024

CLA Assistant Lite bot ✅ All contributors have signed the CLA

DESCRIPTION Outdated Show resolved Hide resolved
Signed-off-by: Pawel Rucki <[email protected]>
@pawelru
Copy link
Contributor Author

pawelru commented Mar 11, 2024

I have read the CLA Document and I hereby sign the CLA

@pawelru pawelru marked this pull request as ready for review March 11, 2024 13:44
Copy link
Contributor

github-actions bot commented Mar 11, 2024

badge

Code Coverage Summary

Filename                          Stmts    Miss  Cover    Missing
------------------------------  -------  ------  -------  -------------------------------------------------------------------------------------------------------------------------------
R/dummy_functions.R                  30       0  100.00%
R/get_rcode_utils.R                  31       1  96.77%   50
R/include_css_js.R                   22       0  100.00%
R/init.R                             86      25  70.93%   108-115, 161-162, 164, 179-185, 192-197, 228
R/landing_popup_module.R             25      25  0.00%    61-87
R/module_filter_manager.R           107      29  72.90%   50-58, 67-72, 195, 200-213
R/module_nested_tabs.R              154       3  98.05%   47, 128, 228
R/module_snapshot_manager.R         209     157  24.88%   87-99, 127-136, 140-152, 154-161, 168-182, 186-188, 190-195, 198-208, 211-227, 236-251, 265-288, 291-302, 305-311, 325, 343-366
R/module_tabs_with_filters.R         76       0  100.00%
R/module_teal_with_splash.R         114       2  98.25%   110, 131
R/module_teal.R                     106       1  99.06%   57
R/modules.R                         152      23  84.87%   127-130, 147-151, 206-209, 291-292, 344, 356-364
R/reporter_previewer_module.R        18       0  100.00%
R/show_rcode_modal.R                 19      19  0.00%    17-36
R/tdata.R                            53       1  98.11%   154
R/teal_data_module-eval_code.R       27       0  100.00%
R/teal_data_module-within.R           7       0  100.00%
R/teal_data_module.R                  6       0  100.00%
R/teal_reporter.R                    62       5  91.94%   69, 118-119, 122, 139
R/teal_slices-store.R                29       0  100.00%
R/teal_slices.R                      59      12  79.66%   137-150
R/TealAppDriver.R                   225      71  68.44%   66-77, 124-127, 135, 156-157, 165, 177-178, 200-206, 292-339, 389-397, 401, 419, 452
R/utils.R                           173       1  99.42%   255
R/validate_inputs.R                  32       0  100.00%
R/validations.R                      58      37  36.21%   110-377
R/zzz.R                              12       8  33.33%   3-15
TOTAL                              1892     420  77.80%

Diff against main

Filename       Stmts    Miss  Cover
-----------  -------  ------  --------
R/modules.R       -1      -1  +0.55%
R/zzz.R           +1      +1  -3.03%
TOTAL              0       0  +100.00%

Results for commit: 6507f84

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

Copy link
Contributor

github-actions bot commented Mar 11, 2024

Unit Tests Summary

  1 files   26 suites   1m 29s ⏱️
226 tests 226 ✅ 0 💤 0 ❌
482 runs  482 ✅ 0 💤 0 ❌

Results for commit 6507f84.

♻️ This comment has been updated with latest results.

Copy link
Contributor

Unit Test Performance Difference

Test Suite $Status$ Time on main $±Time$ $±Tests$ $±Skipped$ $±Failures$ $±Errors$
tdata 💚 $5.71$ $-1.02$ $0$ $0$ $0$ $0$
Additional test case details
Test Suite $Status$ Time on main $±Time$ Test Case
tdata 💚 $5.36$ $-1.04$ new_tdata_accepts_reactive_and_not_reactive_MAE_and_data.frames

Results for commit 6ca4011

♻️ This comment has been updated with latest results.

@pawelru pawelru added the core label Mar 14, 2024
Copy link
Contributor

@gogonzo gogonzo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ja wohl 👍

pawelru added a commit to insightsengineering/teal.logger that referenced this pull request Mar 20, 2024
close insightsengineering/coredev-tasks#502
#69

I tried to use `logger::log_messages()` (and similar functions for
warnings and errors) but I have encounter following problems:
- this is logging into the global logger namespace whereas we want
particular (package) namespace instead - created an issue
- I cloned logger locally and fixed / enhanced the above but then I
realized that the (global) message / warning / stop calls from the
outside of a package will also log to that package logger namespace. In
other words, these are _global_ handlers for all the warnings and not
only warnings created inside `teal` e.g.
```
r$> warning(1)
[WARN] 2024-01-26 15:58:17.0061 pid:83248 token:[] teal 1
Warning message:
1
```

Therefore I have decided to implement own register handlers mechanism. I
initially started doing this separately inside each package but then I
realised that it's not so DRY and decided to extend core `teal.logger`
functionality.

This is not a reprex as I modified `teal` and `teal.slice` namespaces in
a following way:
- added `register_handlers(<pkg>)` in both packages
- For debugging: added following definitions:
  - `teal.slice`:
    - `teal_s_message` calling `message()`
    - `teal_s_warning` calling `warning()`
    - `teal_s_stop` calling `stop()`
  - in `teal`:
    - `teal_message` calling `message()`
    - `teal_warning` calling `warning()`
    - `teal_stop` calling `stop()`
- `teal_message_nested` calling `teal_s_message()` (so as to simulate
`teal` calling `teal.slice`)
    - `teal_warning_nested` calling `teal_s_warning()`
    - `teal_stop_nested` calling `teal_s_stop()`

The outcome:

```
r$> devtools::load_all("teal.logger")
r$> devtools::load_all("teal.slice")
r$> devtools::load_all("teal")

r$> message(1)
1
r$> teal_message(1)
[INFO] 2024-01-26 15:57:40.8901 pid:83248 token:[] teal 1
1
r$> teal_s_message(1)
[INFO] 2024-01-26 15:57:42.1464 pid:83248 token:[] teal.slice 1
1
r$> teal_message_nested(1)
[INFO] 2024-01-26 15:57:50.9231 pid:83248 token:[] teal 1
[INFO] 2024-01-26 15:57:50.9257 pid:83248 token:[] teal.slice 1
1

r$> warning(2)
Warning message:
2 
r$> teal_s_warning(2)
[WARN] 2024-01-26 15:58:17.0061 pid:83248 token:[] teal.slice In ‘teal_s_warning(2)’: 2
Warning message:
In teal_s_warning(2) : 2
r$> teal_warning(2)
[WARN] 2024-01-26 15:58:18.4165 pid:83248 token:[] teal In ‘teal_warning(2)’: 2
Warning message:
In teal_warning(2) : 2
r$> teal_warning_nested(2)
[WARN] 2024-01-26 15:58:20.8666 pid:83248 token:[] teal In ‘teal.slice:::teal_s_warning(message)’: 2
[WARN] 2024-01-26 15:58:20.8685 pid:83248 token:[] teal.slice In ‘teal.slice:::teal_s_warning(message)’: 2
Warning message:
In teal.slice:::teal_s_warning(message) : 2

r$> stop(3)
Error: 3
r$> teal_s_stop(3)
[ERROR] 2024-01-26 15:58:32.9558 pid:83248 token:[] teal.slice In ‘teal_s_stop(3)’: 3
Error in teal_s_stop(3) : 3
r$> teal_stop(3)
[ERROR] 2024-01-26 15:58:33.5246 pid:83248 token:[] teal In ‘teal_stop(3)’: 3
Error in teal_stop(3) : 3
r$> teal_stop_nested(3)
[ERROR] 2024-01-26 15:58:34.0213 pid:83248 token:[] teal In ‘teal.slice:::teal_s_stop(message)’: 3
[ERROR] 2024-01-26 15:58:34.0226 pid:83248 token:[] teal.slice In ‘teal.slice:::teal_s_stop(message)’: 3
Error in teal.slice:::teal_s_stop(message) : 3
```

Interpretation (where "m/w/s" stands for "message / warning / stop"):
- global m/w/s is not impacted - we only capture m/w/s called from
inside the package
- capturing m/w/s in the appropriate logger namespace - see it as a part
of logger produced string - second last part
- the case of nested calls looks odd at the very first glance but I
think it's correct. Each (package) logger instance might have its own
log threshold, appender function, layout etc. It's expected to have
duplicated logs for each of the registered package namespace found on
the stack of calls. I'm interested in hearing your thoughts on this


PRs:

- [ ] insightsengineering/teal#1081
- [ ] insightsengineering/teal.goshawk#258
- [ ]
insightsengineering/teal.modules.clinical#1010
- [ ]
insightsengineering/teal.modules.general#628
- [ ]
insightsengineering/teal.modules.hermes#354
- [ ] insightsengineering/teal.osprey#252
- [ ] insightsengineering/teal.slice#551
- [ ] insightsengineering/teal.transform#175

(I'll keep them as draft as this is conflicting with release plans
because teal.logger would have to be released first)

TODO: tests - however I'm not yet sure how to make them "clean"

---------

Signed-off-by: Pawel Rucki <[email protected]>
Co-authored-by: Dawid Kałędkowski <[email protected]>
DESCRIPTION Outdated Show resolved Hide resolved
@pawelru pawelru enabled auto-merge (squash) March 20, 2024 14:14
@pawelru pawelru merged commit c5ea0dd into main Mar 20, 2024
24 checks passed
@pawelru pawelru deleted the register_handlers branch March 20, 2024 14:22
@github-actions github-actions bot locked and limited conversation to collaborators Mar 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants