https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112016-01-06T16:27:06ZRuby Issue Tracking SystemRuby master - Feature #11955: Expose Object that Receives logs in Loggerhttps://bugs.ruby-lang.org/issues/11955?journal_id=559832016-01-06T16:27:06Zschneems (Richard Schneeman)
<ul></ul><p>Here is a patch to Rails that could benefit from standardizing access to the logger destination object: <a href="https://github.com/rails/rails/pull/22933" class="external">https://github.com/rails/rails/pull/22933</a></p> Ruby master - Feature #11955: Expose Object that Receives logs in Loggerhttps://bugs.ruby-lang.org/issues/11955?journal_id=559952016-01-07T05:44:38Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/55995/diff?detail_id=39956">diff</a>)</li></ul><p>Your example doesn't seem to able to get rid of adding <code>stdout_logger</code> twice or more, even with <code>logger.destination</code>.</p>
<p>Maybe won't it be better to do in <code>LogDevice</code> layer?</p> Ruby master - Feature #11955: Expose Object that Receives logs in Loggerhttps://bugs.ruby-lang.org/issues/11955?journal_id=560212016-01-08T17:00:56Zschneems (Richard Schneeman)
<ul></ul><blockquote>
<p>Your example doesn't seem to able to get rid of adding stdout_logger twice or more, even with logger.destination.</p>
</blockquote>
<p>It took a long time to write that example to be short, maybe I missed some details. A real world example is in that linked pull request, you can see the comparison I implemented <a href="https://github.com/rails/rails/blob/76c385709c873a7105e3a267d84c4e70417a15e2/activesupport/lib/active_support/logger.rb#L8-L17" class="external">https://github.com/rails/rails/blob/76c385709c873a7105e3a267d84c4e70417a15e2/activesupport/lib/active_support/logger.rb#L8-L17</a> this is where I would like to use a public interface instead of <code>instance_variable_get</code>.</p>
<p>LogDevice already exposes the destination, but Logger does not expose the LogDevice object. I did not know if there was a reason people did not what to provide access to LogDevice. Would you prefer that I submitted a patch to expose the LogDevice instead?</p> Ruby master - Feature #11955: Expose Object that Receives logs in Loggerhttps://bugs.ruby-lang.org/issues/11955?journal_id=561652016-01-19T20:03:23Zschneems (Richard Schneeman)
<ul><li><strong>File</strong> <a href="/attachments/5749">ruby-changes.patch</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/5749/ruby-changes.patch">ruby-changes.patch</a> added</li></ul><p>Nobu, I've added a new patch that would expose the <code>LogDevice</code> object in a <code>Logger</code> instance. This would be acceptable for my needs.</p> Ruby master - Feature #11955: Expose Object that Receives logs in Loggerhttps://bugs.ruby-lang.org/issues/11955?journal_id=561742016-01-20T00:27:27Zhsbt (Hiroshi SHIBATA)hsbt@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Assigned</i></li><li><strong>Assignee</strong> set to <i>sonots (Naotoshi Seo)</i></li></ul> Ruby master - Feature #11955: Expose Object that Receives logs in Loggerhttps://bugs.ruby-lang.org/issues/11955?journal_id=574672016-03-15T16:42:01Zschneems (Richard Schneeman)
<ul></ul><p>Anything else that needs to be done for this patch?</p> Ruby master - Feature #11955: Expose Object that Receives logs in Loggerhttps://bugs.ruby-lang.org/issues/11955?journal_id=581402016-04-18T13:16:18Zsonots (Naotoshi Seo)sonots@gmail.com
<ul></ul><p>I am wondering of the interface yet.</p>
<p>Users pass an io object to Logger constructor as <code>logdev</code> like <code>Logger.new(logdev)</code>, so getting the io object from <code>Logger#logdev</code> seems natural. However,</p>
<pre><code>attr_reader :logdev
</code></pre>
<p>returns a LogDevice instance rather than io object, which seems natural from the view of source codes.</p> Ruby master - Feature #11955: Expose Object that Receives logs in Loggerhttps://bugs.ruby-lang.org/issues/11955?journal_id=592852016-06-20T13:45:38Zschneems (Richard Schneeman)
<ul></ul><p>Sorry for the delay, bugs.ruby-lang.org does not send me emails for some reason.</p>
<p>The first patch I attached returned <code>@logdev.dev</code> which is the IO object. It was discussed that to do this Logger must know too much about the logdev interface and it would be simpler to expose the logdev instead.</p>
<p>Either approach will work for my use cases. Now that 2.4.0 preview is out is there a feature freeze? Is there any chance this will come out in time for christmas?</p> Ruby master - Feature #11955: Expose Object that Receives logs in Loggerhttps://bugs.ruby-lang.org/issues/11955?journal_id=677272017-11-09T11:35:33Ztensho (Andrew Babichev)
<ul></ul><p>So will <strong>#logdev</strong> will be exposed in Logger or Logger::LogDevice?</p> Ruby master - Feature #11955: Expose Object that Receives logs in Loggerhttps://bugs.ruby-lang.org/issues/11955?journal_id=995992022-10-15T08:38:58Zioquatix (Samuel Williams)samuel@oriontransfer.net
<ul></ul><p>I'm against this proposal because I think it's solving the wrong problem.</p>
<p>I don't think you should assume the <code>Logger</code> interface has the implementation provided by the <code>logger</code> gem, i.e. <code>Logger::LogDevice</code> is an implementation detail.</p>
<p>It should be very reasonable (as Rails appears to do) replace the logger with any compatible interface, which might not have the same underlying interface. By compatible interface, any object that responds to <code>info</code>, <code>warn</code>, <code>error</code>, etc.</p>
<p>I would say that trying to answer the question "Does calling <code>info</code> on this object emit data to STDOUT?" is fundamentally not part of the logger interface and therefore isn't a question you should be asking.</p>
<p>If your goal is to (1) when run interactively, log to STDOUT (or better, STDERR), and in addition, a file, and (2) when run non-interactively, only output to a file, I would suggest you model this in the configuration, e.g.</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="k">if</span> <span class="no">Rails</span><span class="p">.</span><span class="nf">interactive?</span>
<span class="no">Rails</span><span class="p">.</span><span class="nf">logger</span> <span class="o">=</span> <span class="no">TeeLogger</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="no">STDOUT</span><span class="p">,</span> <span class="n">file</span><span class="p">)</span>
<span class="k">else</span>
<span class="no">Rails</span><span class="p">.</span><span class="nf">logger</span> <span class="o">=</span> <span class="no">Logger</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="n">file</span><span class="p">)</span>
<span class="k">end</span>
</code></pre>
<p>This seems far more intuitive to me.</p>
<p>Is that possible?</p>