Learn R Programming

ribiosUtils (version 1.7.7)

writeLog: Write text as log to a connection

Description

The function writeLog can be used to log outputs and/or running status of scripts to one connection. To use it one does not need to run registerLog first.

Usage

writeLog(fmt, ..., con = stdout(), level = 0)

Value

Side effect is used.

Arguments

fmt

Format string to passed on to sprintf

...

Parameters passed on to sprintf

con

A connection, for instance a file (or its name) or stdout()

level

Logging level: each higher level will add one extra space before the message. See examples

Author

Jitao David Zhang <jitao_david.zhang@roche.com>

Details

In contrast, doLog can be used to log on multiple connections that are registered by registerLog. Therefore, to register logger(s) with registerLog is a prerequisite of calling doLog. Internally doLog calls writeLog sequentially to make multiple-connection logging.

See Also

registerLog to register more than one loggers so that doLog can write to them sequentially.

Examples

Run this code
# \donttest{
  writeLog("This is the start of a log")
  writeLog("Message 1", level=1)
  writeLog("Message 1.1", level=2)
  writeLog("Message 1.2", level=2)
  writeLog("Message 2", level=1)
  writeLog("Message 3", level=1)
  writeLog("Message 3 (special)", level=4)
  writeLog("End of the log");

  ## log with format
  writeLog("This is Message %d", 1)
  writeLog("Square of 2 is %2.2f", sqrt(2))

  ## NA is handled automatically
  writeLog("This is a not available value: %s", NA, level=1)
  writeLog("This is a NULL value: %s", NULL, level=1)
# }

Run the code above in your browser using DataLab