Skip to content
This repository was archived by the owner on Sep 25, 2019. It is now read-only.

Conversation

jeremyyap
Copy link
Member

  • 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"

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)

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)

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.

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]

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.

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]

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.

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)

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]

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|

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 }.

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

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.


def disable_automatic_date_parsing=(value)
Flexirest::Logger.info "#{name} Request Body Type set to be #{value}"
@@disable_automatic_date_parsing = value

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.


def request_body_type=(value)
Flexirest::Logger.info "#{name} Request Body Type set to be #{value}"
@@request_body_type = value

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.

def password=(value)
Flexirest::Logger.info "#{name} Password set..."
value = CGI::escape(value) if value.present? && !value.include?("%")
@@password = value

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.


def password=(value)
Flexirest::Logger.info "#{name} Password set..."
value = CGI::escape(value) if value.present? && !value.include?("%")

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.

def username=(value)
Flexirest::Logger.info "#{name} Username set to be #{value}"
value = CGI::escape(value) if value.present? && !value.include?("%")
@@username = value

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.


def username=(value)
Flexirest::Logger.info "#{name} Username set to be #{value}"
value = CGI::escape(value) if value.present? && !value.include?("%")

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.

def base_url=(value)
Flexirest::Logger.info "#{name} Base URL set to be #{value}"
value = value.gsub(/\/+$/, '')
@@base_url = value

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.

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

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})

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})

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.

evaluation.evaluate
end

Coursemology::Evaluator.logger.info({event: 'Evaluation job completed', evaluation_id: evaluation.id})

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.

evaluation.evaluate
end

Coursemology::Evaluator.logger.info({event: 'Evaluation job completed', evaluation_id: evaluation.id})

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.

# @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})

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.

# @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})

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')
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.

@fonglh
Copy link
Member

fonglh commented Jan 16, 2017

Is it possible to make use of ActiveSupport::Notifications.instrument? Saw some of these calls in the code already.

@jeremyyap jeremyyap closed this Jan 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants