Module: SemanticLogger::Deprecation
- Defined in:
- lib/semantic_logger/deprecation.rb
Overview
Reports the use of a deprecated method or option as a Ruby deprecation warning, see Kernel#warn, so that Ruby
decides whether and where it is reported, as it does for its own deprecations, rather than a setting of Semantic
Logger:
- Only while deprecation warnings are on, see
Warning[:deprecated]. They are off by default, so production stays quiet, and on in tests run by Minitest or test-unit, or withruby -W:deprecatedorRUBYOPT=-W:deprecated. - Written to
$stderr, unless the application routes them elsewhere, such as to its log, or raises them in its tests, by overridingWarning.warn.
Each warning names the line of the application that used what is deprecated, rather than a line of Semantic Logger, of Ruby itself, or of a gem that Semantic Logger called with a block, see .application_location.
Copied from IOStreams::Deprecation, so that both libraries report deprecations the same way.
Class Method Summary collapse
-
.warn(message) ⇒ Object
Reports that the application used something deprecated, unless deprecation warnings are off, with the message, which says what is deprecated and what to use instead, after "SemanticLogger: ", at the line of the application that used it, see .application_location, in the same form as
Kernel#warnnames the line of its caller, such asconfig/initializers/logging.rb:12: warning: SemanticLogger: old is deprecated, use new instead, or without a line when the call stack has none outside this library. -
.warning?(message) ⇒ Boolean
Returns [true|false] whether the message, as
Kernel#warnpasses it toWarning.warn, is a warning reported by .warn, so that an application, or its tests, can tell the deprecation warnings of Semantic Logger from the others.
Class Method Details
.warn(message) ⇒ Object
Reports that the application used something deprecated, unless deprecation warnings are off, with the message,
which says what is deprecated and what to use instead, after "SemanticLogger: ", at the line of the application
that used it, see .application_location, in the same form as Kernel#warn names the line of its caller, such as
config/initializers/logging.rb:12: warning: SemanticLogger: old is deprecated, use new instead, or without a
line when the call stack has none outside this library.
Returns nil.
56 57 58 59 60 61 62 63 64 |
# File 'lib/semantic_logger/deprecation.rb', line 56 def self.warn() return unless Warning[:deprecated] location = application_location text = "#{PREFIX}#{}" text = "#{location.path}:#{location.lineno}: warning: #{text}" if location Kernel.warn(text, category: :deprecated) nil end |
.warning?(message) ⇒ Boolean
Returns [true|false] whether the message, as Kernel#warn passes it to Warning.warn, is a warning reported by
.warn, so that an application, or its tests, can tell the deprecation warnings of Semantic Logger from the others.
68 69 70 |
# File 'lib/semantic_logger/deprecation.rb', line 68 def self.warning?() WARNING.match?() end |