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
# 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")

  message = "#{deposited_file.name} was successfully deposited into Swift Storage!\n"\
  "Here are the details of this preservation event:\n"\
  "\tNOID: '#{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
end

.reopenObject


77
78
79
80
81
82
83
# File 'lib/pushmi_pullyu/logging.rb', line 77

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