Skip to content

Commit ae9d15e

Browse files
committed
Refactor logging
1 parent ce78b99 commit ae9d15e

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

app/controllers/sword_controller.rb

+8-10
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,18 @@ def deposit
2222
@path_to_deposit_contents = Sword::Util::unzip_deposit_file request_body
2323

2424
# log basic essential info. Keep it terse! Gonna use :warn level, though not a warning.
25-
Rails.logger.warn("Received deposit POST. Collection slug: #{@collection_slug}, " \
26-
"Username: #{@depositor_user_id}, " \
27-
"Path to contents: #{@path_to_deposit_contents}"
28-
)
25+
helpers.log_received_deposit_post(@collection_slug,
26+
@depositor_user_id,
27+
@path_to_deposit_contents)
2928

3029
@endpoint.handle_deposit(@path_to_deposit_contents)
3130

3231
# log basic essential info. Keep it terse! Gonna use :warn level, though not a warning.
33-
Rails.logger.warn("Title: #{@endpoint.deposit_title.truncate_words(10)}, " \
34-
"Files: #{@endpoint.documents_to_deposit}, " \
35-
"Hyacinth item pid: #{@endpoint.adapter_item_identifier}, " \
36-
"Hyacinth asset pids: #{@endpoint.asset_pids}, " \
37-
"Path to SWORD contents: #{@path_to_deposit_contents}"
38-
)
32+
helpers.log_deposit_result_info(@endpoint.deposit_title.truncate_words(10),
33+
@endpoint.documents_to_deposit,
34+
@endpoint.adapter_item_identifier,
35+
@endpoint.asset_pids,
36+
@path_to_deposit_contents)
3937

4038
# create Deposit instance and store deposit info in database
4139
@deposit = helpers.create_deposit(@depositor_user_id,

app/helpers/logging_helper.rb

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module LoggingHelper
2+
def log_received_deposit_post(collection_slug,
3+
depositor_user_id,
4+
path_to_deposit_contents)
5+
Rails.logger.warn("Received deposit POST. Collection slug: #{collection_slug}, " \
6+
"Username: #{depositor_user_id}, " \
7+
"Path to contents: #{path_to_deposit_contents}")
8+
end
9+
def log_deposit_result_info(title,
10+
files,
11+
item_pid,
12+
asset_pids,
13+
path_content)
14+
Rails.logger.warn("Title: #{title}, " \
15+
"Files: #{files}, " \
16+
"Hyacinth item pid: #{item_pid}, " \
17+
"Hyacinth asset pids: #{asset_pids}, " \
18+
"Path to SWORD contents: #{path_content}"
19+
)
20+
end
21+
end

0 commit comments

Comments
 (0)