bugsnag-maze-runner 9.0.0 → 9.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b7294cf169ef0a66ead9789be570496771a20734bb793340653b4235aa016f07
4
- data.tar.gz: 30bfe8f408345f79524c37165e9760b97a9acfb1c546628a1cac3b0aa3063f1f
3
+ metadata.gz: 2846c608ba08c4cd98faa8907c25e1d56ab36da97a56c28aa02aee8f39adf0b2
4
+ data.tar.gz: 75e3d297031547a4478c83added87975d5205e973f7777eddfe99718da664d9f
5
5
  SHA512:
6
- metadata.gz: ec4f97ffe50aa33479d9c3f36748ffe72932798d165e71f25072c69613cbb30c485a2efe0aec792aac6c50149ee885d9ecc52dc11a71c813313e79d7b2bfb4d5
7
- data.tar.gz: dd0e9a17df5d6298b59d5932777f423486ab8aed01b95625c47e72450325b61a71df0b417c984cf73a9c3fe029f29ec383defa29fd168270a0658abec418ff19
6
+ metadata.gz: 51b9290030731e65a5f93df77000e17a404b5fab4ca8e728606d2c3f29be4b1846fe36cc2e3fbd034a1d0b100396f735d28bd969da158bc9118f14b14d70a5bf
7
+ data.tar.gz: 023ae9dee40ce4d5e01d9a7f0bdd926754f1145d0a113ca91862841df5e6186a2884c36acdadcc34139e21f81743f2dc82b9330fabb119c9909343f4f7fa2562
data/bin/download-logs CHANGED
@@ -6,7 +6,7 @@ require 'em/pure_ruby'
6
6
 
7
7
  require_relative '../lib/maze'
8
8
  require_relative '../lib/maze/client/bs_client_utils'
9
- require_relative '../lib/maze/logger'
9
+ require_relative '../lib/maze/loggers/logger'
10
10
  require 'net/http'
11
11
  require 'json'
12
12
  require 'uri'
data/bin/maze-runner CHANGED
@@ -40,7 +40,6 @@ require_relative '../lib/maze/errors'
40
40
  require_relative '../lib/maze/generator'
41
41
  require_relative '../lib/maze/helper'
42
42
  require_relative '../lib/maze/http_request'
43
- require_relative '../lib/maze/logger'
44
43
  require_relative '../lib/maze/macos_utils'
45
44
  require_relative '../lib/maze/maze_output'
46
45
  require_relative '../lib/maze/metrics_processor'
@@ -53,6 +52,8 @@ require_relative '../lib/maze/repeaters/bugsnag_repeater'
53
52
  require_relative '../lib/maze/runner'
54
53
  require_relative '../lib/maze/terminating_server'
55
54
 
55
+ require_relative '../lib/maze/loggers/logger'
56
+
56
57
  require_relative '../lib/maze/servlets/base_servlet'
57
58
  require_relative '../lib/maze/servlets/all_commands_servlet'
58
59
  require_relative '../lib/maze/servlets/command_servlet'
@@ -85,6 +86,7 @@ require_relative '../lib/maze/hooks/appium_hooks'
85
86
  require_relative '../lib/maze/hooks/browser_hooks'
86
87
  require_relative '../lib/maze/hooks/command_hooks'
87
88
  require_relative '../lib/maze/hooks/error_code_hook'
89
+ require_relative '../lib/maze/hooks/logger_hooks'
88
90
 
89
91
  require_relative '../lib/maze/driver/appium'
90
92
  require_relative '../lib/maze/driver/browser'
@@ -93,6 +95,7 @@ require_relative '../lib/maze/plugins/bugsnag_reporting_plugin'
93
95
  require_relative '../lib/maze/plugins/error_code_plugin'
94
96
  require_relative '../lib/maze/plugins/global_retry_plugin'
95
97
  require_relative '../lib/maze/plugins/datadog_metrics_plugin'
98
+ require_relative '../lib/maze/plugins/logging_scenarios_plugin'
96
99
 
97
100
  # Require monkey-patches after everything else
98
101
  require_relative '../lib/utils/selenium_money_patch'
data/bin/purge-projects CHANGED
@@ -6,7 +6,7 @@ require 'em/pure_ruby'
6
6
 
