Skip to content
This repository was archived by the owner on Sep 25, 2019. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/coursemology/evaluator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true
require 'active_support/all'
require 'simple_formatter_patch'
require 'flexirest'
require 'faraday_middleware'
require 'docker'
Expand Down
4 changes: 4 additions & 0 deletions lib/coursemology/evaluator/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,15 @@ def on_allocate(evaluations)
# @param [Coursemology::Evaluator::Models::ProgrammingEvaluation] evaluation The evaluation
# retrieved from the server.
def on_evaluation(evaluation)
Coursemology::Evaluator.logger.info(event: 'Evaluation job retrieved',
evaluation_id: evaluation.id)
ActiveSupport::Notifications.instrument('evaluate.client.evaluator.coursemology',
evaluation: evaluation) do
evaluation.evaluate
end

Coursemology::Evaluator.logger.info(event: 'Evaluation job completed',
evaluation_id: evaluation.id)
ActiveSupport::Notifications.instrument('save.client.evaluator.coursemology') do
evaluation.save
end
Expand Down
2 changes: 2 additions & 0 deletions lib/coursemology/evaluator/models/programming_evaluation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def package
@package ||= begin
body = self.class._plain_request('courses/assessment/programming_evaluations/:id/package',
:get, id: id)
Coursemology::Evaluator.logger.info(event: 'Evaluation package received',
evaluation_id: id)
Package.new(Coursemology::Evaluator::StringIO.new(body))
end
end
Expand Down
35 changes: 35 additions & 0 deletions lib/simple_formatter_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true
ActiveSupport::LogSubscriber.colorize_logging = false

class ActiveSupport::Logger::SimpleFormatter
def call(severity, time, progname, msg)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused method argument - progname. If it's necessary, use _ or _progname as an argument name to indicate that it won't be used.

formatted_severity = severity[0]
formatted_time = time.strftime("%Y-%m-%d %H:%M:%S.") << time.usec.to_s[0..2].rjust(3)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer single-quoted strings when you don't need string interpolation or special symbols.

caller_location = get_caller_location
args = format_args(msg)

"#{formatted_time} | CMEvaluator | CMEvaluator | #{formatted_severity} | #{caller_location} | #{args}\n"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [108/100]

end

def format_args(args)
output = if args.is_a?(Hash)
# Format args in key=value pair, separated by pipes
args.map do |key, value|
"#{key}=#{value}"
end.join(' | ')
else
args.to_s.gsub(/\033\[1;4;32m(.*)\033\[0m/, '\1')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add that this is msg=foo?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This follows the behaviour of Superlogger:

If it receives a hash it will print out as msg=foo
Otherwise, it will just print out the msg converted to string.

end
output.squish
end

def get_caller_location
location = caller_locations(6, 1).first

# Extract filename without file extension from location.path
# eg. superlogger/lib/superlogger/logger.rb
file = location.path.split('/').last.split('.').first

"#{file}:#{location.lineno}"
end
end