<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/request-for-comments-on-planned-features-for-futile-logger-1-5/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://cartesianfaith.com/2018/12/15/request-for-comments-on-planned-features-for-futile-logger-1-5/"> R – Cartesian Faith</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>I will be pushing a new version of futile.logger (version 1.5) to CRAN in January. This version introduces a number of enhancements and fixes some bugs. It will also contain at least one breaking change. I am making the release process public, since the package is now used in a number of other packages. If you use <em>futile.logger</em>, this is your opportunity to influence the direction of the package and prepare for changes. Please use the <a rel="nofollow" href="https://github.com/zatonovo/futile.logger/issues" target="_blank">github issue tracker</a> for discussion.</p>
<p>There are two main themes for enhancements: 1) integration with the signal conditions, and 2) supporting multiple appenders with different  thresholds.</p>
<h3>Hijacking the signal system</h3>
<p>Currently, <em>futile.logger</em> is unaware of the signal system in R. The only tie-in is with <code>ftry</code>, which catches a warning or error and prints a message. Unfortunately, the behavior is different from <code>try</code>. This release will make <code>ftry</code> consistent with <code>try</code>. This is a breaking change, so if you use <code>ftry</code> in your code, it will no longer halt processing.</p>
<p>In addition to this fix, <em>futile.logger</em> will now have better integration with the signal system. Currently, if a function emits a warning or an error, these are printed to the screen. It would be convenient if <em>futile.logger</em> can capture these signals and associate them to the correct log levels, i.e. warning to WARN and error to ERROR.</p>
<p>My proposal is to create a <code>hijack_signal_handlers</code> function to override the existing signal handlers. This function can be called at the top of a script or within the <code>.onLoad</code> function of a package. Once called, any warnings or errors would be captured and handled by <em>futile.logger</em>. The implementation would look like this, giving granular control of whether to hijack just warning, errors, or both:</p>
<pre class="wp-block-preformatted">hijack_signal_handlers &lt;- function(warning=TRUE, error=TRUE) {<br>  if (warning) { <br>    # Override warning handler<br>  }<br>  if (error) {<br>    # Override error handler <br>  }<br>}<br></pre>
<p>One issue I see with this function is when used in a package’s .onLoad. Suppose a user requires package A and B. These don’t use <em>futile.logger</em>. Now the user requires package C, which calls <code>hijack_signal_handlers</code> in its <code>.onLoad</code>. When this occurs, warnings and errors emitted from packages A and B would also be captured by <em>futile.logger</em>. From my perspective, this is probably a good thing, but I can appreciate why others may not want this behavior. </p>
<h3>Emitting signals</h3>
<p>The other half of the signal handler puzzle is being able to emit signals from <em>futile.logger</em>. For this case, we want <code>flog.warn</code> to emit a warning signal and <code>flog.error</code> to emit an error signal. One signature looks like</p>
<pre class="wp-block-preformatted">flog.warn(message, emit=TRUE)</pre>
<p>meaning that by default no signal is emitted. This would work for <code>flog.warn</code>, <code>flog.error</code>, and <code>flog.fatal</code> (could map to error as well).</p>
<p>I have mixed feelings about this use case. Part of me says if <em>futile.logger</em> hijacks the signal system, then just use stop and <em>futile.logger</em> will catch it. On the other hand that seems roundabout and less capable than writing <code>flog.error(message, emit=TRUE)</code> or whatever.</p>
<p>Really my main concern is what happens when these two systems work together? Will they play nice or will an error be emitted twice (likely)? If not, then there is more logic that has to be built in, which ultimately adds complexity and wastes cycles. Any input here is encouraged!</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://cartesianfaith.com/2018/12/15/request-for-comments-on-planned-features-for-futile-logger-1-5/"> R – Cartesian Faith</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/eGvDrqxrTMQ" height="1"></a></div>