lib/log4r/outputter/evernoteoutputter.rb in log4ever-0.1.0 vs lib/log4r/outputter/evernoteoutputter.rb in log4ever-0.1.1
- old
+ new
@@ -14,11 +14,13 @@
validate(hash)
end
# synchronize note
def sync
- @note = @evernote.get_note(@notebook)
+ @note = @evernote.note(@notebook)
+ @tag = @evernote.tag(@note)
+ @tag.names = @tags
set_maxsize(@hash) # for rolling
set_shift_age(@hash) # for rolling
end
# validation of evernote parameters
@@ -28,24 +30,24 @@
@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'] || ""
raise ArgumentError, "Must specify from notebook" if notebook_name.empty?
stack_name = hash[:stack] || hash['stack']
- @evernote = MyEvernote.new(is_sandbox, @auth_token)
- tags = @evernote.get_tags(hash[:tags] || hash['tags'] || [])
- @tags = tags.map{|tag_obj| tag_obj.guid}
- @notebook = @evernote.get_notebook(notebook_name, stack_name)
+ @evernote = Log4ever::Evernote.new(@auth_token, is_sandbox)
+ @tags = hash[:tags] || hash['tags'] || []
+ notebook = @evernote.notebook
+ @notebook = notebook.get(notebook_name, stack_name)
@hash = hash
sync
end
def canonical_log(logevent); super end
# write log
def write(content)
sync
- if note_size_requires_roll? || time_requires_roll?
+ if note_size_requires_roll? || time_requires_roll? || different_tag?
create_log(content)
else
update_log(content)
end
end
@@ -53,20 +55,20 @@
private
# 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.tags = @tag.get
@note.content = content
@note.create
Logger.log_internal { "Create note: #{@note.guid}" }
end
# update log in note
def update_log(content)
@note.addContent(content)
- @note.tags = @tags
+ @note.tags = @tag.get
@note.update
Logger.log_internal { "Update note: #{@note.guid}" }
end
# more expensive, only for startup
@@ -76,10 +78,17 @@
# whether or not to rotate
def time_requires_roll?
!@endTime.nil? && Time.now.to_i >= @endTime
end
+
+ # diff note's tag and register tag
+ def different_tag?
+ note_tags = @note.tags || []
+ tag = @tag.get || []
+ (note_tags - tag).size != 0 || (tag - note_tags).size != 0
+ 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']
@@ -135,7 +144,6 @@
end
end
end
end
end
-
end
\ No newline at end of file