kafo 5.1.0 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,127 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'fileutils'
4
+ require 'logging'
5
+
6
+ module Kafo
7
+ class Logging
8
+
9
+ LOG_LEVELS = [:debug, :info, :notice, :warn, :error, :fatal]
10
+
11
+ if ::Logging::LEVELS.keys.map(&:to_symbol) != LOG_LEVELS
12
+ ::Logging.init(:debug, :info, :notice, :warn, :error, :fatal)
13
+ end
14
+
15
+ class << self
16
+ def root_logger
17
+ @root_logger ||= ::Logging.logger.root
18
+ end
19
+
20
+ def setup(verbose: false)
21
+ set_color_scheme
22
+
23
+ level = KafoConfigure.config.app[:log_level]
24
+
25
+ setup_file_logging(
26
+ level,
27
+ KafoConfigure.config.app[:log_dir],
28
+ KafoConfigure.config.app[:log_owner],
29
+ KafoConfigure.config.app[:log_group]
30
+ )
31
+ setup_verbose(level: KafoConfigure.config.app[:verbose_log_level] || level) if verbose
32
+ end
33
+
34
+ def setup_file_logging(log_level, log_dir, log_owner, log_group)
35
+ filename = KafoConfigure.config.log_file
36
+
37
+ begin
38
+ FileUtils.mkdir_p(log_dir, :mode => 0750)
39
+ rescue Errno::EACCES
40
+ puts "No permissions to create log dir #{log_dir}"
41
+ end
42
+
43
+ begin
44
+ root_logger.appenders = ::Logging.appenders.rolling_file(
45
+ 'configure',
46
+ level: log_level,
47
+ filename: filename,
48
+ layout: layout(color: false),
49
+ truncate: true
50
+ )
51
+
52
+ FileUtils.chown(
53
+ log_owner,
54
+ log_group,
55
+ filename
56
+ )
57
+ rescue ArgumentError
58
+ puts "File #{filename} not writeable, won't log anything to file!"
59
+ end
60
+ end
61
+
62
+ def set_color_scheme
63
+ ::Logging.color_scheme(
64
+ 'bright',
65
+ :levels => {
66
+ :info => :cyan,
67
+ :notice => :green,
68
+ :warn => :yellow,
69
+ :error => :red,
70
+ :fatal => [:white, :on_red]
71
+ },
72
+ :date => :blue,
73
+ :logger => :cyan,
74
+ :line => :yellow,
75
+ :file => :yellow,
76
+ :method => :yellow
77
+ )
78
+ end
79
+
80
+ def layout(color: false)
81
+ ::Logging::Layouts::Pattern.new(
82
+ pattern: "%d [%-6l] [%c] %m\n",
83
+ color_scheme: color ? 'bright' : nil,
84
+ date_pattern: '%Y-%m-%d %H:%M:%S'
85
+ )
86
+ end
87
+
88
+ def add_logger(name)
89
+ ::Logging.logger[name]
90
+ end
91
+
92
+ def setup_verbose(level: :notice)
93
+ root_logger.add_appenders(
94
+ ::Logging.appenders.stdout(
95
+ 'verbose',
96
+ layout: layout(color: KafoConfigure.use_colors?),
97
+ level: level
98
+ )
99
+ )
100
+ end
101
+
102
+ def buffer
103
+ @buffer ||= []
104
+ end
105
+
106
+ def buffering?
107
+ root_logger.appenders.empty?
108
+ end
109
+
110
+ def dump_needed?
111
+ !buffer.empty?
112
+ end
113
+
114
+ def to_buffer(*args)
115
+ buffer << args
116
+ end
117
+
118
+ def dump_buffer
119
+ @buffer.each do |log|
120
+ ::Logging.logger[log[0]].send(log[1], *([log[2]].flatten(2)), &log[3])
121
+ end
122
+ @buffer.clear
123
+ end
124
+ end
125
+
126
+ end
127
+ end
@@ -8,16 +8,22 @@ module Kafo
8
8
  method, message = case
9
9
  when line =~ /^Error:(.*)/i || line =~ /^Err:(.*)/i
10
10
  [:error, $1]
11
- when line =~ /^Warning:(.*)/i || line =~ /^Notice:(.*)/i
12
- [:warn, $1]
13
- when line =~ /^Info:(.*)/i
11
+ when line =~ /^Notice:(.*)/i
14
12
  [:info, $1]
15
- when line =~ /^Debug:(.*)/i
13
+ when line =~ /^Warning:(.*)/i || line =~ /^Debug:(.*)/i || line =~ /^Info:(.*)/i
16
14
  [:debug, $1]
17
15
  else
