Project

General

Profile

Feature #12224

logger: Allow specifying log level in constructor

Added by rhenium (Kazuki Yamaguchi) about 1 year ago. Updated about 1 year ago.

Status:
Closed
Priority:
Normal
Target version:
-
[ruby-core:74614]

Description

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:

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:

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

0001-lib-logger.rb-allow-specifying-log-level-via-Logger..patch View (2.25 KB) rhenium (Kazuki Yamaguchi), 03/28/2016 06:18 AM


Related issues

Duplicated by Ruby trunk - Feature #13244: stdlib/Logger: add option: level Rejected

Associated revisions

Revision 54638
Added by sonots (Naotoshi Seo) about 1 year ago

Allow specifying logger parameters in constructor

  • lib/logger.rb: Allow specifying logger prameters such as level, progname, datetime_format, formatter in constructor [Bug #12224]

Revision 54638
Added by sonots (Naotoshi Seo) about 1 year ago

Allow specifying logger parameters in constructor

  • lib/logger.rb: Allow specifying logger prameters such as level, progname, datetime_format, formatter in constructor [Bug #12224]

History

#1 [ruby-core:74718] Updated by shevegen (Robert A. Heiler) about 1 year ago

Here is the link to Logger:

http://ruby-doc.org/stdlib-2.3.0/libdoc/logger/rdoc/Logger.html#method-c-new

It already uses multiple arguments:

new(logdev, shift_age = 7, shift_size = 1048576)
new(logdev, shift_age = 'weekly') 

So I assume another optional one such as :level would be ok (my personal opinion).

#2 [ruby-core:74868] Updated by sonots (Naotoshi Seo) about 1 year ago

  • Assignee set to sonots (Naotoshi Seo)

#3 Updated by sonots (Naotoshi Seo) about 1 year ago

  • Status changed from Open to Closed

Applied in changeset r54638.


Allow specifying logger parameters in constructor

  • lib/logger.rb: Allow specifying logger prameters such as level, progname, datetime_format, formatter in constructor [Bug #12224]

#4 Updated by nobu (Nobuyoshi Nakada) 2 months ago

  • Duplicated by Feature #13244: stdlib/Logger: add option: level added

Also available in: Atom PDF