7
7
  require_relative '../lib/maze'
8
8
  require_relative '../lib/maze/client/bb_api_client'
9
- require_relative '../lib/maze/logger'
9
+ require_relative '../lib/maze/loggers/logger'
10
10
  require_relative '../lib/maze/helper'
11
11
  require 'optimist'
12
12
  require 'uri'
data/bin/upload-app CHANGED
@@ -7,7 +7,7 @@ require 'em/pure_ruby'
7
7
  require_relative '../lib/maze'
8
8
  require_relative '../lib/maze/client/bs_client_utils'
9
9
  require_relative '../lib/maze/client/bb_client_utils'
10
- require_relative '../lib/maze/logger'
10
+ require_relative '../lib/maze/loggers/logger'
11
11
  require_relative '../lib/maze/helper'
12
12
  require 'optimist'
13
13
  require 'uri'
@@ -92,6 +92,9 @@ InstallPlugin do |config|
92
92
  # Only add the retry plugin if --retry is not used on the command line
93
93
  config.filters << Maze::Plugins::GlobalRetryPlugin.new(config) if config.options[:retry].zero?
94
94
 
95
+ # Add step logging
96
+ config.filters << Maze::Plugins::LoggingScenariosPlugin.new(config)
97
+
95
98
  # TODO: Reporting of test failures as errors deactivated pending PLAT-10963
96
99
  #config.filters << Maze::Plugins::BugsnagReportingPlugin.new(config)
97
100
  end
@@ -113,6 +116,9 @@ Before do |scenario|
113
116
 
114
117
  # Call any blocks registered by the client
115
118
  Maze.hooks.call_before scenario
119
+
120
+ # Invoke the logger hook for the scenario
121
+ Maze::Hooks::LoggerHooks.before scenario
116
122
  end
117
123
 
118
124
  # General processing to be run after each scenario
@@ -122,6 +128,9 @@ After do |scenario|
122
128
  Maze::MacosUtils.capture_screen(scenario)
123
129
  end
124
130
 
131
+ # Invoke the logger hook for the scenario
132
+ Maze::Hooks::LoggerHooks.after scenario
133
+
125
134
  # Call any blocks registered by the client
126
135
  Maze.hooks.call_after scenario
127
136
 
@@ -184,17 +193,17 @@ def output_received_requests(request_type)
184
193
  $stdout.puts "--- #{request_type} #{number} of #{count}"
185
194
 
186
195
  $logger.info 'Request body:'
187
- Maze::LogUtil.log_hash(Logger::Severity::INFO, request[:body])
196
+ Maze::Loggers::LogUtil.log_hash(Logger::Severity::INFO, request[:body])
188
197
 
189
198
  $logger.info 'Request headers:'
190
- Maze::LogUtil.log_hash(Logger::Severity::INFO, request[:request].header)
199
+ Maze::Loggers::LogUtil.log_hash(Logger::Severity::INFO, request[:request].header)
191
200
 
192
201
  $logger.info 'Request digests:'
193
- Maze::LogUtil.log_hash(Logger::Severity::INFO, request[:digests])
202
+ Maze::Loggers::LogUtil.log_hash(Logger::Severity::INFO, request[:digests])
194
203
 
195
204
  $logger.info "Response body: #{request[:response].body}"
196
205
  $logger.info 'Response headers:'
197
- Maze::LogUtil.log_hash(Logger::Severity::INFO, request[:response].header)
206
+ Maze::Loggers::LogUtil.log_hash(Logger::Severity::INFO, request[:response].header)
198
207
  end
199
208
  end
200
209
  end
@@ -226,6 +235,9 @@ end
226
235
 
227
236
  # After all tests
228
237
  AfterAll do
238
+ # Ensure the logger output is in the correct location
239
+ Maze::Hooks::LoggerHooks.after_all
240
+
229
241
  maze_output = File.join(Dir.pwd, 'maze_output')
230
242
  maze_output_zip = File.join(Dir.pwd, 'maze_output.zip')
231
243
  # zip a folder with files and subfolders
@@ -30,6 +30,8 @@ module Maze
30
30
  interval = 300
31
31
  elsif error.message.include? 'There are no devices available'
32
32
  interval = 120
33
+ elsif error.message.include? 'Appium Settings app is not running'
34
+ interval = 10
33
35
  else
34
36
  # Do not retry in any other case
35
37
  end
@@ -73,7 +75,9 @@ module Maze
73
75
  }
74
76
  capabilities.deep_merge! BitBarClientUtils.dashboard_capabilities
75
77
  capabilities.deep_merge! BitBarDevices.get_available_device(config.device)
78
+ capabilities['bitbar:options']['appiumVersion'] = config.appium_version unless config.appium_version.nil?
76
79
  capabilities.deep_merge! JSON.parse(config.capabilities_option)
80
+
77
81
  capabilities
78
82
  end
79
83
 
@@ -87,7 +91,7 @@ module Maze
87
91
  $logger.info 'Appium session(s) created:'
88
92
  @session_ids.each do |id|
89
93
  link = api_client.get_device_session_ui_link(id)
90
- $logger.info Maze::LogUtil.linkify(link, "BitBar session: #{id}") if link
94
+ $logger.info Maze::Loggers::LogUtil.linkify(link, "BitBar session: #{id}") if link
91
95
  end
92
96
  end
93
97
 
@@ -68,7 +68,7 @@ module Maze
68
68
  def log_run_intro
69
69
  # Log a link to the BrowserStack session search dashboard
70
70
  url = "https://app-automate.browserstack.com/dashboard/v2/search?query=#{Maze.run_uuid}&type=builds"
71
- $logger.info Maze::LogUtil.linkify(url, 'BrowserStack session(s)')
71
+ $logger.info Maze::Loggers::LogUtil.linkify(url, 'BrowserStack session(s)')
72
72
  end
73
73
 
74
74
  def log_run_outro
@@ -34,7 +34,7 @@ module Maze
34
34
  $logger.info 'Selenium session created:'
35
35
  id = Maze.driver.session_id
36
36
  link = api_client.get_device_session_ui_link(id)
37
- $logger.info Maze::LogUtil.linkify link, 'BitBar session(s)' if link
37
+ $logger.info Maze::Loggers::LogUtil.linkify link, 'BitBar session(s)' if link
38
38
  end
39
39
 
40
40
  def stop_session
@@ -85,7 +85,7 @@ module Maze
85
85
  def log_session_info
86
86
  # Log a link to the BrowserStack session search dashboard
87
87
  url = "https://automate.browserstack.com/dashboard/v2/search?query=#{Maze.run_uuid}&type=builds"
88
- $logger.info Maze::LogUtil.linkify url, 'BrowserStack session(s)'
88
+ $logger.info Maze::Loggers::LogUtil.linkify url, 'BrowserStack session(s)'
89
89
  end
90
90
  end
91
91
  end
@@ -3,7 +3,7 @@ require 'bugsnag'
3
3
  require 'json'
4
4
  require 'open3'
5
5
  require 'securerandom'
6
- require_relative '../logger'
6
+ require_relative '../loggers/logger'
7
7
  require_relative '../../maze'
8
8
 
9
9
  module Maze
@@ -43,7 +43,6 @@ module Maze
43
43
  end
44
44
 
45
45
  def after_all
46
- @client&.log_run_outro
47
46
  if $success
48
47
  Maze::Plugins::DatadogMetricsPlugin.send_increment('appium.test_succeeded')
49
48
  else
@@ -57,6 +56,7 @@ module Maze
57
56
 
58
57
  def at_exit
59
58
  if @client
59
+ @client.log_run_outro
60
60
  $logger.info 'Stopping the Appium session'
61
61
  @client.stop_session