18
16
  [@last_level.nil? ? :info : @last_level, line]
19
17
  end
20
18
 
19
+ if message.include?('Loading facts') && method != :error
20
+ method = :debug
21
+ end
22
+
23
+ if message.include?('Applying configuration version')
24
+ method = :debug
25
+ end
26
+
21
27
  @last_level = method
22
28
  return [method, message.chomp.strip]
23
29
  end
@@ -7,6 +7,7 @@ module Kafo
7
7
  attr_reader :config_dir, :last_scenario_link, :previous_scenario
8
8
 
9
9
  def initialize(config, last_scenario_link_name='last_scenario.yaml')
10
+ @logger = Logger.new('scenario_manager')
10
11
  @config_dir = File.file?(config) ? File.dirname(config) : config
11
12
  @last_scenario_link = File.join(config_dir, last_scenario_link_name)
12
13
  @previous_scenario = File.exist?(last_scenario_link) ? Pathname.new(last_scenario_link).realpath.to_s : nil
@@ -30,7 +31,7 @@ module Kafo
30
31
  end
31
32
 
32
33
  def list_available_scenarios
33
- say ::HighLine.color("Available scenarios", :info)
34
+ say ::HighLine.color("Available scenarios", :notice)
34
35
  available_scenarios.each do |config_file, content|
35
36
  scenario = File.basename(config_file, '.yaml')
36
37
  use = (File.expand_path(config_file) == @previous_scenario ? 'INSTALLED' : "use: --scenario #{scenario}")
@@ -110,7 +111,7 @@ module Kafo
110
111
  end
111
112
 
112
113
  def show_scenario_diff(prev_scenario, new_scenario)
113
- say ::HighLine.color("Scenarios are being compared, that may take a while...", :info)
114
+ say ::HighLine.color("Scenarios are being compared, that may take a while...", :notice)
114
115
  prev_conf = load_and_setup_configuration(prev_scenario)
115
116
  new_conf = load_and_setup_configuration(new_scenario)
116
117
  print_scenario_diff(prev_conf, new_conf)
@@ -123,7 +124,7 @@ module Kafo
123
124
  dump_log_and_exit(0)
124
125
  else
125
126
  confirm_scenario_change(scenario)
126
- KafoConfigure.logger.info "Scenario #{scenario} was selected"
127
+ @logger.notice "Scenario #{scenario} was selected"
127
128
  end
128
129
  end
129
130
  end
@@ -166,7 +167,7 @@ module Kafo
166
167
  elsif !ARGV.include?('--force') && !KafoConfigure.in_help_mode?
167
168
  message = "You are trying to replace existing installation with different scenario. This may lead to unpredictable states. " +
168
169
  "Use --force to override. You can use --compare-scenarios to see the differences"
169
- KafoConfigure.logger.error(message)
170
+ @logger.error(message)
170
171
  dump_log_and_exit(:scenario_error)
171
172
  end
172
173
  true
@@ -225,19 +226,17 @@ module Kafo
225
226
 
226
227
  def fail_now(message, exit_code)
227
228
  $stderr.puts "ERROR: #{message}"
228
- KafoConfigure.logger.error message
229
+ @logger.error message
229
230
  KafoConfigure.exit(exit_code)
230
231
  end
231
232
 
232
233
  def dump_log_and_exit(code)
233
- if Logger.buffering? && Logger.buffer.any?
234
- Logger.setup_verbose
235
- KafoConfigure.verbose = true
234
+ if Logging.buffering? && Logging.buffer.any?
236
235
  if !KafoConfigure.config.nil?
237
- Logger.setup
238
- KafoConfigure.logger.info("Log was be written to #{KafoConfigure.config.log_file}")
236
+ Logging.setup(verbose: true)
237
+ @logger.notice("Log was be written to #{KafoConfigure.config.log_file}")
239
238
  end
240
- KafoConfigure.logger.info('Logs flushed')
239
+ @logger.notice('Logs flushed')
241
240
  end
242
241
  KafoConfigure.exit(code)
243
242
  end
@@ -15,7 +15,7 @@ module Kafo
15
15
  end
16
16
 
17
17
  def logger
18
- Logging::logger['checks']
18
+ ::Logging::logger['checks']
19
19
  end
20
20
 
21
21
  def check
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
  module Kafo
3
3
  PARSER_CACHE_VERSION = 1
4
- VERSION = "5.1.0"
4
+ VERSION = "6.0.0"
5
5
  end
@@ -68,7 +68,7 @@ END
68
68
 
69
69
  def display_hash
70
70
  data = Hash[@config.modules.map { |mod| [mod.name, mod.enabled? ? mod.params_hash : false] }]
71
- say HighLine.color(YAML.dump(data), :info)
71
+ say HighLine.color(YAML.dump(data), :notice)
72
72
  end
73
73
 
74
74
  def configure_module(mod)
@@ -79,7 +79,7 @@ END
79
79
  menu.prompt = 'Choose an option from the menu... '
80
80
  menu.select_by = :index
81
81
 
82
- menu.choice("Enable/disable #{mod.name} module, current value: #{HighLine.color(mod.enabled?.to_s, :info)}") { turn_module(mod) }
82
+ menu.choice("Enable/disable #{mod.name} module, current value: #{HighLine.color(mod.enabled?.to_s, :notice)}") { turn_module(mod) }
83
83
  if mod.enabled?
84
84
  render_params(mod.primary_parameter_group.params, menu)
85
85
 
@@ -114,7 +114,7 @@ END
114
114
  def render_params(params, menu)
115
115
  params.each do |param|
116
116
  if param.visible?(@kafo.params)
117
- menu.choice "Set #{HighLine.color(param.name, :important)}, current value: #{HighLine.color(param.value_to_s, :info)}" do
117
+ menu.choice "Set #{HighLine.color(param.name, :important)}, current value: #{HighLine.color(param.value_to_s, :notice)}" do
118
118
  configure(param)
119
119
  end
120
120
  end
@@ -141,13 +141,13 @@ END
141
141
  end
142
142
 
143
143
  def configure_single(param)
144
- say "\ncurrent value: #{HighLine.color(param.value_to_s, :info)}"
144
+ say "\ncurrent value: #{HighLine.color(param.value_to_s, :notice)}"
145
145
  ask("new value:")
146
146
  end
147
147
 
148
148
  def configure_multi(param)
149
- say HighLine.color('every line is a separate value, blank line to quit, for hash use key:value syntax', :info)
150
- say "\ncurrent value: #{HighLine.color(param.value_to_s, :info)} %>"
149
+ say HighLine.color('every line is a separate value, blank line to quit, for hash use key:value syntax', :notice)
150
+ say "\ncurrent value: #{HighLine.color(param.value_to_s, :notice)} %>"
151
151
  ask("new value:") do |q|
152
152
  q.gather = ""
153
153
  end
@@ -164,7 +164,7 @@ END
164
164
  say "\n" + HighLine.color("Resetting parameters of module #{mod.name}", :headline)
165
165
  choose do |menu|
166
166
  mod.params.each do |param|
167
- menu.choice "Reset #{HighLine.color(param.name, :important)}, current value: #{HighLine.color(param.value_to_s, :info)}, default value: #{HighLine.color(param.default_to_s, :info)}" do
167
+ menu.choice "Reset #{HighLine.color(param.name, :important)}, current value: #{HighLine.color(param.value_to_s, :notice)}, default value: #{HighLine.color(param.default_to_s, :notice)}" do
168
168
  reset(param)
169
169
  end if param.visible?(@kafo.params)
170
170
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kafo
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.0
4
+ version: 6.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marek Hulan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-17 00:00:00.000000000 Z
11
+ date: 2020-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -217,7 +217,10 @@ files:
217
217
  - config/kafo.yaml.example
218
218
  - doc/kafo_run.png
219
219
  - doc/kafo_run.uml
220
+ - doc/plantuml.jar
220
221
  - lib/kafo.rb
222
+ - lib/kafo/app_option/declaration.rb
223
+ - lib/kafo/app_option/definition.rb
221
224
  - lib/kafo/base_context.rb
222
225
  - lib/kafo/color_scheme.rb
223
226
  - lib/kafo/condition.rb
@@ -257,6 +260,7 @@ files:
257
260
  - lib/kafo/hooking.rb
258
261
  - lib/kafo/kafo_configure.rb
259
262
  - lib/kafo/logger.rb
263
+ - lib/kafo/logging.rb
260
264
  - lib/kafo/migration_context.rb
261
265
  - lib/kafo/migrations.rb
262
266
  - lib/kafo/param.rb
@@ -309,14 +313,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
309
313
  requirements:
310
314
  - - ">="
311
315
  - !ruby/object:Gem::Version
312
- version: 2.0.0
316
+ version: 2.4.0
313
317
  required_rubygems_version: !ruby/object:Gem::Requirement
314
318
  requirements:
315
319
  - - ">="
316
320
  - !ruby/object:Gem::Version
317
321
  version: '0'
318
322
  requirements: []
319
- rubygems_version: 3.1.2
323
+ rubygems_version: 3.1.4
320
324
  signing_key:
321
325
  specification_version: 4
322
326
  summary: A gem for making installations based on puppet user friendly