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

Instance Method Summary collapse

Class Attribute Details

.loggerObject



30
31
32
# File 'lib/pushmi_pullyu/logging.rb', line 30

def logger
  @logger ||= initialize_logger
end

Class Method Details

.initialize_logger(log_target = $stdout) ⇒ Object



24
25
26
27
28
# File 'lib/pushmi_pullyu/logging.rb', line 24

def initialize_logger(log_target = $stdout)
  @logger = Logger.new(log_target)
  @logger.level = Logger::INFO
  @logger
end

.log_aip_activity(aip_directory, message) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/pushmi_pullyu/logging.rb', line 34

def log_aip_activity(aip_directory, message)
  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(message)
  aip_logger.info(message)

  aip_logger.close
end

.log_preservation_event(deposited_file, aip_directory) ⇒ Object



46
47
48
49
50
51
52
53
54
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
# File 'lib/pushmi_pullyu/logging.rb', line 46

def log_preservation_event(deposited_file, aip_directory)
  preservation_logger = Logger.new("#{PushmiPullyu.options[:logdir]}/preservation_events.log")
  preservation_json_logger = Logger.new("#{PushmiPullyu.options[:logdir]}/preservation_events.json")

  message = "#{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?
    message << "\tFile Details:\n"
    file_details.each do |file_detail|
      message << %(\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

  # Log to both the application log, and the preservation log file
  logger.info(message)
  preservation_logger.info(message)

  preservation_logger.close

  message_json_str = preservation_event_to_json(deposited_file, aip_directory)
  preservation_json_logger.info("#{message_json_str},")
  preservation_json_logger.close
end

.preservation_event_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"


110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/pushmi_pullyu/logging.rb', line 110

def preservation_event_to_json(deposited_file, aip_directory)
  message = {}

  message['do_uuid'] = deposited_file.name.to_s
  message['aip_deposited_at'] = deposited_file.last_modified.to_s
  message['aip_md5sum'] = deposited_file.etag.to_s
  message['aip_sha256'] = ''
  message['aip_metadata'] = deposited_file..to_json.to_s

  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

  message['aip_file_details'] = tmp_details
  message.to_json
end

.reopenObject



137
138
139
140
141
142
143
# File 'lib/pushmi_pullyu/logging.rb', line 137

def reopen
  if @logger
    @logger.reopen
  else
    @logger = initialize_logger
  end
end

Instance Method Details

#loggerObject



16
17
18
# File 'lib/pushmi_pullyu/logging.rb', line 16

def logger
  PushmiPullyu::Logging.logger
end