Improve logging

This commit is contained in:
Alex Ling 2021-09-14 07:16:14 +00:00
parent a151ec486d
commit 03e044a1aa

View File

@ -9,6 +9,7 @@ class Library
def save_instance def save_instance
path = Config.current.library_path path = Config.current.library_path
instance_file_path = File.join path, "library.yml.gz" instance_file_path = File.join path, "library.yml.gz"
Logger.debug "Caching library to #{instance_file_path}"
writer = Compress::Gzip::Writer.new instance_file_path, writer = Compress::Gzip::Writer.new instance_file_path,
Compress::Gzip::BEST_COMPRESSION Compress::Gzip::BEST_COMPRESSION
@ -22,21 +23,16 @@ class Library
instance_file_path = File.join dir, "library.yml.gz" instance_file_path = File.join dir, "library.yml.gz"
return unless File.exists? instance_file_path return unless File.exists? instance_file_path
Logger.debug "Load library instance" Logger.debug "Loading cached library from #{instance_file_path}"
is_loaded = false
begin begin
Compress::Gzip::Reader.open instance_file_path do |content| Compress::Gzip::Reader.open instance_file_path do |content|
@@default = Library.from_yaml content @@default = Library.from_yaml content
end end
is_loaded = true Library.default.register_jobs
rescue e rescue e
Logger.error e Logger.error e
end end
if is_loaded
Library.default.register_jobs
end
end end
def initialize def initialize
@ -64,7 +60,7 @@ class Library
start = Time.local start = Time.local
scan scan
ms = (Time.local - start).total_milliseconds ms = (Time.local - start).total_milliseconds
Logger.info "Scanned #{@title_ids.size} titles in #{ms}ms" Logger.debug "Library initialized in #{ms}ms"
sleep scan_interval.minutes sleep scan_interval.minutes
end end
end end
@ -171,11 +167,14 @@ class Library
storage.close storage.close
ms = (Time.local - start).total_milliseconds ms = (Time.local - start).total_milliseconds
Logger.debug "Scan completed. #{ms}ms" Logger.info "Scanned #{@title_ids.size} titles in #{ms}ms"
Storage.default.mark_unavailable Storage.default.mark_unavailable
spawn do
save_instance save_instance
end end
end
def get_continue_reading_entries(username) def get_continue_reading_entries(username)
cr_entries = deep_titles cr_entries = deep_titles