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

FR: print and as.character methods? #152

Open
r2evans opened this issue Apr 9, 2024 · 0 comments
Open

FR: print and as.character methods? #152

r2evans opened this issue Apr 9, 2024 · 0 comments

Comments

@r2evans
Copy link

r2evans commented Apr 9, 2024

As I was thinking about the recent comment in #26, I wonder if there could be convenience in having print and as.character S3 methods for the return value to facilitate the nested use.

library(logger)
logged <- log_info("test")
# INFO [2024-04-09 09:20:45] test
class(logged)
# [1] "list"
class(logged) <- c("logger", "list")
print.logger <- function(x, ..., index = 1) print.default(unname(x[[index]]$record), ...)
as.character.logger <- function(x, ..., index = 1) unname(x[[index]]$record)
logged
# [1] "INFO [2024-04-09 09:20:45] test"
jsonlite::toJSON(as.character(logged))
# ["INFO [2024-04-09 09:20:45] test"] 

Thoughts? They're effectively "free" and come closer to my original thoughts when suggesting pass-through.

@r2evans r2evans added the bug Something isn't working label Apr 9, 2024
@FMKerckhof FMKerckhof mentioned this issue Apr 9, 2024
@daroczig daroczig removed the bug Something isn't working label Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants