Skip to content

Commit

Permalink
Reduce the console output from logging and
Browse files Browse the repository at this point in the history
create a new logger that logs at different thresholds to console and to file. #50
Update tests. Update codemeta.json
  • Loading branch information
gfinak committed Sep 6, 2018
1 parent 59fc997 commit aec8cc0
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 52 deletions.
4 changes: 4 additions & 0 deletions NAMESPACE
Expand Up @@ -35,14 +35,18 @@ importFrom(devtools,build_vignettes)
importFrom(devtools,parse_deps)
importFrom(devtools,reload)
importFrom(futile.logger,INFO)
importFrom(futile.logger,TRACE)
importFrom(futile.logger,appender.console)
importFrom(futile.logger,appender.file)
importFrom(futile.logger,appender.tee)
importFrom(futile.logger,flog.appender)
importFrom(futile.logger,flog.debug)
importFrom(futile.logger,flog.error)
importFrom(futile.logger,flog.fatal)
importFrom(futile.logger,flog.info)
importFrom(futile.logger,flog.logger)
importFrom(futile.logger,flog.threshold)
importFrom(futile.logger,flog.trace)
importFrom(futile.logger,flog.warn)
importFrom(knitr,knit)
importFrom(knitr,spin)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
@@ -1,3 +1,7 @@
# DataPackageR 0.15.3.9000
* Reduce the console output from logging. (ropensci/DataPackageR/issues/50)
* Create a new logger that logs at different thresholds to console and to file (ropensci/DataPackageR/issues/50)

# DataPackageR 0.15.3
* conditional tests when pandoc is missing (ropensci/DataPackager/issues/46)
* add use_data_object and use_processing_script (ropensci/DataPackager/issues/44)
Expand Down
20 changes: 10 additions & 10 deletions R/build.R
Expand Up @@ -16,7 +16,7 @@
#' @importFrom rmarkdown pandoc_available
#' @importFrom utils install.packages
#' @importFrom yaml read_yaml
#' @importFrom futile.logger flog.debug flog.info flog.warn flog.error flog.fatal flog.appender flog.threshold INFO appender.console appender.tee
#' @importFrom futile.logger flog.logger flog.trace appender.file flog.debug flog.info flog.warn flog.error flog.fatal flog.appender flog.threshold INFO TRACE appender.console appender.tee
#' @importFrom knitr knit spin
#' @export
#' @examples
Expand All @@ -40,8 +40,8 @@ package_build <- function(packageName = NULL,
log = INFO,
deps = TRUE,
install = TRUE) {
flog.threshold(log)
flog.appender(appender.console())
.multilog_setup(LOGFILE = NULL)
# flog.appender(appender.console())
# requireNamespace("futile.logger")
if (is.null(packageName)) {
packageName <- "."
Expand All @@ -50,13 +50,13 @@ package_build <- function(packageName = NULL,
packageName <- basename(package_path)
# Is this a package root?
if (!is_r_package$find_file() == package_path) {
flog.fatal(paste0(package_path, " is not an R package root directory"))
flog.fatal(paste0(package_path, " is not an R package root directory"), name = "console")
stop("exiting", call. = FALSE)
}
} else {
package_path <- normalizePath(packageName, winslash = "/")
if (!file.exists(package_path)) {
flog.fatal(paste0("Non existent package ", packageName))
flog.fatal(paste0("Non existent package ", packageName), name = "console")
stop("exiting", call. = FALSE)
}
packageName <- basename(package_path)
Expand All @@ -71,23 +71,23 @@ package_build <- function(packageName = NULL,
package_path,
" is not a valid R package directory beneath ",
getwd()
))
), name = "console")
stop("exiting", call. = FALSE)
}

# Return success if we've processed everything
success <-
DataPackageR(arg = package_path, deps = deps)
ifelse(success,
flog.info("DataPackageR succeeded"),
flog.warn("DataPackageR failed")
.multilog_trace("DataPackageR succeeded"),
.multilog_warn("DataPackageR failed")
)
flog.info("Building documentation")
.multilog_trace("Building documentation")
roxygen2::roxygenise(package_path,
clean = TRUE
)