62
62
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Maze
4
+ module Hooks
5
+ # Hooks for Browser mode use
6
+ class LoggerHooks
7
+ class << self
8
+ def before(scenario)
9
+ location = "\"# #{scenario.location}\""
10
+ $logger.trace ''
11
+ $logger.trace "\n--- Begin Scenario: #{scenario.name} #{location}"
12
+ end
13
+
14
+ def after(scenario)
15
+ location = "\"# #{scenario.location}\""
16
+ $logger.trace "--- End Scenario: #{scenario.name} #{location}"
17
+ $logger.trace ''
18
+ end
19
+
20
+ def after_all
21
+ if ENV['BUILDKITE']
22
+ FileUtils.mv("#{Dir.pwd}/#{Maze::Loggers::FileLogger::LOG_LOCATION}", "#{Dir.pwd}/maze_output/maze-runner.log")
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'logger'
4
+
5
+ module Maze
6
+ module Loggers
7
+ # A logger to file, always logging at TRACE level
8
+ class FileLogger < Logger
9
+
10
+ LOG_LOCATION = 'maze-runner.log'
11
+
12
+ include Singleton
13
+
14
+ attr_accessor :datetime_format
15
+
16
+ def initialize
17
+ # Remove the previous log file if it exists
18
+ File.delete(LOG_LOCATION) if File.exist?(LOG_LOCATION)
19
+
20
+ super(LOG_LOCATION, level: ::Logger::TRACE)
21
+
22
+ @datetime_format = '%H:%M:%S'
23
+
24
+ @formatter = proc do |severity, time, _name, message|
25
+ formatted_time = time.strftime(@datetime_format)
26
+
27
+ "\e[2m[#{formatted_time}]\e[0m #{severity.rjust(5)}: #{message}\n"
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Maze
4
+ module Loggers
5
+ # A collection of logging utilities
6
+ class LogUtil
7
+ class << self
8
+ # Logs Hash-based data, accounting for things like file upload requests that are too big to log meaningfully.
9
+ #
10
+ # @param severity [Integer] A constant from Logger::Severity
11
+ # @param data [Hash] The data to log (currently needs to be a Hash)
12
+ def log_hash(severity, data)
13
+ return unless data.is_a? Hash
14
+
15
+ # Try to pretty print as JSON, if not too big
16
+ begin
17
+ json = JSON.pretty_generate data
18
+ if json.length < 128 * 1024
19
+ $logger.add severity, json
20
+ else
21
+ log_hash_by_field severity, data
22
+ end
23
+ rescue Encoding::UndefinedConversionError => error
24
+ # Just give up, we don't want to risk a further error trying to log garbage
25
+ Bugsnag.notify error
26
+ $logger.error 'Unable to log hash as JSON'
27
+ end
28
+ end
29
+
30
+ # Logs a hash field by field,
31
+ #
32
+ # @param severity [Integer] A Logger::Severity
33
+ # @param hash [Hash] The Hash
34
+ def log_hash_by_field(severity, hash)
35
+ hash.keys.each do |key|
36
+ value = hash[key].to_s
37
+ if value.length < 1024
38
+ $logger.add severity, " #{key}: #{value}"
39
+ else
40
+ $logger.add severity, " #{key} (length): #{value.length}"
41
+ $logger.add severity, " #{key} (start): #{value[0, 1024]}"
42
+ end
43
+ end
44
+ end
45
+
46
+ # Produces a clickable link when logged in Buildkite
47
+ # @param url [String] Link URL
48
+ # @param text [String] Link text
49
+ def linkify(url, text)
50
+ if ENV['BUILDKITE']
51
+ "\033]1339;url='#{url}';content='#{text}'\a"
52
+ else
53
+ "#{text}: #{url}"
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bugsnag'
4
+ require 'logger'
5
+ require 'singleton'
6
+ require_relative 'file_logger'
7
+ require_relative 'log_util'
8
+ require_relative 'stdout_logger'
9
+
10
+ # Monkey patch a 'trace' log level into the standard Logger
11
+ class Logger
12
+ remove_const(:SEV_LABEL)
13
+ SEV_LABEL = {
14
+ -1 => 'TRACE',
15
+ 0 => 'DEBUG',
16
+ 1 => 'INFO',
17
+ 2 => 'WARN',
18
+ 3 => 'ERROR',
19
+ 4 => 'FATAL',
20
+ 5 => 'ANY'
21
+ }
22
+
23
+ module Severity
24
+ TRACE=-1
25
+ end
26
+
27
+ def trace(name = nil, &block)
28
+ add(TRACE, nil, name, &block)
29
+ end
30
+
31
+ def trace?
32
+ @level <= TRACE
33
+ end
34
+ end
35
+
36
+ module Maze
37
+ module Loggers
38
+ class Logger
39
+ include Singleton
40
+
41
+ attr_accessor :stdout_logger, :file_logger
42
+
43
+ def initialize
44
+ @stdout_logger = Maze::Loggers::STDOUTLogger.instance
45
+ @file_logger = Maze::Loggers::FileLogger.instance
46
+ end
47
+
48
+ # Attempts to forward all method calls to both loggers
49
+ def method_missing(method, *args, &block)
50
+ if @stdout_logger.respond_to?(method) && @file_logger.respond_to?(method)
51
+ @stdout_logger.send(method, *args, &block)
52
+ @file_logger.send(method, *args, &block)
53
+ else
54
+ super
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ $logger = Maze::Loggers::Logger.instance
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'logger'
4
+
5
+ module Maze
6
+ module Loggers
7
+ # A logger to STDOUT, with level configured according to the environment
8
+ class STDOUTLogger < Logger
9
+ include Singleton
10
+
11
+ attr_accessor :datetime_format
12
+
13
+ def initialize
14
+ if ENV['TRACE']
15
+ super(STDOUT, level: ::Logger::TRACE)
16
+ elsif ENV['DEBUG']
17
+ super(STDOUT, level: ::Logger::DEBUG)
18
+ elsif ENV['QUIET']
19
+ super(STDOUT, level: ::Logger::ERROR)
20
+ else
21
+ super(STDOUT, level: ::Logger::INFO)
22
+ end
23
+
24
+ @datetime_format = '%H:%M:%S'
25
+
26
+ @formatter = proc do |severity, time, _name, message|
27
+ formatted_time = time.strftime(@datetime_format)
28
+
29
+ "\e[2m[#{formatted_time}]\e[0m #{severity.rjust(5)}: #{message}\n"
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bugsnag'
4
+ require 'cucumber/core/filter'
5
+
6
+ module Maze
7
+ module Plugins
8
+ class LoggingScenariosPlugin < Cucumber::Core::Filter.new(:configuration)
9
+
10
+ def test_case(test_case)
11
+ configuration.on_event(:test_step_started) do |event|
12
+ $logger.trace "Step started: #{event.test_step.to_s}"
13
+ end
14
+
15
+ super
16
+ end
17
+ end
18
+ end
19
+ end
data/lib/maze/server.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  require 'bugsnag'
4
4
  require 'json'
