flog: Generates a logging message using glue and crayon, with some...

View source: R/logging.R

flogR Documentation

Generates a logging message using glue and crayon, with some bells/whistles.

Description

Like other logging approaches, each message created with this function is assigned a level (priority). If the current logging level, which is returned from a call to flog_level (ostensibly determenied by the value of the "facile.log.level(.*?)" option) is less than or equal to level of this message, then the message will be generated and sent to file. You can include a namespace for the message to provide a namespace-specific level/priority hierarchy.

Usage

flog(
  ...,
  level = "info",
  ns = NULL,
  session = NULL,
  file = stderr(),
  sep = "",
  fill = FALSE,
  labels = NULL,
  append = FALSE,
  newline = !is.null(file)
)

Arguments

...

the string elements to pass into glue::glue()

level

the "firing level" of this message. Defaults to "info"

ns

(namespace) if included, then the message checks the namespace-specific logging priority

session, file, sep, fill, labels, append

sent to base::cat()

newline

If TRUE, appends a ⁠\\n⁠ to the message. By default, this is TRUE when file is not NULL.

Details

Conveninece wrapper functions are provided for each logging level, ie. call fwarn("message") instead of flog("message", level = "warn")⁠. Also, each facile* package provides its own ⁠flog()⁠function which sets the namespace⁠ns' parameter to default to a package-specific namespace so you can control logging at the different package level.

Value

invisibly returns the text generated in the logging message.

Logging Levels

Logging levels are

.flog_levels <- c("all"  = 0, "trace" = 1, "debug" = 2, "info" = 3,
                  "warn" = 4, "error" = 5, "fatal" = 6)

crayon

Glue lets you put cayon functions in {} to stylize output. For instance, you can make "bold and red" the color red and also bold, like so:

flog("This is {red}{bold}bold and red{reset}, right?")

Nice! It might be more convenient if we could make it a bit more terse, as shown below, but that might happen at another time.

flog("This is rb`bold and red`, right?")

Colors:

  • b: blue

  • c: cyan

  • g: green

  • k: black

  • m: magenta

  • r: red

  • y: yellow

Styles:

  • i: italic

  • s: strong (bold)

  • S: striketthrough

  • u: underline


facilebio/FacileData documentation built on Feb. 23, 2024, 9:14 a.m.