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

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



121
122
123
# File 'lib/dapp/dapp/logging/base.rb', line 121

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

Instance Method Details

#dev_mode?Boolean

Returns:

  • (Boolean)


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

def dev_mode?
  option_dev
end

#dry_run?Boolean

Returns:

  • (Boolean)


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

def dry_run?
  option_dry_run
end

#ignore_config_warning?Boolean

Returns:

  • (Boolean)


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

def ignore_config_warning?
  options[:ignore_config_warning]
end

#introspect_before_error?Boolean

Returns:

  • (Boolean)


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

def introspect_before_error?
  options[:introspect_before_error]
end

#introspect_error?Boolean

Returns:

  • (Boolean)


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

def introspect_error?
  options[:introspect_error]
end

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



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

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



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

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

#log_dimg_name_with_indent(dimg, &blk) ⇒ Object



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

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



90
91
92
93
94
95
# File 'lib/dapp/dapp/logging/base.rb', line 90

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



104
105
106
# File 'lib/dapp/dapp/logging/base.rb', line 104

def log_indent
  ' ' * 2 * log_indent_size
end

#log_indent_nextObject



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

def log_indent_next
  self.log_indent_size += 1
end

#log_indent_prevObject



112
113
114
115
116
117
118
# File 'lib/dapp/dapp/logging/base.rb', line 112

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



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

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

#log_quiet?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/dapp/dapp/logging/base.rb', line 5

def log_quiet?
  option_quiet
end

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



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

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

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



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

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

#log_step_with_indent(step) ⇒ Object



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

def log_step_with_indent(step)
  log_step(step)
  with_log_indent { yield }
end

#log_timeObject



86
87
88
# File 'lib/dapp/dapp/logging/base.rb', line 86

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

#log_time?Boolean

Returns:

  • (Boolean)


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

def log_time?
  option_time
end

#log_verbose?Boolean

Returns:

  • (Boolean)


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

def log_verbose?
  option_verbose
end

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



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

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_streamObject



126
127
128
129
130
131
132
133
134
# File 'lib/dapp/dapp/logging/base.rb', line 126

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



97
98
99
100
101
102
# File 'lib/dapp/dapp/logging/base.rb', line 97

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