lib/log4r/outputter/evernoteoutputter.rb in log4ever-0.0.4 vs lib/log4r/outputter/evernoteoutputter.rb in log4ever-0.0.5

- old
+ new

@@ -16,36 +16,35 @@ validate(hash) end # validation of evernote parameters def validate(hash) - set_maxsize(hash) # for rolling - set_shift_age(hash) # for roling - env = hash[:env] || hash['env'] || 'sandbox' if env == 'sandbox' @env = "https://#{SANDBOX_HOST}/edam/user" elsif env == 'production' @env = "https://#{PRODUCTION_HOST}/edam/user" else raise ArgumentError, "Must specify from env 'sandbox' or 'production'" end @auth_token = hash[:auth_token] || hash['auth_token'] || "" raise ArgumentError, "Must specify from auth token" if @auth_token.empty? + notebook_name = hash[:notebook] || hash['notebook'] || "" + stack_name = hash[:stack] || hash['stack'] + raise ArgumentError, "Must specify from notebook" if @notebook_name.empty? @evernote = MyEvernote.new(@env, @auth_token) - notebook = hash[:notebook] || hash['notebook'] || "" - raise ArgumentError, "Must specify from notebook" if notebook.empty? tags = @evernote.get_tags(hash[:tags] || hash['tags'] || []) - stack = hash[:stack] || hash['stack'] - @evernote = MyEvernote.new(@env, @auth_token) - @notebook = @evernote.get_notebook(notebook, stack) - @note = @evernote.get_note(@notebook) + notebook = @evernote.get_notebook(notebook_name, stack_name) + @note = @evernote.get_note(notebook) @tags = tags.map{|tag_obj| tag_obj.guid} + set_maxsize(hash) # for rolling + set_shift_age(hash) # for rolling end def canonical_log(logevent); super end + # write log def write(content) if note_size_requires_roll? || time_requires_roll? create_log(content) else update_log(content) @@ -74,11 +73,11 @@ # more expensive, only for startup def note_size_requires_roll? @note.size == 0 || (@maxsize > 0 && @note.size >= @maxsize) end - # whether or not to rotate rolling + # whether or not to rotate def time_requires_roll? !@endTime.nil? && Time.now.to_i >= @endTime end # max amount of log in note @@ -119,19 +118,19 @@ unless _shift_age.nil? unless [Log4ever::ShiftAge::DAILY, Log4ever::ShiftAge::WEEKLY, Log4ever::ShiftAge::MONTHLY].include? _shift_age raise TypeError, "Argument 'shift_age' must be > 0", caller end - now = Time.now + created_at = @note.created_at case _shift_age when Log4ever::ShiftAge::DAILY - tomorrow = Time.local(now.tomorrow.year, now.tomorrow.month, now.tomorrow.day) + tomorrow = Time.local(created_at.tomorrow.year, created_at.tomorrow.month, created_at.tomorrow.day) @endTime = tomorrow.to_i when Log4ever::ShiftAge::WEEKLY - next_week = Time.local(now.next_week.year, now.next_week.month, now.next_week.day) + next_week = Time.local(created_at.next_week.year, created_at.next_week.month, created_at.next_week.day) @endTime = next_week.to_i when Log4ever::ShiftAge::MONTHLY - next_month = Time.local(now.next_month.year, now.next_month.month, now.next_month.day) + next_month = Time.local(created_at.next_month.year, created_at.next_month.month, created_at.next_month.day) @endTime = next_month.to_i else raise TypeError, "Argument 'shift_age' must be '1' or '2' or '3'", caller end end \ No newline at end of file