daroczig / daroczig/logger

FR: print and as.character methods?

Open
#152 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
HTML
Stars
323
Forks
46
Avg merge
1d 21h
Merged PRs (30d)
1

Description

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.

```r
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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.