md.log: md.log

View source: R/md.log.R

md.logR Documentation

md.log

Description

produces Markdown log files with an optional argument to include the function call inside the Markdown log file.

Usage

md.log(msg, file = "", append = FALSE, sys.info = TRUE,
section="monospace", level="", trace=TRUE, date=FALSE,
time=FALSE, print=FALSE, datetime.fmt="%Y-%m-%d %H:%M:%S")

Arguments

msg

the text that is to be printed in the log file. By default msg is printed as monospace code inside the Markdown log, unless the section argument is used to change this behavior.

file

A connection, or a character string naming the file to print to. If "" (the default), the msg is printed to the standard output connection or the previously defined log file

append

logical. Only used if the argument file is the name of file (and not a connection). If TRUE, output will be appended to file; otherwise, it will overwrite the contents of file.

sys.info

logical. Only used Only used if the argument file is the name of file (and not a connection). If TRUE, the system information, R version, and date and time will be printed at the outset of the log file.

section

styles the msg argument with Markdown syntax and it can be monospace, section, subsection, or paragraph. the default value is monospace.

level

is a marker that is printed at the beginning of each monospace massage and cannot be more than seven characters long. this argument can be used to distinct massages with warnings or errors

trace

logical. If TRUE, the function call is included before each msg

date

logical. if TRUE, the current date is included before each msg

time

logical. if TRUE, the current time is included before each msg

print

logical. if TRUE, the massage is printed in R console as well.

datetime.fmt

specifies the format of date and time arguments and by default is "%Y-%m-%d %H:%M:%S". whitespace should only be used to separate the date and time formats

Author(s)

E. F. Haghish
Institute for Community Medicine
University of Greifswald, Germany
haghish@uni-greifswald.de
and
Institute for Medical Informatics (IMBI)
University of Freiburg, Germany
haghish@imbi.uni-freiburg.de

Examples

# --------------------------------------------------------------------
# Testing the md.log package
# ====================================================================

child = function() {
  md.log("current function", level="dope!")
}

parent = function(){
 md.log("step 2")
 child()
}

grandparent = function() {
 md.log("step 3")
 parent()
}

# The main test function that produces the log and calls the other functions
md.log.test = function() {
 require(md.log)
 md.log("Initiating a new Markdown log", file="markdown.log")

 # starting the logs
 md.log("a simple MONOSPACE log")
 md.log("Adding a level", level="notice")
 md.log("level makes you pay attention to a particular line")

 # add a subsection and a paragraph in the log
 md.log("This is a subsection", section="subsection")
 md.log("This is a text paragraph for detailed explanation...", section="paragraph")

 # testing the function call
 child()
 md.log("so far so good! now let's test a more complex nest")
 grandparent()
}

md.log.test()

md.log documentation built on Aug. 5, 2022, 5:25 p.m.