-
Notifications
You must be signed in to change notification settings - Fork 2
Patch logger to match Superlogger format, insert instrumentation logs #68
Conversation
jeremyyap
commented
Jan 13, 2017
- Patch ActiveSupport::Logger::SimpleFormatter to match Superlogger format
- Patch Flexirest gem to remove ANSI escape sequences for text color
- Insert log lines at the following positions:
- Evaluation job retrieved
- Evaluation package retrieved
- Evaluation job completed
caller_location = get_caller_location | ||
args = format_args(msg) | ||
|
||
"#{formatted_time} | CMEvaluator | CMEvaluator | #{formatted_severity} | #{caller_location} | #{args}\n" |
There was a problem hiding this comment.
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]
class ActiveSupport::Logger::SimpleFormatter | ||
def call(severity, time, progname, msg) | ||
formatted_severity = severity[0] | ||
formatted_time = time.strftime("%Y-%m-%d %H:%M:%S.") << time.usec.to_s[0..2].rjust(3) |
There was a problem hiding this comment.
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.
ActiveSupport::LogSubscriber.colorize_logging = false | ||
|
||
class ActiveSupport::Logger::SimpleFormatter | ||
def call(severity, time, progname, msg) |
There was a problem hiding this comment.
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.
lib/flexirest_patch.rb
Outdated
Flexirest::Logger.debug "#{Flexirest.name} #{key} - Writing to cache" | ||
cached_response = CachedResponse.new(status:response.status, result:result, response_headers: headers) | ||
cached_response.etag = "#{headers[:etag]}" if headers[:etag] | ||
cached_response.expires = Time.parse(headers[:expires]) rescue nil if headers[:expires] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid using rescue in its modifier form.
lib/flexirest_patch.rb
Outdated
key = "#{request.class_name}:#{request.original_url}" | ||
Flexirest::Logger.debug "#{Flexirest.name} #{key} - Writing to cache" | ||
cached_response = CachedResponse.new(status:response.status, result:result, response_headers: headers) | ||
cached_response.etag = "#{headers[:etag]}" if headers[:etag] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer to_s over string interpolation.
lib/flexirest_patch.rb
Outdated
if cache_store && (headers[:etag] || headers[:expires]) | ||
key = "#{request.class_name}:#{request.original_url}" | ||
Flexirest::Logger.debug "#{Flexirest.name} #{key} - Writing to cache" | ||
cached_response = CachedResponse.new(status:response.status, result:result, response_headers: headers) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space missing after colon.
Line is too long. [110/100]
lib/flexirest_patch.rb
Outdated
return unless !result.respond_to?(:_status) || [200, 304].include?(result._status) | ||
headers = response.response_headers | ||
|
||
headers.keys.select{|h| h.is_a? String}.each do |key| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space missing to the left of {.
Space between { and | missing.
Space missing inside }.
lib/flexirest_patch.rb
Outdated
key = "#{request.class_name}:#{request.original_url}" | ||
Flexirest::Logger.debug "#{Flexirest.name} #{key} - Trying to read from cache" | ||
value = cache_store.read(key) | ||
value = Marshal.load(value) rescue value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useless assignment to variable - value.
Avoid using rescue in its modifier form.
lib/flexirest_patch.rb
Outdated
|
||
def disable_automatic_date_parsing=(value) | ||
Flexirest::Logger.info "#{name} Request Body Type set to be #{value}" | ||
@@disable_automatic_date_parsing = value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace class var @@disable_automatic_date_parsing with a class instance var.
lib/flexirest_patch.rb
Outdated
|
||
def request_body_type=(value) | ||
Flexirest::Logger.info "#{name} Request Body Type set to be #{value}" | ||
@@request_body_type = value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace class var @@request_body_type with a class instance var.
lib/flexirest_patch.rb
Outdated
def password=(value) | ||
Flexirest::Logger.info "#{name} Password set..." | ||
value = CGI::escape(value) if value.present? && !value.include?("%") | ||
@@password = value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace class var @@password with a class instance var.
lib/flexirest_patch.rb
Outdated
|
||
def password=(value) | ||
Flexirest::Logger.info "#{name} Password set..." | ||
value = CGI::escape(value) if value.present? && !value.include?("%") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use :: for method calls.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
lib/flexirest_patch.rb
Outdated
def username=(value) | ||
Flexirest::Logger.info "#{name} Username set to be #{value}" | ||
value = CGI::escape(value) if value.present? && !value.include?("%") | ||
@@username = value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace class var @@username with a class instance var.
lib/flexirest_patch.rb
Outdated
|
||
def username=(value) | ||
Flexirest::Logger.info "#{name} Username set to be #{value}" | ||
value = CGI::escape(value) if value.present? && !value.include?("%") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use :: for method calls.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
lib/flexirest_patch.rb
Outdated
def base_url=(value) | ||
Flexirest::Logger.info "#{name} Base URL set to be #{value}" | ||
value = value.gsub(/\/+$/, '') | ||
@@base_url = value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace class var @@base_url with a class instance var.
lib/flexirest_patch.rb
Outdated
request_options[:api_auth] = { | ||
:api_auth_access_id => api_auth_access_id, | ||
:api_auth_secret_key => api_auth_secret_key, | ||
:api_auth_options => api_auth_options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the new Ruby 1.9 hash syntax.
@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}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant curly braces around a hash parameter.
Space inside { missing.
Space inside } missing.
@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}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant curly braces around a hash parameter.
Space inside { missing.
Space inside } missing.
lib/coursemology/evaluator/client.rb
Outdated
evaluation.evaluate | ||
end | ||
|
||
Coursemology::Evaluator.logger.info({event: 'Evaluation job completed', evaluation_id: evaluation.id}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant curly braces around a hash parameter.
Space inside { missing.
Line is too long. [106/100]
Space inside } missing.
lib/coursemology/evaluator/client.rb
Outdated
evaluation.evaluate | ||
end | ||
|
||
Coursemology::Evaluator.logger.info({event: 'Evaluation job completed', evaluation_id: evaluation.id}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant curly braces around a hash parameter.
Space inside { missing.
Line is too long. [106/100]
Space inside } missing.
lib/coursemology/evaluator/client.rb
Outdated
# @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}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant curly braces around a hash parameter.
Space inside { missing.
Line is too long. [106/100]
Space inside } missing.
lib/coursemology/evaluator/client.rb
Outdated
# @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}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant curly braces around a hash parameter.
Space inside { missing.
Line is too long. [106/100]
Space inside } missing.
"#{key}=#{value}" | ||
end.join(' | ') | ||
else | ||
args.to_s.gsub(/\033\[1;4;32m(.*)\033\[0m/, '\1') |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
Is it possible to make use of |