lib/sord/logging.rb in sord-0.8.0 vs lib/sord/logging.rb in sord-0.9.0
- old
+ new
@@ -1,6 +1,7 @@
-require 'colorize'
+# typed: true
+require 'rainbow'
module Sord
# Handles writing logs to stdout and any other classes which request them.
module Logging
# This is an Array of callables which are all executed upon a log message.
@@ -66,131 +67,121 @@
# with some unique colour applied.
# @param [String] msg The log message to write.
# @param [YARD::CodeObjects::Base] item The CodeObject which this log
# is associated with, if any. This is shown before the log message if it is
# specified.
- # @param [Integer] indent_level The level at which to indent the code.
# @return [void]
- def self.generic(kind, header, msg, item, indent_level = 0)
+ def self.generic(kind, header, msg, item)
return unless enabled_types.include?(kind)
if item
- puts "#{header} (#{item.path.bold}) #{msg}" unless silent?
+ puts "#{header} (#{Rainbow(item.path).bold}) #{msg}" unless silent?
else
puts "#{header} #{msg}" unless silent?
end
- invoke_hooks(kind, msg, item, indent_level)
+ invoke_hooks(kind, msg, item)
end
# Print a warning message. This should be used for things which require the
# user's attention but do not prevent the process from stopping.
# @param [String] msg The log message to write.
# @param [YARD::CodeObjects::Base] item The CodeObject which this log
# is associated with, if any. This is shown before the log message if it is
# specified.
- # @param [Integer] indent_level The level at which to indent the code.
# @return [void]
- def self.warn(msg, item = nil, indent_level = 0)
- generic(:warn, '[WARN ]'.yellow, msg, item, indent_level)
+ def self.warn(msg, item = nil)
+ generic(:warn, Rainbow('[WARN ]').yellow, msg, item)
end
# Print an info message. This should be used for generic informational
# messages which the user doesn't need to act on.
# @param [String] msg The log message to write.
# @param [YARD::CodeObjects::Base] item The CodeObject which this log
# is associated with, if any. This is shown before the log message if it is
# specified.
- # @param [Integer] indent_level The level at which to indent the code.
# @return [void]
- def self.info(msg, item = nil, indent_level = 0)
- generic(:info, '[INFO ]', msg, item, indent_level)
+ def self.info(msg, item = nil)
+ generic(:info, '[INFO ]', msg, item)
end
# Print a duck-typing message. This should be used when the YARD
# documentation contains duck typing, which isn't supported by Sorbet, so
# it is substituted for something different.
# @param [String] msg The log message to write.
# @param [YARD::CodeObjects::Base] item The CodeObject which this log
# is associated with, if any. This is shown before the log message if it is
# specified.
- # @param [Integer] indent_level The level at which to indent the code.
# @return [void]
- def self.duck(msg, item = nil, indent_level = 0)
- generic(:duck, '[DUCK ]'.cyan, msg, item, indent_level)
+ def self.duck(msg, item = nil)
+ generic(:duck, Rainbow('[DUCK ]').cyan, msg, item)
end
# Print an error message. This should be used for things which require the
# current process to stop.
# @param [String] msg The log message to write.
# @param [YARD::CodeObjects::Base] item The CodeObject which this log
# is associated with, if any. This is shown before the log message if it is
# specified.
- # @param [Integer] indent_level The level at which to indent the code.
# @return [void]
- def self.error(msg, item = nil, indent_level = 0)
- generic(:error, '[ERROR]'.red, msg, item, indent_level)
+ def self.error(msg, item = nil)
+ generic(:error, Rainbow('[ERROR]').red, msg, item)
end
# Print an infer message. This should be used when the user should be told
# that some information has been filled in or guessed for them, and that
# information is likely correct.
# @param [String] msg The log message to write.
# @param [YARD::CodeObjects::Base] item The CodeObject which this log
# is associated with, if any. This is shown before the log message if it is
# specified.
- # @param [Integer] indent_level The level at which to indent the code.
# @return [void]
- def self.infer(msg, item = nil, indent_level = 0)
- generic(:infer, '[INFER]'.light_blue, msg, item, indent_level)
+ def self.infer(msg, item = nil)
+ generic(:infer, Rainbow('[INFER]').blue, msg, item)
end
# Print an omit message. This should be used as a special type of warning
# to alert the user that there is some information missing, but this
# information is not critical to the completion of the process.
# @param [String] msg The log message to write.
# @param [YARD::CodeObjects::Base] item The CodeObject which this log
# is associated with, if any. This is shown before the log message if it is
# specified.
- # @param [Integer] indent_level The level at which to indent the code.
# @return [void]
- def self.omit(msg, item = nil, indent_level = 0)
- generic(:omit, '[OMIT ]'.magenta, msg, item, indent_level)
+ def self.omit(msg, item = nil)
+ generic(:omit, Rainbow('[OMIT ]').magenta, msg, item)
end
# Print a done message. This should be used when a process completes
# successfully.
# @param [String] msg The log message to write.
# @param [YARD::CodeObjects::Base] item The CodeObject which this log
# is associated with, if any. This is shown before the log message if it is
# specified.
- # @param [Integer] indent_level The level at which to indent the code.
# @return [void]
- def self.done(msg, item = nil, indent_level = 0)
- generic(:done, '[DONE ]'.green, msg, item)
+ def self.done(msg, item = nil)
+ generic(:done, Rainbow('[DONE ]').green, msg, item)
end
# Invokes all registered hooks on the logger.
# @param [Symbol] kind The kind of log message this is.
# @param [String] msg The log message to write.
# @param [YARD::CodeObjects::Base] item The CodeObject which this log
# is associated with, if any. This is shown before the log message if it is
# specified.
- # @param [Integer] indent_level The level at which to indent the code.
# @return [void]
- def self.invoke_hooks(kind, msg, item, indent_level = 0)
+ def self.invoke_hooks(kind, msg, item)
@@hooks.each do |hook|
- hook.(kind, msg, item, indent_level) rescue nil
+ hook.(kind, msg, item) rescue nil
end
end
# Adds a hook to the logger.
# @yieldparam [Symbol] kind The kind of log message this is.
# @yieldparam [String] msg The log message to write.
# @yieldparam [YARD::CodeObjects::Base] item The CodeObject which this log
# is associated with, if any. This is shown before the log message if it is
# specified.
- # @yieldparam [Integer] indent_level The level at which to indent the code.
# @yieldreturn [void]
# @return [void]
def self.add_hook(&blk)
@@hooks << blk
end