printlog: Log a message

Description Usage Arguments Details Value Note See Also Examples

Description

Log a message

Usage

1
2
3
4
printlog(..., level = 0, ts = TRUE, cr = TRUE, flag = FALSE,
  flush = FALSE)

flaglog(...)

Arguments

...

Expressions to be printed to the log

level

Priority level (numeric, optional)

ts

Print preceding timestamp? (logical, optional)

cr

Print trailing newline? (logical, optional)

flag

Flag this message (e.g. error or warning) (logical, optional)

flush

Immediately flush output to file (logical, optional)

Details

Logs a message, which consists of zero or more printable objects. Simple objects (numeric and character) are printed together on a single line, whereas complex objects (data frames, etc) start on a new line by themselves.

If the current log was opened with sink = TRUE, messages are printed to the screen, otherwise not. Messages can be flagged; flaglog assumes that the message is to be flagged, whereas printlog does not.

Messages will only appear in the logfile if their level exceeds the log's loglevel; this allows you to easily change the amount of detail being logged.

Value

Invisible success (TRUE) or failure (FALSE).

Note

A message's preceding timestamp and following carriage return can be suppressed using the ts and cr parameters.

See Also

openlog closelog

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
logfile <- openlog("test.log")
printlog("message")
printlog(1, "plus", 1, "equals", 1 + 1)
closelog()
readLines(logfile)

logfile <- openlog("test", loglevel = 1)
printlog("This message will not appear", level = 0)
printlog("This message will appear", level = 1)
closelog()
readLines(logfile)

Example output

sh: 1: cannot create /dev/null: Permission denied
 [1] "Wed Apr 18 00:42:19 2018  Opening test.log "                              
 [2] "Wed Apr 18 00:42:19 2018  message "                                       
 [3] "Wed Apr 18 00:42:19 2018  1 plus 1 equals 2 "                             
 [4] "Wed Apr 18 00:42:19 2018  Closing test.log flags = 0 "                    
 [5] "-------"                                                                  
 [6] "R version 3.4.1 (2017-06-30)"                                             
 [7] "Platform: x86_64-pc-linux-gnu (64-bit)"                                   
 [8] ""                                                                         
 [9] "Matrix products: default"                                                 
[10] "BLAS: /usr/lib/atlas-base/atlas/libblas.so.3.0"                           
[11] "LAPACK: /usr/lib/lapack/liblapack.so.3.0"                                 
[12] ""                                                                         
[13] "locale:"                                                                  
[14] "[1] C"                                                                    
[15] ""                                                                         
[16] "attached base packages:"                                                  
[17] "[1] stats     graphics  grDevices utils     datasets  methods   base     "
[18] ""                                                                         
[19] "other attached packages:"                                                 
[20] "[1] luzlogr_0.2.0"                                                        
[21] ""                                                                         
[22] "loaded via a namespace (and not attached):"                               
[23] "[1] compiler_3.4.1   assertthat_0.2.0"                                    
sh: 1: cannot create /dev/null: Permission denied
 [1] "Wed Apr 18 00:42:19 2018  Opening test "                                  
 [2] "Wed Apr 18 00:42:19 2018  This message will appear "                      
 [3] "Wed Apr 18 00:42:19 2018  Closing test flags = 0 "                        
 [4] "-------"                                                                  
 [5] "R version 3.4.1 (2017-06-30)"                                             
 [6] "Platform: x86_64-pc-linux-gnu (64-bit)"                                   
 [7] ""                                                                         
 [8] "Matrix products: default"                                                 
 [9] "BLAS: /usr/lib/atlas-base/atlas/libblas.so.3.0"                           
[10] "LAPACK: /usr/lib/lapack/liblapack.so.3.0"                                 
[11] ""                                                                         
[12] "locale:"                                                                  
[13] "[1] C"                                                                    
[14] ""                                                                         
[15] "attached base packages:"                                                  
[16] "[1] stats     graphics  grDevices utils     datasets  methods   base     "
[17] ""                                                                         
[18] "other attached packages:"                                                 
[19] "[1] luzlogr_0.2.0"                                                        
[20] ""                                                                         
[21] "loaded via a namespace (and not attached):"                               
[22] "[1] compiler_3.4.1   assertthat_0.2.0"                                    

luzlogr documentation built on May 2, 2019, 2:14 p.m.