Issue #12224 has been reported by Kazuki Yamaguchi.

----------------------------------------
Feature #12224: logger: Allow specifying log level in constructor
https://bugs.ruby-lang.org/issues/12224

* Author: Kazuki Yamaguchi
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
When I use Logger class, I very often (or maybe always) set minimal log level together. Since method chaining can't be used for setters, we have to split it into two statements:

~~~ruby
logger = Logger.new($stdout)
logger.level = :info
~~~

Imagine if the `logger` was much longer name, such as ActiveRecord::Base.logger. I personally don't want to repeat it.
I found a number of samples on GitHub (they would countain copy-and-pastes though) [1].

So I propose adding a new keyword argument `level` to Logger.new:

~~~ruby
logger = Logger.new($stdout, level: :info)
~~~

This will be effectively same as the original code I indicated above.

I attached a patch for this.

[1] https://github.com/search?utf8=%E2%9C%93&q=%22%3D+Logger.new%22+%22level+%3D%22+language%3ARuby&type=Code&ref=searchresults

---Files--------------------------------
0001-lib-logger.rb-allow-specifying-log-level-via-Logger..patch (2.25 KB)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>