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



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

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

Instance Method Details

#dry_run?Boolean

Returns:

  • (Boolean)


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

def dry_run?
  cli_options[:dry_run]
end

#introspect_before_error?Boolean

Returns:

  • (Boolean)


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

def introspect_before_error?
  cli_options[:introspect_before_error]
end

#introspect_error?Boolean

Returns:

  • (Boolean)


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

def introspect_error?
  cli_options[:introspect_error]
end

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



59
60
61
62
63
64
65
66
# File 'lib/dapp/project/logging/base.rb', line 59

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_format_string(str, time: true, indent: true, style: nil) ⇒ Object



72
73
74
75
76
77
# File 'lib/dapp/project/logging/base.rb', line 72

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_indentObject



92
93
94
# File 'lib/dapp/project/logging/base.rb', line 92

def log_indent
  ' ' * 2 * log_indent_size
end

#log_indent_nextObject



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

def log_indent_next
  self.log_indent_size += 1
end

#log_indent_prevObject



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

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



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

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



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

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

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



44
45
46
47
# File 'lib/dapp/project/logging/base.rb', line 44

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

#log_step_with_indent(step) ⇒ Object



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

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

#log_timeObject



68
69
70
# File 'lib/dapp/project/logging/base.rb', line 68

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



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

def log_warning(*args, **kwargs)
  kwargs[:style] = :warning
  log(*args, **kwargs)
end

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



79
80
81
82
83
# File 'lib/dapp/project/logging/base.rb', line 79

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

#with_log_indent(with = true) ⇒ Object



85
86
87
88
89
90
# File 'lib/dapp/project/logging/base.rb', line 85

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