flog.info("Building package")
.multilog_trace("Building package")
location <- build(package_path,
path = dirname(package_path),
vignettes = vignettes
Expand Down
18 changes: 11 additions & 7 deletions R/digests.R
Expand Up @@ -11,12 +11,14 @@
newv <- lapply(newv, as.numeric)[[1]]
if (any(is.na(oldv)) | any(is.na(newv))) {
options(warn = oldwarn)
flog.fatal(paste0(
.multilog_fatal(paste0(
"Invalid DataVersion string found ",
old_data_digest[["DataVersion"]],
" and ", new_data_digest[["DataVersion"]]
))
# stop("exiting", call. = FALSE)
{
stop("exiting", call. = FALSE)
}
}
greater <- apply(t(cbind(oldv, newv)), 2, function(x) x[2] > x[1])
equal <- apply(t(cbind(oldv, newv)), 2, function(x) x[2] == x[1])
Expand All @@ -35,7 +37,7 @@
if (valid) {
for (i in names(new_digest)[-1L]) {
if (new_digest[[i]] != old_digest[[i]]) {
flog.warn(paste0(i, " has changed."))
.multilog_warn(paste0(i, " has changed."))
valid <- FALSE
}
}
Expand All @@ -52,12 +54,12 @@
# some new elements exist
valid <- FALSE
for (i in difference) {
flog.debug(paste0(i, " added."))
.multilog_debug(paste0(i, " added."))
}
}
for (i in intersection) {
if (new_digest[[i]] != old_digest[[i]]) {
flog.debug(paste0(i, " changed"))
.multilog_debug(paste0(i, " changed"))
# some new elements are not the same
valid <- FALSE
}
Expand Down Expand Up @@ -88,11 +90,13 @@

.digest_data_env <- function(object_names, dataenv, pkg_description) {
if (is.null(pkg_description[["DataVersion"]])) {
flog.fatal(paste0(
.multilog_fatal(paste0(
"DESCRIPTION file must have a DataVersion",
" line. i.e. DataVersion: 0.2.0"
))
# stop("exiting", call. = FALSE)
{
stop("exiting", call. = FALSE)
}
}
new_data_digest <- list()
new_data_digest[["DataVersion"]] <- pkg_description[["DataVersion"]]
Expand Down
2 changes: 1 addition & 1 deletion R/load_save.R
Expand Up @@ -7,7 +7,7 @@
masterfile = NULL,
pkg_path = NULL) {
.save_digest(new_data_digest, path = pkg_path)
flog.info("Saving to data")
.multilog_trace("Saving to data")
# TODO get the names of each data object and save them separately. Provide a
# function to load all.
for (i in seq_along(object_names)) {
Expand Down
39 changes: 39 additions & 0 deletions R/logger.R
@@ -0,0 +1,39 @@
.multilog_info <- function(msg) {
flog.info(msg, name = "console")
flog.info(msg, name = "logfile")
}
.multilog_trace <- function(msg) {
flog.trace(msg, name = "console")
flog.trace(msg, name = "logfile")
}
.multilog_warn <- function(msg) {
flog.warn(msg, name = "console")
flog.warn(msg, name = "logfile")
}
.multilog_debug <- function(msg) {
flog.debug(msg, name = "console")
flog.debug(msg, name = "logfile")
}
.multilog_fatal <- function(msg) {
flog.fatal(msg, name = "console")
flog.fatal(msg, name = "logfile")
}
.multilog_error <- function(msg) {
flog.error(msg, name = "console")
flog.error(msg, name = "logfile")
}

.multilog_thresold <- function(console = INFO, logfile = TRACE) {
flog.threshold(console, name = "console")
flog.threshold(logfile, name = "logfile")
}
.multilog_setup <- function(LOGFILE = NULL) {
if (!is.null(LOGFILE)) {
flog.logger(name = "logfile",
appender = appender.file(LOGFILE),
threshold = TRACE)
}
flog.logger(name = "console",
appender = appender.console(),
threshold = INFO)
}

0 comments on commit aec8cc0

Please sign in to comment.