Skip to content

Commit 7d782e1

Browse files
committed
log_info() #70
1 parent 02f1383 commit 7d782e1

File tree

12 files changed

+325
-10
lines changed

12 files changed

+325
-10
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export(log_close)
55
export(log_code)
66
export(log_error)
77
export(log_hook)
8+
export(log_info)
89
export(log_open)
910
export(log_path)
1011
export(log_print)

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Fixed bug on creating path for message file.
44
* Added "stdout" option to send log output to the console
55
instead of a file.
6+
* Added `log_info()` function to send an informational message
7+
to the log.
68

79
# logr 1.3.8
810

R/logr.R

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,3 +1223,62 @@ get_warnings <- function() {
12231223
}
12241224

12251225

1226+
#' @title Logs an informational message
1227+
#' @description Writes an informational message to the log. Message will be written
1228+
#' to the log at the point the function is called.
1229+
#' @param msg The message to log. The message must be a character string.
1230+
#' @param console Whether or not to print to the console. Valid values are
1231+
#' TRUE and FALSE. Default is TRUE.
1232+
#' @param blank_after Whether or not to print a blank line following the
1233+
#' printed message. The blank line helps readability of the log. Valid values
1234+
#' are TRUE and FALSE. Default is TRUE.
1235+
#' @param hide_notes If notes are on, this parameter gives you the option
1236+
#' of not printing notes for a particular log entry. Default is FALSE,
1237+
#' meaning notes will be displayed. Used internally.
1238+
#' @return The object, invisibly
1239+
#' @seealso \code{\link{log_warning}} to write a warning message to the log.
1240+
#' @export
1241+
#' @examples
1242+
#' library(logr)
1243+
#'
1244+
#' # Create temp file location
1245+
#' tmp <- file.path(tempdir(), "test.log")
1246+
#'
1247+
#' # Open log
1248+
#' lf <- log_open(tmp)
1249+
#'
1250+
#' # Send info to log
1251+
#' log_info("Here is an info message")
1252+
#'
1253+
#' # Close log
1254+
#' log_close()
1255+
#'
1256+
#' # View results
1257+
#' writeLines(readLines(lf))
1258+
#'
1259+
log_info <- function(msg,
1260+
console = TRUE,
1261+
blank_after = NULL,
1262+
hide_notes = FALSE) {
1263+
1264+
if (is.null(blank_after)) {
1265+
1266+
blank_after <- e$log_blank_after
1267+
}
1268+
1269+
if (all("character" %in% class(msg))) {
1270+
1271+
nmsg <- paste0("Info: ", msg)
1272+
1273+
# Pass everything to log_print()
1274+
ret <- log_print(nmsg, console = console, blank_after = blank_after,
1275+
msg = FALSE, hide_notes = hide_notes)
1276+
1277+
} else {
1278+
1279+
message("Info message must be a character string.")
1280+
}
1281+
1282+
invisible(ret)
1283+
}
1284+

_pkgdown.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ reference:
3636
- log_path
3737
- log_status
3838
- log_code
39+
- log_info
3940

4041

4142
navbar:

docs/news/index.html

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/pkgdown.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ articles:
1010
logr-put: logr-put.html
1111
logr-tidylog: logr-tidylog.html
1212
logr: logr.html
13-
last_built: 2025-01-28T22:18Z
13+
last_built: 2025-01-29T02:22Z
1414
urls:
1515
reference: https://logr.r-sassy.org/reference
1616
article: https://logr.r-sassy.org/articles

docs/reference/index.html

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/log_info.html

Lines changed: 172 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/sitemap.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<url><loc>https://logr.r-sassy.org/reference/log_close.html</loc></url>
2020
<url><loc>https://logr.r-sassy.org/reference/log_code.html</loc></url>
2121
<url><loc>https://logr.r-sassy.org/reference/log_error.html</loc></url>
22+
<url><loc>https://logr.r-sassy.org/reference/log_info.html</loc></url>
2223
<url><loc>https://logr.r-sassy.org/reference/log_open.html</loc></url>
2324
<url><loc>https://logr.r-sassy.org/reference/log_path.html</loc></url>
2425
<url><loc>https://logr.r-sassy.org/reference/log_print.html</loc></url>

man/log_info.Rd

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)