forked from code4lib/ruby-oai
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogging.rb
More file actions
executable file
·69 lines (61 loc) · 2.19 KB
/
logging.rb
File metadata and controls
executable file
·69 lines (61 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Reopen Harvest and add logging
module OAI
module Harvester
class Harvest
alias_method :orig_start, :start
alias_method :orig_harvest, :harvest
alias_method :orig_call, :call
alias_method :orig_init, :initialize
def initialize(*args)
orig_init(*args)
@summary = []
@logger = Logger.new(File.join(@config.logfile, "harvester.log"),
shift_age = 'weekly') if @config.logfile
@logger.datetime_format = "%Y-%m-%d %H:%M"
# Turn off logging if no logging directory is specified.
@logger.level = Logger::FATAL unless @config.logfile
end
def start(sites = nil, interactive = false)
if not interactive
@logger.info { "Starting regular harvest" }
orig_start(sites)
begin
OAI::Harvester::Mailer.send(@config.mail_server, @config.email, @summary)
rescue
@logger.error { "Error sending out summary email: #{$!}"}
end
else
@logger.info { "Starting interactive harvest"}
orig_start(sites, true)
end
end
private
def harvest(site)
begin
@logger.info { "Harvest of '#{site}' starting" }
@summary << "Harvest of '#{site}' attempted"
orig_harvest(site)
rescue OAI::Exception
if "noRecordsMatch" == $!.code
@logger.info "No new records available"
@summary << "'#{site}' had no new records."
else
@logger.error { "Harvesting of '#{site}' failed, message: #{$!}" }
@summary << "'#{site}' had an OAI Error! #{$!}"
end
rescue
@logger.error { "Harvesting of '#{site}' failed, message: #{$!}" }
@logger.error { "#{$!.backtrace.join('\n')}" }
@summary << "'#{site}' had an Error! #{$!}"
end
end
def call(url, options)
@logger.info { "fetching: #{url} with options #{options.inspect}" }
file, records = orig_call(url, options)
@logger.info { "retrieved #{records} records" }
@summary << "Retrieved #{records} records."
return file, records
end
end
end
end