lib/log4r/outputter/evernoteoutputter.rb in log4ever-0.0.2 vs lib/log4r/outputter/evernoteoutputter.rb in log4ever-0.0.3

- old
+ new

@@ -43,43 +43,47 @@ end def canonical_log(logevent); super end def write(content) - @content = content if note_size_requires_roll? || time_requires_roll? - create_log + create_log(content) else - update_log + update_log(content) end end private - def create_log + # write log to note + def create_log(content) @note.clear @note.title = @name + " - " + Time.now.strftime("%Y-%m-%d %H:%M:%S") @note.tags = @tags - @note.content = @content + @note.content = content @note.create Logger.log_internal { "Create note: #{@note.guid}" } end - def update_log - @note.addContent(@content) + # update log in note + def update_log(content) + @note.addContent(content) + @note.tags = @tags @note.update Logger.log_internal { "Update note: #{@note.guid}" } end # 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 def time_requires_roll? !@endTime.nil? && Time.now.to_i >= @endTime end - + + # max amount of log in note def set_maxsize(options) if options.has_key?(:maxsize) || options.has_key?('maxsize') maxsize = options[:maxsize] || options['maxsize'] multiplier = 1 @@ -102,28 +106,12 @@ @maxsize = _maxsize else @maxsize = 0 end end - - def set_maxtime(options) - if options.has_key?(:maxtime) || options.has_key?('maxtime') - _maxtime = (options[:maxtime] or options['maxtime']).to_i - if _maxtime.class != Fixnum - raise TypeError, "Argument 'maxtime' must be an Fixnum", caller - end - if _maxtime == 0 - raise TypeError, "Argument 'maxtime' must be > 0", caller - end - @maxtime = _maxtime - @startTime = Time.now - else - @maxtime = 0 - @startTime = 0 - end - end + # rolling interval def set_shift_age(options) if options.has_key?(:shift_age) || options.has_key?('shift_age') _shift_age = (options[:shift_age] or options['shift_age']).to_i if _shift_age.class != Fixnum raise TypeError, "Argument 'shift_age' must be an Fixnum", caller @@ -131,10 +119,9 @@ 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 case _shift_age when Log4ever::ShiftAge::DAILY tomorrow = Time.local(now.tomorrow.year, now.tomorrow.month, now.tomorrow.day) @endTime = tomorrow.to_i \ No newline at end of file