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

Add Logger$finalize() #66

Merged
merged 14 commits into from
Nov 9, 2023
Merged

Conversation

marcusmunch
Copy link
Collaborator

@marcusmunch marcusmunch commented Nov 7, 2023

Intent

This closes #64.

Approach

I have added a Logger$finalize() function (see also R6#finalizer in Advanced R).
Currently, it does nothing unless log_path is NULL and log_tbl is not NULL.
The finalizer generates a query which sets all log_file in the DB to NULL if they were previously equal to self$log_filename (i.e. exactly what I described in #64).1

For usability/readability, I added a bit of logic to table_exists to compensate for the shortcomings of DBI::dbExistsTable.

Known issues

More feature than bud: Since the DB connection is stored within a tbl_dbi object, table_exists does not care about the conn argument if db_table_id inherits from tbl_dbi.

Checklist

  • The PR passes all local unit tests
  • I have documented any new features introduced
  • If the PR adds a new feature, please add an entry in NEWS.md
  • A reviewer is assigned to this PR

Footnotes

  1. This is done with DBI::dbExecute as dplyr::rows_update (naturally) cannot match a log_file that is not NULL with one that is 🙃 .

@marcusmunch marcusmunch added the enhancement New feature or request label Nov 7, 2023
@marcusmunch marcusmunch requested a review from a team November 7, 2023 13:21
@marcusmunch marcusmunch self-assigned this Nov 7, 2023
@marcusmunch marcusmunch marked this pull request as ready for review November 7, 2023 13:26
@marcusmunch marcusmunch merged commit b42e89f into ssi-dk:main Nov 9, 2023
11 checks passed
@marcusmunch marcusmunch deleted the logger-finalizer branch November 9, 2023 20:51
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.

FEATURE: Set log_file in DB log if not writing file logs
2 participants