module Superhosting::Helper::Logger
Public Instance Methods
__debug()
click to toggle source
# File lib/superhosting/helper/logger.rb, line 39 def __debug Thread.current[:debug] end
__dry_run()
click to toggle source
# File lib/superhosting/helper/logger.rb, line 20 def __dry_run Thread.current[:dry_run] end
__dry_run=(val)
click to toggle source
# File lib/superhosting/helper/logger.rb, line 24 def __dry_run=(val) Thread.current[:dry_run] = val end
__logger()
click to toggle source
# File lib/superhosting/helper/logger.rb, line 4 def __logger Thread.current[:logger] end
__logger=(val)
click to toggle source
# File lib/superhosting/helper/logger.rb, line 8 def __logger=(val) Thread.current[:logger] = val end
debug(msg=nil, indent: true, desc: nil, &b)
click to toggle source
# File lib/superhosting/helper/logger.rb, line 52 def debug(msg=nil, indent: true, desc: nil, &b) unless self.__logger.nil? unless desc.nil? (desc[:data] ||= {})[:msg] = msg msg = t(desc: desc) end msg = indent ? with_indent(msg) : msg.chomp self.__logger.debug(msg, &b) end {} # net_status end
debug_block(desc: nil, operation: false) { || ... }
click to toggle source
# File lib/superhosting/helper/logger.rb, line 84 def debug_block(desc: nil, operation: false, &b) old = self.indent self.debug(desc: desc) self.indent_step status = :failed resp = yield status = :ok resp rescue Exception => e raise ensure self.debug(desc: { code: status }) self.indent = old end
debug_operation(desc: nil, &b)
click to toggle source
# File lib/superhosting/helper/logger.rb, line 64 def debug_operation(desc: nil, &b) old = self.indent status = :failed diff = nil resp = b.call do |resp| status = resp[:code] || :ok diff = resp[:diff] end resp rescue Exception => e raise ensure desc[:code] = :"#{desc[:code]}.#{status}" self.debug(desc: desc) self.debug(diff, indent: false) if !diff.nil? and self.__debug self.indent = old end
indent()
click to toggle source
# File lib/superhosting/helper/logger.rb, line 110 def indent @@indent ||= self.indent_reset end
indent=(val)
click to toggle source
# File lib/superhosting/helper/logger.rb, line 114 def indent=(val) @@indent = val end
indent_reset()
click to toggle source
# File lib/superhosting/helper/logger.rb, line 118 def indent_reset self.indent = 0 end
indent_step()
click to toggle source
# File lib/superhosting/helper/logger.rb, line 122 def indent_step self.indent += 1 end
indent_step_back()
click to toggle source
# File lib/superhosting/helper/logger.rb, line 126 def indent_step_back self.indent -= 1 end
info(msg=nil, indent: true, desc: nil, **kwargs, &b)
click to toggle source
# File lib/superhosting/helper/logger.rb, line 43 def info(msg=nil, indent: true, desc: nil, **kwargs, &b) unless self.__logger.nil? msg = indent ? with_indent(msg) : msg.chomp msg = kwargs if msg.empty? # TODO self.__logger.info(msg, &b) end {} # net_status end
storage()
click to toggle source
# File lib/superhosting/helper/logger.rb, line 35 def storage Thread.current[:dry_storage] ||= {} end
t(desc: {}, context: nil)
click to toggle source
# File lib/superhosting/helper/logger.rb, line 102 def t(desc: {}, context: nil) code = desc[:code] data = desc[:data] ::I18n.t [:debug, context, code].join('.'), [:debug, code].join('.'), **data, raise: true rescue ::I18n::MissingTranslationData => e raise NetStatus::Exception, { code: :missing_translation, data: { code: code } } end
with_dry_run() { |old| ... }
click to toggle source
# File lib/superhosting/helper/logger.rb, line 28 def with_dry_run old = __dry_run yield old ensure __dry_run = old end
with_indent(msg)
click to toggle source
# File lib/superhosting/helper/logger.rb, line 130 def with_indent(msg) ind = "#{' ' * 4 * self.indent }" "#{ind}#{msg.to_s.sub("\n", "\n#{ind}")}" end
with_logger(logger: nil) { || ... }
click to toggle source
# File lib/superhosting/helper/logger.rb, line 12 def with_logger(logger: nil) old = self.__logger self.__logger = nil if logger.is_a? FalseClass yield ensure self.__logger = old end