Module: Dapp::Project::Logging::Base

Included in:
Dapp::Project
Defined in:
lib/dapp/project/logging/base.rb

Overview

Base

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



125
126
127
# File 'lib/dapp/project/logging/base.rb', line 125

def included(base)
  base.extend(self)
end

Instance Method Details

#dry_run? ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/dapp/project/logging/base.rb', line 32

def dry_run?
  cli_options[:dry_run]
end

#ignore_config_warning? ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/dapp/project/logging/base.rb', line 20

def ignore_config_warning?
  cli_options[:ignore_config_warning]
end

#introspect_before_error? ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/dapp/project/logging/base.rb', line 28

def introspect_before_error?
  cli_options[:introspect_before_error]
end

#introspect_error? ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/dapp/project/logging/base.rb', line 24

def introspect_error?
  cli_options[:introspect_error]
end

#log(message = '', desc: nil, inline: false, **kwargs) ⇒ Object



75
76
77
78
79
80
81
82
# File 'lib/dapp/project/logging/base.rb', line 75

def log(message = '', desc: nil, inline: false, **kwargs)
  return if log_quiet?
  unless desc.nil?
    (desc[:data] ||= {})[:msg] = message
    message = t(**desc)
  end
  print "#{log_format_string(message, **kwargs)}#{"\n" unless inline}"
end

#log_config_warning(*args, **kwargs) ⇒ Object



70
71
72
73
# File 'lib/dapp/project/logging/base.rb', line 70

def log_config_warning(*args, **kwargs)
  return if ignore_config_warning?
  log_warning(*args, **kwargs)
end

#log_dimg_name_with_indent(dimg, &blk) ⇒ Object



41
42
43
44
# File 'lib/dapp/project/logging/base.rb', line 41

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) ⇒ Object



88
89
90
91
92
93
# File 'lib/dapp/project/logging/base.rb', line 88

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 ⇒ Object



108
109
110
# File 'lib/dapp/project/logging/base.rb', line 108

def log_indent
  ' ' * 2 * log_indent_size
end

#log_indent_next ⇒ Object



112
113
114
# File 'lib/dapp/project/logging/base.rb', line 112

def log_indent_next
  self.log_indent_size += 1
end

#log_indent_prev ⇒ Object



116
117
118
119
120
121
122
# File 'lib/dapp/project/logging/base.rb', line 116

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) ⇒ Object



36
37
38
39
# File 'lib/dapp/project/logging/base.rb', line 36

def log_info(*args, **kwargs)
  kwargs[:style] = :info
  log(*args, **kwargs)
end

#log_quiet? ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/dapp/project/logging/base.rb', line 8

def log_quiet?
  cli_options[:log_quiet]
end

#log_secondary(*args, **kwargs) ⇒ Object



58
59
60
61
# File 'lib/dapp/project/logging/base.rb', line 58

def log_secondary(*args, **kwargs)
  kwargs[:style] = :secondary
  log(*args, **kwargs)
end

#log_step(*args, **kwargs) ⇒ Object



53
54
55
56
# File 'lib/dapp/project/logging/base.rb', line 53

def log_step(*args, **kwargs)
  kwargs[:style] = :step
  log(*args, **kwargs)
end

#log_step_with_indent(step) ⇒ Object



46
47
48
49
50
51
# File 'lib/dapp/project/logging/base.rb', line 46

def log_step_with_indent(step)
  log_step(step)
  with_log_indent do
    yield
  end
end

#log_time ⇒ Object



84
85
86
# File 'lib/dapp/project/logging/base.rb', line 84

def log_time
  "#{DateTime.now.strftime('%Y-%m-%dT%T%z')} "
end

#log_time? ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/dapp/project/logging/base.rb', line 12

def log_time?
  cli_options[:log_time]
end

#log_verbose? ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/dapp/project/logging/base.rb', line 16

def log_verbose?
  cli_options[:log_verbose]
end

#log_warning(*args, **kwargs) ⇒ Object



63
64
65
66
67
68
# File 'lib/dapp/project/logging/base.rb', line 63

def log_warning(*args, **kwargs)
  kwargs[:style] = :warning
  kwargs[:desc] ||= {}
  kwargs[:desc][:context] ||= :warning
  log(*args, **kwargs)
end

#log_with_indent(message = '', **kwargs) ⇒ Object



95
96
97
98
99
# File 'lib/dapp/project/logging/base.rb', line 95

def log_with_indent(message = '', **kwargs)
  with_log_indent do
    log(message, **kwargs)
  end
end

#with_log_indent(with = true) ⇒ Object



101
102
103
104
105
106
# File 'lib/dapp/project/logging/base.rb', line 101

def with_log_indent(with = true)
  log_indent_next if with
  yield
ensure
  log_indent_prev if with
end