Module: Dapp::Build::Stage::Mod::Logging

Included in:
Base
Defined in:
lib/dapp/build/stage/mod/logging.rb

Overview

Logging

Instance Method Summary collapse

Instance Method Details

#ignore_log_commands?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/dapp/build/stage/mod/logging.rb', line 85

def ignore_log_commands?
  false
end

#log_buildObject



19
20
21
22
23
24
# File 'lib/dapp/build/stage/mod/logging.rb', line 19

def log_build
  dimg.project.with_log_indent do
    dimg.project.log_info dimg.project.t(code: 'image.signature', data: { signature: image_name })
    log_image_details unless empty?
  end if dimg.project.log_verbose? && !should_be_quiet?
end

#log_image_build(&image_build) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/dapp/build/stage/mod/logging.rb', line 8

def log_image_build(&image_build)
  if empty?                            then log_state(:empty)
  elsif image.tagged?                  then log_state(:using_cache)
  elsif should_be_not_present?         then log_state(:not_present)
  elsif dimg.project.dry_run?          then log_state(:build, styles: { status: :success })
  else log_image_build_process(&image_build)
  end
ensure
  log_build
end

#log_image_build_processObject



77
78
79
80
81
82
83
# File 'lib/dapp/build/stage/mod/logging.rb', line 77

def log_image_build_process
  return yield if should_be_quiet?
  dimg.project.log_process(log_name, process: dimg.project.t(code: 'status.process.building'),
                                     short: should_not_be_detailed?) do
    yield
  end
end

#log_image_commandsObject



57
58
59
60
61
# File 'lib/dapp/build/stage/mod/logging.rb', line 57

def log_image_commands
  return if (bash_commands = image.send(:bash_commands)).empty?
  dimg.project.log_info dimg.project.t(code: 'image.commands')
  dimg.project.with_log_indent { dimg.project.log_info bash_commands.join("\n") }
end

#log_image_created_atObject



41
42
43
44
# File 'lib/dapp/build/stage/mod/logging.rb', line 41

def log_image_created_at
  dimg.project.log_info dimg.project.t(code: 'image.info.created_at',
                                       data: { value: Time.parse(image.created_at).localtime })
end

#log_image_detailsObject



26
27
28
29
30
31
32
33
# File 'lib/dapp/build/stage/mod/logging.rb', line 26

def log_image_details
  if image.tagged?
    log_image_created_at
    log_image_size
  end
  log_image_commands unless ignore_log_commands?
  log_image_instructions
end

#log_image_instructionsObject



35
36
37
38
39
# File 'lib/dapp/build/stage/mod/logging.rb', line 35

def log_image_instructions
  return if (instructions = image.prepare_instructions(image.send(:change_options))).empty?
  dimg.project.log_info dimg.project.t(code: 'image.instructions')
  dimg.project.with_log_indent { dimg.project.log_info instructions.join("\n") }
end

#log_image_sizeObject



46
47
48
49
50
51
52
53
54
55
# File 'lib/dapp/build/stage/mod/logging.rb', line 46

def log_image_size
  if !prev_stage.nil? && from_image.tagged?
    size = image.size.to_f - from_image.size.to_f
    code = 'image.info.difference'
  else
    size = image.size
    code = 'image.info.size'
  end
  dimg.project.log_info dimg.project.t(code: code, data: { value: size.to_f.round(2) })
end

#log_nameObject



63
64
65
# File 'lib/dapp/build/stage/mod/logging.rb', line 63

def log_name
  dimg.project.t(code: name, context: log_name_context)
end

#log_name_contextObject



67
68
69
# File 'lib/dapp/build/stage/mod/logging.rb', line 67

def log_name_context
  :stage
end

#log_state(state_code, styles: {}) ⇒ Object



71
72
73
74
75
# File 'lib/dapp/build/stage/mod/logging.rb', line 71

def log_state(state_code, styles: {})
  dimg.project.log_state(log_name,
                         state: dimg.project.t(code: state_code, context: 'state'),
                         styles: styles) unless should_be_quiet?
end

#should_be_introspected?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/dapp/build/stage/mod/logging.rb', line 93

def should_be_introspected?
  dimg.project.cli_options[:introspect_stage] == name && !dimg.project.dry_run? && !dimg.artifact?
end

#should_be_quiet?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/dapp/build/stage/mod/logging.rb', line 97

def should_be_quiet?
  dimg.artifact? && !dimg.project.log_verbose?
end

#should_not_be_detailed?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/dapp/build/stage/mod/logging.rb', line 89

def should_not_be_detailed?
  image.send(:bash_commands).empty?
end