Skip to content

Commit 3b3cb46

Browse files
committed
feat: write per-step processing logs to separate files
Each submission processing step now logs to both the main parsing.log and its own file under a new parsing_logs/ folder in the submission's data folder: parsed.log - RDF generation / parsing metadata.log - metadata extraction labels.log - missing labels generation obsolete.log - obsolete classes generation indexed.log - index all data / terms / properties (shared) metrics.log - metrics calculation diff.log - submission version diff A memoized step_logger helper in OntologyProcessor wraps the main logger and a per-file logger in a MultiLogger so every step broadcasts to both destinations. MultiLogger's broadcast methods are fixed to splat args (they previously logged messages as arrays). The parsing_logs/ folder is removed on archive.
1 parent f065870 commit 3b3cb46

4 files changed

Lines changed: 40 additions & 13 deletions

File tree

lib/ontologies_linked_data/models/ontology_submission.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,10 @@ def parsing_log_path
454454
return File.join(self.data_folder, 'parsing.log')
455455
end
456456

457+
def parsing_logs_folder
458+
return File.join(self.data_folder, 'parsing_logs')
459+
end
460+
457461
def triples_file_path
458462
self.bring(:uploadFilePath) if self.bring?(:uploadFilePath)
459463
self.bring(:masterFileName) if self.bring?(:masterFileName)

lib/ontologies_linked_data/services/submission_process/operations/submission_archiver.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Services
33
class OntologySubmissionArchiver < OntologySubmissionProcess
44

55
FILES_TO_DELETE = ['labels.ttl', 'mappings.ttl', 'obsolete.ttl', 'owlapi.xrdf', 'errors.log']
6-
FOLDERS_TO_DELETE = ['unzipped']
6+
FOLDERS_TO_DELETE = ['unzipped', 'parsing_logs']
77
FILE_SIZE_ZIPPING_THRESHOLD = 100 * 1024 * 1024 # 100MB
88

99
def process(force: false)

lib/ontologies_linked_data/services/submission_process/submission_processor.rb

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,30 @@ def process_submission(logger, options = {})
3434
@submission.archive
3535
else
3636

37-
@submission.generate_rdf(logger, reasoning: process_reasoning?(options)) if process_rdf?(options)
37+
@submission.generate_rdf(step_logger(logger, 'parsed.log'), reasoning: process_reasoning?(options)) if process_rdf?(options)
3838

3939
parsed = @submission.ready?(status: %i[rdf])
4040

41-
@submission = @submission.extract_metadata(logger, user_params: options[:params], heavy_extraction: extract_metadata?(options))
41+
@submission = @submission.extract_metadata(step_logger(logger, 'metadata.log'), user_params: options[:params], heavy_extraction: extract_metadata?(options))
4242

43-
@submission.generate_missing_labels(logger) if generate_missing_labels?(options)
43+
@submission.generate_missing_labels(step_logger(logger, 'labels.log')) if generate_missing_labels?(options)
4444

45-
@submission.generate_obsolete_classes(logger) if generate_obsolete_classes?(options)
45+
@submission.generate_obsolete_classes(step_logger(logger, 'obsolete.log')) if generate_obsolete_classes?(options)
4646

4747
if !parsed && (index_search?(options) || index_properties?(options) || index_all_data?(options))
4848
raise StandardError, "The submission #{@submission.ontology.acronym}/submissions/#{@submission.submissionId}
4949
cannot be indexed because it has not been successfully parsed"
5050
end
5151

52-
@submission.index_all(logger, commit: process_index_commit?(options)) if index_all_data?(options)
52+
@submission.index_all(step_logger(logger, 'indexed.log'), commit: process_index_commit?(options)) if index_all_data?(options)
5353

54-
@submission.index_terms(logger, commit: process_index_commit?(options)) if index_search?(options)
54+
@submission.index_terms(step_logger(logger, 'indexed.log'), commit: process_index_commit?(options)) if index_search?(options)
5555

56-
@submission.index_properties(logger, commit: process_index_commit?(options)) if index_properties?(options)
56+
@submission.index_properties(step_logger(logger, 'indexed.log'), commit: process_index_commit?(options)) if index_properties?(options)
5757

58-
@submission.generate_metrics(logger) if process_metrics?(options)
58+
@submission.generate_metrics(step_logger(logger, 'metrics.log')) if process_metrics?(options)
5959

60-
@submission.generate_diff(logger) if process_diff?(options)
60+
@submission.generate_diff(step_logger(logger, 'diff.log')) if process_diff?(options)
6161
end
6262
@submission.save
6363
logger.info("Submission processing of #{@submission.id} completed successfully")
@@ -75,6 +75,19 @@ def notify_submission_processed(logger)
7575
logger.error("Email sending failed: #{e.message}\n#{e.backtrace.join("\n\t")}"); logger.flush
7676
end
7777

78+
# Build a logger for a processing step that writes both to the main log
79+
# (the one passed into #process) and to a step-specific file located in the
80+
# submission's parsing_logs folder. Loggers are memoized per file name so
81+
# steps sharing a file (e.g. the indexers) append to the same handle.
82+
def step_logger(main_logger, filename)
83+
@step_loggers ||= {}
84+
@step_loggers[filename] ||= begin
85+
FileUtils.mkdir_p(@submission.parsing_logs_folder)
86+
file_logger = Logger.new(File.join(@submission.parsing_logs_folder, filename))
87+
LinkedData::Utils::MultiLogger.new(loggers: [main_logger, file_logger])
88+
end
89+
end
90+
7891
def process_archive?(options)
7992
options[:archive].eql?(true)
8093
end

lib/ontologies_linked_data/utils/multi_logger.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,18 @@
22

33
module LinkedData::Utils
44
class MultiLogger < OmniLogger
5-
def flush()
6-
@loggers.each { |logger| logger.flush }
5+
def flush
6+
@loggers.each(&:flush)
7+
end
8+
9+
# OmniLogger's generated level methods broadcast with `logger.send(level, args)`,
10+
# passing the args as a single array (so `info("msg")` logs `["msg"]`). Redefine
11+
# them here to splat the args and forward the block to each underlying logger.
12+
Logger::Severity.constants.each do |level|
13+
name = level.downcase
14+
define_method(name) do |*args, &block|
15+
@loggers.each { |logger| logger.send(name, *args, &block) }
16+
end
717
end
818
end
9-
end
19+
end

0 commit comments

Comments
 (0)