5
5
  require 'webrick'
6
- require_relative './logger'
6
+ require_relative 'loggers/logger'
7
7
  require_relative './request_list'
8
8
 
9
9
  module Maze
data/lib/maze.rb CHANGED
@@ -7,7 +7,7 @@ require_relative 'maze/timers'
7
7
  # Glues the various parts of MazeRunner together that need to be accessed globally,
8
8
  # providing an alternative to the proliferation of global variables or singletons.
9
9
  module Maze
10
- VERSION = '9.0.0'
10
+ VERSION = '9.1.0'
11
11
 
12
12
  class << self
13
13
  attr_accessor :check, :driver, :internal_hooks, :mode, :start_time, :dynamic_retry, :public_address,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bugsnag-maze-runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.0.0
4
+ version: 9.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Kirkland
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-17 00:00:00.000000000 Z
11
+ date: 2024-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cucumber
@@ -409,9 +409,13 @@ files:
409
409
  - lib/maze/hooks/command_hooks.rb
410
410
  - lib/maze/hooks/error_code_hook.rb
411
411
  - lib/maze/hooks/hooks.rb
412
+ - lib/maze/hooks/logger_hooks.rb
412
413
  - lib/maze/http_request.rb
413
414
  - lib/maze/interactive_cli.rb
414
- - lib/maze/logger.rb
415
+ - lib/maze/loggers/file_logger.rb
416
+ - lib/maze/loggers/log_util.rb
417
+ - lib/maze/loggers/logger.rb
418
+ - lib/maze/loggers/stdout_logger.rb
415
419
  - lib/maze/macos_utils.rb
416
420
  - lib/maze/maze_output.rb
417
421
  - lib/maze/metrics_processor.rb
@@ -424,6 +428,7 @@ files:
424
428
  - lib/maze/plugins/datadog_metrics_plugin.rb
