Skip to content

Commit

Permalink
feat: use structured logs for logging errors
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Jun 19, 2020
1 parent 2af4bf9 commit 1e097b3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 11 additions & 3 deletions lib/pact_broker/logging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,17 @@ def logger=(logger)
end

def log_error e, description = nil
message = "#{e.class} #{e.message}\n#{e.backtrace.join("\n")}"
message = "#{description} - #{message}" if description
logger.error message
if logger.instance_of?(SemanticLogger::Logger)
if description
logger.error(description, e)
else
logger.error(e)
end
else
message = "#{e.class} #{e.message}\n#{e.backtrace.join("\n")}"
message = "#{description} - #{message}" if description
logger.error message
end
if ENV['PACT_BROKER_HIDE_PACTFLOW_MESSAGES'] != 'true'
logger.info "\n\n#{'*' * 80}\n\nPrefer it was someone else's job to deal with this error? Check out https://pactflow.io/oss for a hardened, fully supported SaaS version of the Pact Broker with an improved UI + more.\n\n#{'*' * 80}\n"
end
Expand Down
4 changes: 3 additions & 1 deletion lib/pact_broker/logging/default_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ def initialize
end

def call(log, output)
@formatter.call(log.level.upcase, log.time, nil, log.message)
self.log = log
self.logger = logger
@formatter.call(log.level.upcase, log.time, nil, [tags, named_tags, duration, message, payload, exception].compact.join(" "))
end
end
end
Expand Down

0 comments on commit 1e097b3

Please sign in to comment.