Closed pawelru closed 7 months ago
Note to myself: this still requires some thinking. Both testthat2 as well as R CMD BUILD doesn't like this functionality and fail with the following: error: should not be called with handlers on the stack
.
Filename Stmts Miss Cover Missing
--------------------- ------- ------ ------- ---------
R/register_handlers.R 39 0 100.00%
R/register_logger.R 56 1 98.21% 115
R/supress_logs.R 5 5 0.00% 17-21
R/utils.R 20 0 100.00%
TOTAL 120 6 95.00%
Filename Stmts Miss Cover
--------------------- ------- ------ --------
R/register_handlers.R +39 0 +100.00%
R/utils.R +3 0 +100.00%
TOTAL +42 0 +5.00%
Results for commit: d99e6c6cb076cee2962251d6c79c67d060bd5fc4
Minimum allowed coverage is 80%
:recycle: This comment has been updated with latest results
1 files 3 suites 0s :stopwatch: 25 tests 25 :white_check_mark: 0 :zzz: 0 :x: 37 runs 37 :white_check_mark: 0 :zzz: 0 :x:
Results for commit d99e6c6c.
:recycle: This comment has been updated with latest results.
Note to myself: this still requires some thinking. Both testthat2 as well as R CMD BUILD doesn't like this functionality and fail with the following:
error: should not be called with handlers on the stack
.
Re: this. It's not super easy to identify when it's forbidden. After additional research I have found out that also pkgdown complains about this (so it's not only build and test). Therefore it would be difficult to specify a condition when this could be safely called. I decided to introduce a try block instead (and document it accordingly). This is not a solution that I am super proud of but it does the trick.
Test Suite | $Status$ | Time on main |
$±Time$ | $±Tests$ | $±Skipped$ | $±Failures$ | $±Errors$ |
---|---|---|---|---|---|---|---|
register_handlers | 👶 | $+0.15$ | $+20$ | $0$ | $0$ | $0$ | |
utils | 👶 | $+0.03$ | $+7$ | $0$ | $0$ | $0$ |
Results for commit a1f43e8a79ab601213eff87369e3c96a5b5e66eb
♻️ This comment has been updated with latest results.
teal.goshawk
and tmh still havelogger::log_info
feel free to create an issue and put it to our backlog if you have too much to do now
I got it covered. Please have a look at the parent issue. It has all the PRs linked so it's easily findable.
UPDATE: actually they are also linked here in the top-message as well
Hi @gogonzo Please have a look at the latest commit. I made several changes focused on avoid the repetition you detected. These includes:
registered_handlers_namespaces
object storing name of packages registered - this is created in zzz.R
and then used in the handler function itselfAn example (with not pushed test functions):
r$> setwd("teal")
r$> devtools::load_all("../teal.logger")
ℹ Loading teal.logger
r$> devtools::load_all("../teal.slice")
ℹ Loading teal.slice
r$> devtools::load_all(".")
ℹ Loading teal
Loading required package: shiny
Loading required package: teal.data
Loading required package: teal.code
Registered S3 method overwritten by 'teal':
method from
c.teal_slices teal.slice
[INFO] 2024-03-19 17:42:12.8201 pid:31547 token:[] teal You are using teal version 0.15.2.9004
r$> message(1)
1
r$> test_message()
[INFO] 2024-03-19 17:42:30.2534 pid:31547 token:[] teal This is a teal message.
r$> teal.slice:::test_message()
[INFO] 2024-03-19 17:42:48.5948 pid:31547 token:[] teal.slice This is a teal.slice message.
r$> test_nested_message()
[INFO] 2024-03-19 17:42:59.7324 pid:31547 token:[] teal.slice This is a teal.slice message.
r$> test_nested_message
function() {
teal.slice:::test_message()
}
<environment: namespace:teal>
close https://github.com/insightsengineering/coredev-tasks/issues/502 #69
I tried to use
logger::log_messages()
(and similar functions for warnings and errors) but I have encounter following problems:teal
e.g.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
andteal.slice
namespaces in a following way:register_handlers(<pkg>)
in both packagesteal.slice
:teal_s_message
callingmessage()
teal_s_warning
callingwarning()
teal_s_stop
callingstop()
teal
:teal_message
callingmessage()
teal_warning
callingwarning()
teal_stop
callingstop()
teal_message_nested
callingteal_s_message()
(so as to simulateteal
callingteal.slice
)teal_warning_nested
callingteal_s_warning()
teal_stop_nested
callingteal_s_stop()
The outcome:
Interpretation (where "m/w/s" stands for "message / warning / stop"):
PRs:
(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"