425
429
  - lib/maze/plugins/error_code_plugin.rb
426
430
  - lib/maze/plugins/global_retry_plugin.rb
431
+ - lib/maze/plugins/logging_scenarios_plugin.rb
427
432
  - lib/maze/proxy.rb
428
433
  - lib/maze/repeaters/aspecto_repeater.rb
429
434
  - lib/maze/repeaters/bugsnag_repeater.rb
data/lib/maze/logger.rb DELETED
@@ -1,117 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bugsnag'
4
- require 'logger'
5
- require 'singleton'
6
-
7
- # Monkey patch a 'trace' log level into the standard Logger
8
- class Logger
9
- remove_const(:SEV_LABEL)
10
- SEV_LABEL = {
11
- -1 => 'TRACE',
12
- 0 => 'DEBUG',
13
- 1 => 'INFO',
14
- 2 => 'WARN',
15
- 3 => 'ERROR',
16
- 4 => 'FATAL',
17
- 5 => 'ANY'
18
- }
19
-
20
- module Severity
21
- TRACE=-1
22
- end
23
-
24
- def trace(name = nil, &block)
25
- add(TRACE, nil, name, &block)
26
- end
27
-
28
- def trace?
29
- @level <= TRACE
30
- end
31
- end
32
-
33
- # Logger classes
34
- module Maze
35
- # A logger, with level configured according to the environment
36
- class Logger < Logger
37
- include Singleton
38
-
39
- attr_accessor :datetime_format
40
-
41
- def initialize
42
- if ENV['TRACE']
43
- super(STDOUT, level: Logger::TRACE)
44
- elsif ENV['DEBUG']
45
- super(STDOUT, level: Logger::DEBUG)
46
- elsif ENV['QUIET']
47
- super(STDOUT, level: Logger::ERROR)
48
- else
49
- super(STDOUT, level: Logger::INFO)
50
- end
51
-
52
- @datetime_format = '%H:%M:%S'
53
-
54
- @formatter = proc do |severity, time, _name, message|
55
- formatted_time = time.strftime(@datetime_format)
56
-
57
- "\e[2m[#{formatted_time}]\e[0m #{severity.rjust(5)}: #{message}\n"
58
- end
59
- end
60
- end
61
-
62
- $logger = Maze::Logger.instance
63
-
64
- # A collection of logging utilities
65
- class LogUtil
66
- class << self
67
- # Logs Hash-based data, accounting for things like file upload requests that are too big to log meaningfully.
68
- #
69
- # @param severity [Integer] A constant from Logger::Severity
70
- # @param data [Hash] The data to log (currently needs to be a Hash)
71
- def log_hash(severity, data)
72
- return unless data.is_a? Hash
73
-
74
- # Try to pretty print as JSON, if not too big
75
- begin
76
- json = JSON.pretty_generate data
77
- if json.length < 128 * 1024
78
- $logger.add severity, json
79
- else
80
- log_hash_by_field severity, data
81
- end
82
- rescue Encoding::UndefinedConversionError => error
83
- # Just give up, we don't want to risk a further error trying to log garbage
84
- Bugsnag.notify error
85
- $logger.error 'Unable to log hash as JSON'
86
- end
87
- end
88
-
89
- # Logs a hash field by field,
90
- #
91
- # @param severity [Integer] A Logger::Severity
92
- # @param hash [Hash] The Hash
93
- def log_hash_by_field(severity, hash)
94
- hash.keys.each do |key|
95
- value = hash[key].to_s
96
- if value.length < 1024
97
- $logger.add severity, " #{key}: #{value}"
98
- else
99
- $logger.add severity, " #{key} (length): #{value.length}"
100
- $logger.add severity, " #{key} (start): #{value[0, 1024]}"
101
- end
102
- end
103
- end
104
-
105
- # Produces a clickable link when logged in Buildkite
106
- # @param url [String] Link URL
107
- # @param text [String] Link text
108
- def linkify(url, text)
109
- if ENV['BUILDKITE']
110
- "\033]1339;url='#{url}';content='#{text}'\a"
111
- else
112
- "#{text}: #{url}"
113
- end
114
- end
115
- end
116
- end
117
- end