Skip to content

Commit

Permalink
removed vscode dev (temp); addressed CRAN submission freedback
Browse files Browse the repository at this point in the history
removed vscode dev (temp); addressed CRAN submission freedback
  • Loading branch information
bmoretz committed Mar 12, 2022
1 parent f1dc16d commit 0e46346
Show file tree
Hide file tree
Showing 21 changed files with 188 additions and 327 deletions.
14 changes: 5 additions & 9 deletions .lintr
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
linters: with_defaults(
line_length_linter = NULL, # 53
dummy_linter = NULL
dummy_linter = NULL,
T_and_F_symbol_linter,
equals_na_linter,
nonportable_path_linter
)
exclusions: list(
"docs/404.html",
"docs/articles/Formats.html",
"docs/articles/index.html",
"docs/articles/Layouts.html",
"docs/articles/Levels.html",
Expand Down Expand Up @@ -163,12 +165,6 @@ exclusions: list(
"man/value.fmt_timestamp.Rd",
"man/value.Rd",
"vignettes/Formats.html",
"vignettes/Formats.R",
"vignettes/Formats.Rmd",
"vignettes/Layouts.html",
"vignettes/Layouts.R",
"vignettes/Layouts.Rmd",
"vignettes/Levels.html",
"vignettes/Levels.R",
"vignettes/Levels.Rmd"
"vignettes/Levels.html"
)
50 changes: 0 additions & 50 deletions .vscode/launch.json

This file was deleted.

10 changes: 4 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: dyn.log
Type: Package
Title: Dynamic Logging for R Inspired by Configuration Driven Development
Version: 0.3.2
Version: 0.3.3
Authors@R:
c(person(given = "Brandon",
family = "Moretz",
Expand All @@ -14,7 +14,7 @@ Description: A comprehensive and dynamic configuration driven logging package fo
are several excellent logging solutions already in the R ecosystem, I always feel constrained
in some way by each of them. Every project is designed differently to solve it's domain specific problem,
and ultimately the utility of a logging solution is its ability to adapt to this design. This is the
rai-son de' tre for dyn.log: to provide a modular design, template mechanics and a configuration-based
raison d'être for 'dyn.log': to provide a modular design, template mechanics and a configuration-based
integration model, so that the logger can integrate deeply into your design, even though it knows
nothing about it.
License: MIT + file LICENSE
Expand All @@ -32,7 +32,6 @@ Imports:
Roxygen: list(markdown = TRUE)
URL: https://bmoretz.github.io/dyn.log/
BugReports: https://github.com/bmoretz/dyn.log/issues
RoxygenNote: 7.1.2
Suggests:
devtools,
usethis,
Expand All @@ -48,9 +47,8 @@ Suggests:
here,
fansi,
pander,
DT,
languageserver,
httpgd
DT
Config/testthat/edition: 3
RoxygenNote: 7.1.2
Language: en-US
VignetteBuilder: knitr
19 changes: 19 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Release Summaries <img src="man/figures/hex.png" width = "175" height = "200" align="right" />

# dyn.log 0.3.3

## What's Changed

* New Features
+ N/A

* Enhancements
+ additional linters:
+ T_and_F_symbol_linter
+ equals_na_linter
+ nonportable_path_linter
+ resolved all warnings produced by including the new lintrs.
+ updated the README.md to be more reflective of the overall goal of the package.

* Other
+ vscode support
+ moved the development configuration that supports vscode into a separate branch and cleaned up all the additional dependencies.

# dyn.log 0.3.2

## What's Changed
Expand Down
13 changes: 8 additions & 5 deletions R/config.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ get_configurations <- function(pkgname = "dyn.log") {
config_files <- list.files(
system.file("", package = pkgname),
pattern = ".yaml",
full.names = T
full.names = TRUE
)

configs <- list()
Expand Down Expand Up @@ -52,7 +52,7 @@ init_logger <- function(file_path = NULL) {
config_file <- file_path
}

config <- yaml::read_yaml(config_file, eval.expr = T)
config <- yaml::read_yaml(config_file, eval.expr = TRUE)
config_name <- tools::file_path_sans_ext(basename(config_file))

ensure_logger(config$variable)
Expand Down Expand Up @@ -98,7 +98,7 @@ ensure_logger <- function(variable) {
}

envir <- globalenv()
idx <- which(ls(envir) == variable, arr.ind = T)
idx <- which(ls(envir) == variable, arr.ind = TRUE)

if (identical(idx, integer())) {
logger <- LogDispatch$new()
Expand All @@ -120,7 +120,7 @@ ensure_logger <- function(variable) {
wipe_logger <- function() {
envir <- globalenv(); objs <- ls(envir)

idx <- which(objs == active$log_var, arr.ind = T)
idx <- which(objs == active$log_var, arr.ind = TRUE)

if (!identical(idx, integer(0))) {
rm(list = objs[idx], envir = envir)
Expand All @@ -144,7 +144,10 @@ load_log_layouts <- function(layouts) {

invisible(sapply(layouts, function(layout) {
if (identical(class(layout$format), "character")) {
parsed <- stringr::str_split(layout$formats, pattern = ",", simplify = T)

parsed <- stringr::str_split(layout$formats,
pattern = ",",
simplify = TRUE)

formats <- sapply(parsed, function(fmt) {
eval(parse(text = stringr::str_trim(fmt)))
Expand Down
18 changes: 10 additions & 8 deletions R/context.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ extract_func_name <- function(func) {
#' @returns string representation of a func call.
format_fn_call <- function(expr,
cutoff = 100L) {
deparse1(expr, collapse = " ", width.cutoff = cutoff, backtick = T)
deparse1(expr, collapse = " ",
width.cutoff = cutoff,
backtick = TRUE)
}

#' @title Formatted Call Stack
Expand All @@ -95,9 +97,9 @@ format_fn_call <- function(expr,
#' @family Context
#' @returns formatted call stack
#' @importFrom stringr str_detect fixed
get_call_stack <- function(keep_args = F,
get_call_stack <- function(keep_args = FALSE,
call_subset = c(-1, -1),
filter_internal = T) {
filter_internal = TRUE) {

trace_back <- rlang::trace_back()
trace <- sapply(trace_back, list, simplify = "branch")
Expand Down Expand Up @@ -154,7 +156,7 @@ clean_internal_calls <- function(call_stack) {

internal_calls <- sapply(call_stack, function(call) {
stringr::str_starts(call, pattern = stringr::fixed("dyn.log::"))
}, simplify = T)
}, simplify = TRUE)

if (length(internal_calls) > 0) {
call_stack <- call_stack[!internal_calls]
Expand All @@ -177,17 +179,17 @@ clean_internal_calls <- function(call_stack) {
#' @return system context for evaluating \code{fmt_metric} objects.
#' @family Context
#' @export
exec_context <- function(keep_args = F,
exec_context <- function(keep_args = FALSE,
max_calls = 5,
call_subset = c(-1, -1),
filter_internal = T) {
filter_internal = TRUE) {

full_stack <- get_call_stack(keep_args = keep_args,
call_subset = call_subset,
filter_internal = filter_internal)

lcs <- sapply(full_stack, is_logger_call, simplify = T)
lc_idx <- as.integer(which(lcs, arr.ind = T))
lcs <- sapply(full_stack, is_logger_call, simplify = TRUE)
lc_idx <- as.integer(which(lcs, arr.ind = TRUE))

if (!identical(lc_idx, integer(0))) {
full_stack <- full_stack[1:(lc_idx - 1)]
Expand Down
14 changes: 7 additions & 7 deletions R/dispatch.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
#' @export
LogDispatch <- R6::R6Class( #nolint
classname = "LogDispatch",
lock_objects = F,
lock_class = F,
cloneable = F,
portable = F,
lock_objects = FALSE,
lock_class = FALSE,
cloneable = FALSE,
portable = FALSE,

public = list(

Expand Down Expand Up @@ -95,7 +95,7 @@ LogDispatch <- R6::R6Class( #nolint
caller_env <- rlang::caller_env()
parent_env <- parent.env(caller_env)

has_calling_class <- ifelse(is.null(parent_env$self), F, T)
has_calling_class <- ifelse(is.null(parent_env$self), FALSE, TRUE)
calling_class <- NA
log_msg <- glue::glue(msg, .envir = parent)

Expand All @@ -109,7 +109,7 @@ LogDispatch <- R6::R6Class( #nolint
# association given its hierarchy.
cls_name <- class(calling_class)
registered <- names(log_layouts())
layout_idx <- max(c(0L, match(cls_name, registered)), na.rm = T)
layout_idx <- max(c(0L, match(cls_name, registered)), na.rm = TRUE)

if (layout_idx > 0) {
log_layout <- log_layouts(registered[layout_idx])
Expand Down Expand Up @@ -143,7 +143,7 @@ LogDispatch <- R6::R6Class( #nolint
evaluated <- evaluate_layout(detail, context)

cat(glue::glue(evaluated),
fill = T,
fill = TRUE,
file = stdout())
}

Expand Down
4 changes: 2 additions & 2 deletions R/layout.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ evaluate_layout <- function(detail, context) {
if (any(!is.na(match(detail$types, "fmt_newline")))) {
is_break <- sapply(detail$formats, function(fmt) "fmt_newline" %in% class(fmt))
groups <- split(range, with(rle(is_break), rep(cumsum(!values), lengths))) # nolint (values is bound from RLE)
new_lines <- which(is_break, arr.ind = T)
new_lines <- which(is_break, arr.ind = TRUE)
}

output <- character(0)
Expand All @@ -139,7 +139,7 @@ evaluate_layout <- function(detail, context) {
rng <- unlist(unname(group))
has_break <- any(rng %in% new_lines)

if (has_break == T) {
if (has_break == TRUE) {
rng <- rng[-length(rng)]
}

Expand Down
2 changes: 1 addition & 1 deletion R/level.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ log_levels <- local({

if (length(level) > 0 && is.na(level)) {
# remove an existing level
lvl_idx <- which(!is.na(match(lvl_names, name)), arr.ind = T)
lvl_idx <- which(!is.na(match(lvl_names, name)), arr.ind = TRUE)
if (!identical(lvl_idx, integer())) {
levels <<- levels[-lvl_idx]
}
Expand Down
28 changes: 18 additions & 10 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ output:
always_allow_html: yes
---

<!-- README.md is generated from README.Rmd. Please edit that file -->

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
Expand All @@ -31,17 +29,27 @@ knitr::opts_chunk$set(
[![R-CMD-check](https://github.com/bmoretz/dyn.log/workflows/R-CMD-check/badge.svg)](https://github.com/bmoretz/dyn.log/actions)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://cran.r-project.org/web/licenses/MIT)
[![Codecov test coverage](https://codecov.io/gh/bmoretz/dyn.log/branch/master/graph/badge.svg)](https://app.codecov.io/gh/bmoretz/dyn.log?branch=master)
[![](https://img.shields.io/badge/devel%20version-0.3.0-blue.svg)](https://bmoretz.github.io/dyn.log/)
[![](https://img.shields.io/badge/devel%20version-0.3.3-blue.svg)](https://bmoretz.github.io/dyn.log/)
[![Lifecycle](https://img.shields.io/badge/lifecycle-stable-darkgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
<!-- badges: end -->

The goal of dyn.log is to be a comprehensive and dynamic configuration driven logging package
for R. While there are several excellent logging solutions already in the R ecosystem, I always
feel constrained in some way by each of them. Every project is designed differently to achieve its stated goal;
to solve some problem, and ultimately the utility of a logging solution is its ability to adapt
to the project’s design. This is the rai·&#x200B;son d'être for dyn.log; to provide a modular design,
template mechanics and a configuration-based integration model. This enableds the logger to integrate
deeply into your design, even though it knows nothing about it.
The goal of `dyn.log` is to be a comprehensive, dynamic, configuration-based logging package for R. While there are several excellent logging solutions already in the R ecosystem, I found none of them were both robust functionality-wise, and completely generic i.e., they are designed exclusively for use within a specific environment (shiny/plumber/etc).

This is the raison d'être for `dyn.log`: a flexible logging solution that:

* Integrates seamlessly
+ set an R option or call `init_logging` in your .Rprofile and your logger is attached (and will re-attach when you `rm(list = ls())`).
* Agnostics of project type, so it can be deployed across the entire application stack
+ [shiny](https://github.com/rstudio/shiny)
+ [plumber](https://github.com/rstudio/plumber)
+ stand-alone prototype scripts
+ etc.
* Reusable
+ log layout, levels, etc. can be highly-customized for both shiny apps and plumber services, then reused across packages running in different environments (docker containers).

### Demos

In order to keep the package as light as possible dependency-wise, there are no demos that come integrated with the package. However, separate repositories are **coming soon** to demonstrate the above scenarios and will be linked here.

## Installation

Expand Down
Loading

0 comments on commit 0e46346

Please sign in to comment.