Refactor logging across controllers and jobs to use a centralized log method; improve consistency and readability of log messages

This commit is contained in:
2026-02-27 22:32:07 -05:00
parent f32b48296d
commit 9c0f153518
10 changed files with 107 additions and 31 deletions

View File

@@ -17,12 +17,12 @@ module RedmineQbo
# Edit Issue Form
# Here we build the required form components before passing them to a partial view formatting.
def view_issues_form_details_bottom(context={})
Rails.logger.debug "RedmineQbo::Hooks::IssuesHookListener.view_issues_form_details_bottom: Building form components for quickbooks customer, estimate, and invoice data"
log "view_issues_form_details_bottom: Building form components for quickbooks customer, estimate, and invoice data"
f = context[:form]
issue = context[:issue]
project = context[:project]
Rails.logger.debug issue.inspect
Rails.logger.debug project.inspect
log issue.inspect
log project.inspect
# Customer Name Text Box with database backed autocomplete
# onchange event will update the hidden customer_id field
@@ -44,7 +44,7 @@ module RedmineQbo
#
# If this is not handled correctly, it leads to a 422 error when creating a new issue and selecting a customer.
js_path = "updateIssueFrom('#{escape_javascript update_issue_form_path(project, issue)}', this)"
Rails.logger.debug js_path
log js_path
# This hidden field is used for the customer ID for the issue
# the onchange event will reload the issue form via ajax to update the available estimates
@@ -93,6 +93,12 @@ module RedmineQbo
}
})
end
private
def log(msg)
Rails.logger.info "[IssuesHookListener] #{msg}"
end
end
end

View File

@@ -27,6 +27,7 @@ module RedmineQbo
before_save :titlize_subject
after_commit :enqueue_billing, on: :update
end
end
module ClassMethods
@@ -35,20 +36,22 @@ module RedmineQbo
module InstanceMethods
# Enqueue a background job to bill the time spent on this issue to the associated customer in Quickbooks, if the issue is closed and has a customer assigned.
def enqueue_billing
Rails.logger.debug "QBO: Checking if issue needs to be billed for issue ##{id}"
log "Checking if issue needs to be billed for issue ##{id}"
#return unless saved_change_to_status_id?
return unless closed?
return unless customer.present?
return unless assigned_to&.employee_id.present?
return unless Qbo.first
Rails.logger.debug "QBO: Enqueuing billing for issue ##{id}"
log "Enqueuing billing for issue ##{id}"
BillIssueTimeJob.perform_later(id)
end
# Titlize the subject of the issue before saving to ensure consistent formatting for billing descriptions in Quickbooks
def titlize_subject
Rails.logger.debug "QBO: Titlizing subject for issue ##{id}"
log "Titlizing subject for issue ##{id}"
self.subject = subject.split(/\s+/).map do |word|
if word =~ /[A-Z]/ && word =~ /[0-9]/
@@ -60,9 +63,16 @@ module RedmineQbo
end
end
# This method is used to generate a shareable token for the customer associated with this issue, which can be used to link the issue to the corresponding customer in Quickbooks for billing and tracking purposes.
def share_token
CustomerToken.get_token(self)
end
private
def log(msg)
Rails.logger.info "[IssuePatch] #{msg}"
end
end
Issue.send(:include, IssuePatch)