module Dapp::Dapp::Logging::Base

Attributes

log_indent_size[W]

Public Class Methods

included(base) click to toggle source
# File lib/dapp/dapp/logging/base.rb, line 6
def included(base)
  base.send(:extend, ClassMethods)
end

Public Instance Methods

dev_mode?() click to toggle source
# File lib/dapp/dapp/logging/base.rb, line 45
def dev_mode?
  option_dev
end
dry_run?() click to toggle source
# File lib/dapp/dapp/logging/base.rb, line 41
def dry_run?
  option_dry_run
end
ignore_config_warning?() click to toggle source
# File lib/dapp/dapp/logging/base.rb, line 29
def ignore_config_warning?
  !!options[:ignore_config_warning]
end
introspect_before_error?() click to toggle source
# File lib/dapp/dapp/logging/base.rb, line 37
def introspect_before_error?
  !!options[:introspect_before_error]
end
introspect_error?() click to toggle source
# File lib/dapp/dapp/logging/base.rb, line 33
def introspect_error?
  !!options[:introspect_error]
end
log(message = '', desc: nil, inline: false, stream: $stdout, **kwargs) click to toggle source
# File lib/dapp/dapp/logging/base.rb, line 89
def log(message = '', desc: nil, inline: false, stream: $stdout, **kwargs)
  return if log_quiet?
  unless desc.nil?
    (desc[:data] ||= {})[:msg] = message
    message = t(**desc)
  end
  stream.print "#{log_format_string(message, **kwargs)}#{"\n" unless inline}"
end
log_config_warning(*args, **kwargs) click to toggle source
# File lib/dapp/dapp/logging/base.rb, line 84
def log_config_warning(*args, **kwargs)
  return if ignore_config_warning?
  log_warning(*args, **kwargs)
end
log_dimg_name_with_indent(dimg) { || ... } click to toggle source
# File lib/dapp/dapp/logging/base.rb, line 54
def log_dimg_name_with_indent(dimg, &blk)
  return yield if dimg._name.nil?
  log_step_with_indent(dimg._name, &blk)
end
log_format_string(str, time: true, indent: true, style: nil) click to toggle source
# File lib/dapp/dapp/logging/base.rb, line 102
def log_format_string(str, time: true, indent: true, style: nil)
  str.to_s.lines.map do |line|
    line = paint_string(line, style) if style
    "#{log_time if time && log_time?}#{indent ? (log_indent + line) : line}"
  end.join
end
log_indent() click to toggle source
# File lib/dapp/dapp/logging/base.rb, line 116
def log_indent
  ' ' * 2 * log_indent_size
end
log_indent_next() click to toggle source
# File lib/dapp/dapp/logging/base.rb, line 120
def log_indent_next
  self.log_indent_size += 1
end
log_indent_prev() click to toggle source
# File lib/dapp/dapp/logging/base.rb, line 124
def log_indent_prev
  if self.log_indent_size <= 0
    self.log_indent_size = 0
  else
    self.log_indent_size -= 1
  end
end
log_info(*args, **kwargs) click to toggle source
# File lib/dapp/dapp/logging/base.rb, line 49
def log_info(*args, **kwargs)
  kwargs[:style] = :info
  log(*args, **kwargs)
end
log_quiet?() click to toggle source
# File lib/dapp/dapp/logging/base.rb, line 17
def log_quiet?
  option_quiet
end
log_secondary(*args, **kwargs) click to toggle source
# File lib/dapp/dapp/logging/base.rb, line 69
def log_secondary(*args, **kwargs)
  kwargs[:style] = :secondary
  log(*args, **kwargs)
end
log_step(*args, **kwargs) click to toggle source
# File lib/dapp/dapp/logging/base.rb, line 64
def log_step(*args, **kwargs)
  kwargs[:style] = :step
  log(*args, **kwargs)
end
log_step_with_indent(step) { || ... } click to toggle source
# File lib/dapp/dapp/logging/base.rb, line 59
def log_step_with_indent(step)
  log_step(step)
  with_log_indent { yield }
end
log_time() click to toggle source
# File lib/dapp/dapp/logging/base.rb, line 98
def log_time
  self.class.log_time
end
log_time?() click to toggle source
# File lib/dapp/dapp/logging/base.rb, line 21
def log_time?
  option_time
end
log_verbose?() click to toggle source
# File lib/dapp/dapp/logging/base.rb, line 25
def log_verbose?
  option_verbose
end
log_warning(*args, **kwargs) click to toggle source
# File lib/dapp/dapp/logging/base.rb, line 74
def log_warning(*args, **kwargs)
  kwargs[:style] = :warning
  kwargs[:stream] ||= $stderr
  if args.empty?
    kwargs[:desc] ||= {}
    kwargs[:desc][:context] ||= :warning
  end
  log(*args, **kwargs)
end
service_stream() click to toggle source
# File lib/dapp/dapp/logging/base.rb, line 132
def service_stream
  @@service_stream ||= begin
    fd = IO.sysopen("/tmp/dapp-service.log", "a")

    stream = IO.new(fd)
    stream.sync = true
    stream
  end
end
with_log_indent(with = true) { || ... } click to toggle source
# File lib/dapp/dapp/logging/base.rb, line 109
def with_log_indent(with = true)
  log_indent_next if with
  yield
ensure
  log_indent_prev if with
end

Protected Instance Methods

log_indent_size() click to toggle source
# File lib/dapp/dapp/logging/base.rb, line 146
def log_indent_size
  @log_indent_size ||= 0
end