Module: PushmiPullyu::Logging
- Included in:
- CLI
- Defined in:
- lib/pushmi_pullyu/logging.rb
Overview
PushmiPullyu::Logging is a standard Ruby logger wrapper
Defined Under Namespace
Classes: SimpleFormatter
Class Attribute Summary collapse
Class Method Summary collapse
- .initialize_loggers(log_target: $stdout, events_target: $stdout, json_target: $stdout) ⇒ Object
- .log_aip_activity(aip_directory, message) ⇒ Object
- .log_preservation_attempt(entity, try_attempt) ⇒ Object
- .log_preservation_event(message, message_json) ⇒ Object
- .log_preservation_fail_and_retry(entity, try_attempt, exception) ⇒ Object
- .log_preservation_failure(entity, try_attempt, exception) ⇒ Object
- .log_preservation_success(entity, deposited_file, aip_directory) ⇒ Object
-
.preservation_success_to_json(deposited_file, aip_directory) ⇒ Object
Provides an alternative logging method in json format for the convenience of parsing in the process of auditing against OpenStack Swift preservation.
- .reopen ⇒ Object
Instance Method Summary collapse
Class Attribute Details
.logger ⇒ Object
33 34 35 |
# File 'lib/pushmi_pullyu/logging.rb', line 33 def logger @logger ||= initialize_loggers end |
Class Method Details
.initialize_loggers(log_target: $stdout, events_target: $stdout, json_target: $stdout) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/pushmi_pullyu/logging.rb', line 24 def initialize_loggers(log_target: $stdout, events_target: $stdout, json_target: $stdout) @preservation_logger = Logger.new(events_target) @preservation_json_logger = Logger.new(json_target) @logger = Logger.new(log_target) @logger.level = Logger::INFO @logger end |
.log_aip_activity(aip_directory, message) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/pushmi_pullyu/logging.rb', line 37 def log_aip_activity(aip_directory, ) log_file = "#{aip_directory}/data/logs/aipcreation.log" aip_logger = Logger.new(log_file) aip_logger.level = logger.level # Log to both the application log, and the log file that gets archived in the AIP logger.info() aip_logger.info() aip_logger.close end |
.log_preservation_attempt(entity, try_attempt) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/pushmi_pullyu/logging.rb', line 130 def log_preservation_attempt(entity, try_attempt) # We add + 1 to try_attempt because humans like to start counting from 1 try_attempt += 1 = "#{entity[:type]} will attempt to be deposited.\n" \ "Here are the details of this preservation event:\n" \ "\t#{entity[:type]} uuid: #{entity[:uuid]}" \ "\tTry attempt: #{try_attempt}\n" = { event_type: :attempt, event_time: Time.now.to_s, entity_type: entity[:type], entity_uuid: entity[:uuid], try_attempt: try_attempt } log_preservation_event(, .to_json) end |
.log_preservation_event(message, message_json) ⇒ Object
49 50 51 52 53 |
# File 'lib/pushmi_pullyu/logging.rb', line 49 def log_preservation_event(, ) logger.info() @preservation_logger.info() @preservation_json_logger.info("#{},") end |
.log_preservation_fail_and_retry(entity, try_attempt, exception) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/pushmi_pullyu/logging.rb', line 88 def log_preservation_fail_and_retry(entity, try_attempt, exception) # We add + 1 to try_attempt because humans like to start counting from 1 try_attempt += 1 = "#{entity[:type]} failed to be deposited and will try again.\n" \ "Here are the details of this preservation event:\n" \ "\t#{entity[:type]} uuid: #{entity[:uuid]}" \ "\tReadding to preservation queue with try attempt: #{try_attempt}\n" \ "\tError of type: #{exception.class.name}\n" \ "\tError message: #{exception.}\n" = { event_type: :fail_and_retry, event_time: Time.now.to_s, entity_type: entity[:type], entity_uuid: entity[:uuid], try_attempt: try_attempt, error_message: exception. } log_preservation_event(, .to_json) end |
.log_preservation_failure(entity, try_attempt, exception) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/pushmi_pullyu/logging.rb', line 110 def log_preservation_failure(entity, try_attempt, exception) # We add + 1 to try_attempt because humans like to start counting from 1 try_attempt += 1 = "#{entity[:type]} failed to be deposited.\n" \ "Here are the details of this preservation event:\n" \ "\t#{entity[:type]} uuid: #{entity[:uuid]}" \ "\tTry attempt: #{try_attempt}\n" = { event_type: :failure, event_time: Time.now.to_s, entity_type: entity[:type], entity_uuid: entity[:uuid], try_attempt: try_attempt, error_message: exception. } log_preservation_event(, .to_json) end |
.log_preservation_success(entity, deposited_file, aip_directory) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/pushmi_pullyu/logging.rb', line 55 def log_preservation_success(entity, deposited_file, aip_directory) = "#{deposited_file.name} was successfully deposited into Swift Storage!\n" \ "Here are the details of this preservation event:\n" \ "\tUUID: '#{deposited_file.name}'\n" \ "\tTimestamp of Completion: '#{deposited_file.last_modified}'\n" \ "\tAIP Checksum: '#{deposited_file.etag}'\n" \ "\tMetadata: #{deposited_file.}\n" \ file_details = file_log_details(aip_directory) if file_details.present? << "\tFile Details:\n" file_details.each do |file_detail| << %(\t\t{"fileset_uuid": "#{file_detail[:fileset_name]}", \t\t"details": { \t\t\t"file_name": "#{file_detail[:file_name]}", \t\t\t"file_type": "#{file_detail[:file_extension]}", \t\t\t"file_size": #{file_detail[:file_size]} \t\t}}\n) end end = { event_type: :success, event_time: Time.now.to_s, entity_type: entity[:type], entity_uuid: entity[:uuid], event_details: preservation_success_to_json(deposited_file, aip_directory) } log_preservation_event(, .to_json) end |
.preservation_success_to_json(deposited_file, aip_directory) ⇒ Object
Provides an alternative logging method in json format for the convenience of parsing in the process of auditing against OpenStack Swift preservation.
output format:
I, [2022-04-06T11:07:21.983875 #20791] INFO -- : \
"do_uuid": "83b5d21f-a60a-43ba-945a-f03deec64a1d",
"aip_deposited_at": "Thu, 07 Apr 2022 16:37:00 GMT",
"aip_md5sum": "fe5832a510799b04c1c503e46dc3b589",
"aip_sha256": "",
"aip_metadata": "{\"project-id\":\"83b5d21f-a60a-43ba-945a-f03deec64a1d\",
\"aip-version\":\"1.0\",
\"project\":\"ERA\",
\"promise\":\"bronze\"",
"aip_file_details": [
{
"fileset_uuid": "b2c6ac0f-f2ed-489e-bbae-bd26465207aa",
"file_name": "Spallacci_Amanda_202103_PhD.pdf",
"file_type": "pdf",
"file_size": "2051363"
}
]
}
note:
to parse, the prefix "I, ... INFO --:" in each line needs to be
stripped using a bash command such as "sed"
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/pushmi_pullyu/logging.rb', line 177 def preservation_success_to_json(deposited_file, aip_directory) = {} ['do_uuid'] = deposited_file.name.to_s ['aip_deposited_at'] = deposited_file.last_modified.to_s ['aip_md5sum'] = deposited_file.etag.to_s ['aip_sha256'] = '' ['aip_metadata'] = deposited_file. file_details = file_log_details(aip_directory) tmp_details = [] if file_details.present? file_details.each do |file_detail| tmp_hash = {} tmp_hash['fileset_uuid'] = file_detail[:fileset_name].to_s tmp_hash['file_name'] = file_detail[:file_name].to_s tmp_hash['file_type'] = file_detail[:file_extension].to_s tmp_hash['file_size'] = file_detail[:file_size].to_s tmp_details << tmp_hash end end ['aip_file_details'] = tmp_details end |
.reopen ⇒ Object
204 205 206 207 208 209 210 |
# File 'lib/pushmi_pullyu/logging.rb', line 204 def reopen if @logger @logger.reopen else @logger = initialize_loggers end end |
Instance Method Details
#logger ⇒ Object
16 17 18 |
# File 'lib/pushmi_pullyu/logging.rb', line 16 def logger PushmiPullyu::Logging.logger end |