This is a preview release of futile.logger 1.3.3 so some people with feature requests can try out the code before I push to CRAN.

A futile try/catch

It is now possible to capture non-futile warnings and errors by wrapping a block in ftry, which is essentially a wrapper around tryCatch. The return value is the value of the expression or the message invoked by a warning or

<br />&gt; ftry(log(-1))<br />WARN [2013-05-29 15:49:45] simpleWarning in log(-1): NaNs produced<br />

When using ftry, the warning and error handlers are defined to call flog.warn or flog.error, respectively. A finally statement can also be passed to ftry, just like in tryCatch.

<br />&gt; o &lt;- ftry(log(-1), finally=flog.info("In finally block"))<br />INFO [2013-05-29 15:54:26] In finally block<br />WARN [2013-05-29 15:54:26] simpleWarning in log(-1): NaNs produced<br />

Custom layouts

The default layout for the futile.logger is designed to be minimally function. For people who want control over their log output, it is now possible to call layout.format to define a format string for a logger. The available variables are:

~l The log level
~t The timestamp
~n The namespace of the calling function
~f The name of the calling function
~m The message string

None of these variables are required, although at a minimum ~m should be used so you get useful strings out. To set a logger's layout amounts to passing the closure generated by layout.format to flog.layout.

<br />&gt; flog.layout(layout.format('[~l] [~t] [~n.~f] ~m'))<br />&gt; dummy &lt;- function() { flog.info("Check out my shiny log message") }<br />&gt; dummy()<br />[INFO] [2013-05-29 16:26:19] [ROOT.dummy] Check out my shiny log message<br />

For those that are truly particular, the timestamp format can also be set using the datetime.fmt option.

Carping log messages

With a nod to PERL, I've also introduced (by request) the ability to return every single log message directed to futile.logger. This is a per logger setting and is returned invisibly so as to not clutter the console.

<br />&gt; flog.carp(TRUE)<br />NULL<br />&gt; flog.threshold(WARN)<br />NULL<br />&gt; o &lt;- flog.info("This won't print")<br />&gt; o<br />[1] "[INFO] [2013-05-29 16:29:11] [futile.logger.flog.info] This won't print\n"<br />

If you are testing this package, please let me know. The download link will be available for about a week, after which I will push to CRAN.

About these ads