Skip to content
This repository has been archived by the owner on Sep 17, 2019. It is now read-only.

Commit

Permalink
Improves sync-logging.
Browse files Browse the repository at this point in the history
Books and Notes both use sync.log now.
  • Loading branch information
joegatt committed Jun 29, 2013
1 parent a8f59cc commit 1078b3a
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 26 deletions.
10 changes: 8 additions & 2 deletions app/helpers/evernote_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ def user_nickname
evernote_auth.nickname
end

def error_details
{ provider: 'Evernote', guid: cloud_note_metadata.guid, title: cloud_note_metadata.title, username: user_nickname }
def logger_details
{
provider: 'Evernote',
guid: cloud_note_metadata.guid,
title: cloud_note_metadata.title,
username: user_nickname,
id: evernote_note.id
}
end
end
2 changes: 1 addition & 1 deletion app/mailers/book_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def metadata_missing(book)

mail(
:to => Settings.monitoring.email,
:subject => I18n.t('books.sync.failed.metadata_missing.email.subject',
:subject => I18n.t('books.sync.metadata_missing.email.subject',
isbn: @isbn, details: "#{ @author } | #{ @title } | #{ @published_date }"),
:host => Settings.host
)
Expand Down
6 changes: 5 additions & 1 deletion app/models/book.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ def populate!
merge(GoogleBooksRequest.new(isbn).metadata) if Settings.books.google_books.active?
merge(OpenLibraryRequest.new(isbn).metadata) if Settings.books.open_library.active?
undirtify(false) unless metadata_missing?
BookMailer.metadata_missing(self).deliver if (metadata_missing? || attempts == Settings.notes.attempts)
SYNC_LOG.info I18n.t('books.sync.updated', id: id, author: author, title: title, isbn: isbn)
if metadata_missing? && attempts == Settings.notes.attempts
BookMailer.metadata_missing(self).deliver
SYNC_LOG.error I18n.t('books.sync.metadata_missing.logger', id: id, author: author, title: title, isbn: isbn)
end
save!
end

Expand Down
14 changes: 7 additions & 7 deletions app/models/evernote_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def initialize(evernote_note, offline = false)

rescue Evernote::EDAM::Error => error
max_out_attempts
SYNC_LOG.info I18n.t("#{ error.identifier }: #{ error.key }.", error_details)
SYNC_LOG.info I18n.t('notes.sync.updated', logger_details)
end

private
Expand All @@ -40,7 +40,7 @@ def update_note
evernote_note.note.save!
evernote_note.note.update_resources_with_evernote_data(cloud_note_data)
evernote_note.update_with_data_from_cloud(cloud_note_data)
SYNC_LOG.info "#{ error_details[:title] } saved as Note #{ (evernote_note.note.id) }."
SYNC_LOG.info "#{ logger_details[:title] } saved as Note #{ (evernote_note.note.id) }."
end

def update_necessary_according_to_note?
Expand All @@ -53,7 +53,7 @@ def evernote_notebook_required?
result = Settings.evernote.notebooks.include?(cloud_note_metadata.notebookGuid)
unless result
evernote_note.destroy
SYNC_LOG.info I18n.t('notes.sync.rejected.not_in_notebook', error_details)
SYNC_LOG.info I18n.t('notes.sync.rejected.not_in_notebook', logger_details)
end
result
end
Expand All @@ -62,7 +62,7 @@ def cloud_note_active?
result = cloud_note_metadata.active
unless result
evernote_note.destroy
SYNC_LOG.info I18n.t('notes.sync.rejected.deleted_note', error_details)
SYNC_LOG.info I18n.t('notes.sync.rejected.deleted_note', logger_details)
end
result
end
Expand All @@ -71,7 +71,7 @@ def cloud_note_updated?
result = evernote_note.update_sequence_number.nil? || (evernote_note.update_sequence_number < cloud_note_metadata.updateSequenceNum)
unless result
evernote_note.undirtify
SYNC_LOG.info I18n.t('notes.sync.rejected.not_latest', error_details)
SYNC_LOG.info I18n.t('notes.sync.rejected.not_latest', logger_details)
end
result
end
Expand All @@ -85,15 +85,15 @@ def cloud_note_has_required_tags?
result = !(Array(Settings.notes.instructions.required) & cloud_note_tags).empty?
unless result
evernote_note.destroy
SYNC_LOG.info I18n.t('notes.sync.rejected.tag_missing', error_details)
SYNC_LOG.info I18n.t('notes.sync.rejected.tag_missing', logger_details)
end
result
end

def cloud_note_is_not_ignorable?
result = (Settings.notes.instructions.ignore & cloud_note_tags).empty?
unless result
SYNC_LOG.info I18n.t('notes.sync.rejected.ignore', error_details)
SYNC_LOG.info I18n.t('notes.sync.rejected.ignore', logger_details)
evernote_note.undirtify
end
result
Expand Down
2 changes: 1 addition & 1 deletion app/models/google_books_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize(isbn)
populate(response, isbn) if response && response['items'].first['volumeInfo']

rescue
Rails.logger.error I18n.t('books.sync.failed.logger', provider: 'GoogleBooks', isbn: isbn)
SYNC_LOG.error I18n.t('books.sync.failed.logger', provider: 'GoogleBooks', isbn: isbn)
end

def populate(response, isbn)
Expand Down
2 changes: 1 addition & 1 deletion app/models/isbndb_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def initialize(isbn)
populate(response) if response && response['data']

rescue
Rails.logger.error I18n.t('books.sync.failed.logger', provider: 'Isbndb', isbn: isbn)
SYNC_LOG.error I18n.t('books.sync.failed.logger', provider: 'Isbndb', isbn: isbn)
end

def populate(response)
Expand Down
2 changes: 1 addition & 1 deletion app/models/open_library_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize(isbn)
populate(response, isbn) if response && response["ISBN:#{ isbn }"]['details']

rescue
Rails.logger.error I18n.t('books.sync.failed.logger', provider: 'OpenLibrary', isbn: isbn)
SYNC_LOG.error I18n.t('books.sync.failed.logger', provider: 'OpenLibrary', isbn: isbn)
end

def populate(response, isbn)
Expand Down
2 changes: 1 addition & 1 deletion app/models/world_cat_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def initialize(isbn)
populate(response, isbn) if response && response['oclcdcs']

rescue
Rails.logger.error I18n.t('books.sync.failed.logger', provider: 'WorldCat', isbn: isbn)
SYNC_LOG.error I18n.t('books.sync.failed.logger', provider: 'WorldCat', isbn: isbn)
end

def populate(response, isbn)
Expand Down
24 changes: 13 additions & 11 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ en:
full: "Note %{id} v%{sequence}"
untitled_synonyms: ["Untitled", "Untitled note", "New note"]
sync:
updated: "%{provider}: note %{guid} (%{title}) updated."
updated: "%{provider}: note %{id} (%{title}) UPDATED."
rejected:
version_not_ok: "%{provider}: note %{guid} (%{title}) for user %{username} failed! The SDK is out of date."
version_not_ok: "%{provider}: note %{guid} failed! The SDK is out of date."
not_authenticated: "%{provider}: note %{guid} rejected! Your %{provider} API key is not authenticated."
not_in_notebook: "%{provider}: note %{guid} for user %{username} rejected! Not in required notebook."
deleted_note: "%{provider}: note %{guid} for user %{username} rejected! Note has been deleted from cloud notebook."
tag_missing: "%{provider}: note %{guid} (%{title}) for user %{username} rejected! Missing required tag."
ignore: "%{provider}: note %{guid} (%{title}) for user %{username} rejected! Contains instructions to ignore."
not_latest: "%{provider}: note %{guid} (%{title}) for user %{username} rejected! Already have latest version."
not_in_notebook: "%{provider}: note %{guid} rejected! Not in required notebook."
deleted_note: "%{provider}: note %{guid} rejected! Note has been deleted from cloud notebook."
tag_missing: "%{provider}: note %{guid} (%{title}) rejected! Missing required tag."
ignore: "%{provider}: note %{guid} (%{title}) rejected! Contains instructions to ignore."
not_latest: "%{provider}: note %{guid} (%{title}) rejected! Already have latest version."
update_error: "%{provider}: note %{guid} failed on database update!"
failed:
logger: "%{provider}: note %{guid} (%{title}) failed on database update!"
Expand All @@ -64,12 +64,14 @@ en:
short: "%{name}"
editor_short: "(ed.)"
sync:
updated: "%{author}: %{title} ISBN %{isbn} UPDATED."
failed:
logger: "Sync failed while fetching metadata from %{provider} for ISBN %{isbn}."
metadata_missing:
email:
subject: "Missing Book metadata: ISBN %{isbn} | %{details}"
body: "The following book has been added to your bibliography, but it has missing metadata so it can't be referenced:"
metadata_missing:
logger: "Book %{id} - %{author}: %{title} ISBN %{isbn} - metadata missing!"
email:
subject: "Missing Book metadata: ISBN %{isbn} | %{details}"
body: "The following book has been added to your bibliography, but it has missing metadata so it can't be referenced:"

citations:
index:
Expand Down

0 comments on commit 1078b3a

Please sign in to comment.