Class: Log4r::EvernoteOutputter

Inherits:
Outputter
  • Object
show all
Defined in:
lib/log4r/outputter/evernoteoutputter.rb

Instance Method Summary collapse

Constructor Details

#initialize(_name, hash = {}) ⇒ EvernoteOutputter

Returns a new instance of EvernoteOutputter.



13
14
15
16
# File 'lib/log4r/outputter/evernoteoutputter.rb', line 13

def initialize(_name, hash = {})
  super(_name, hash)
  validate(hash)
end

Instance Method Details

#canonical_log(logevent) ⇒ Object



44
# File 'lib/log4r/outputter/evernoteoutputter.rb', line 44

def canonical_log(logevent); super end

#syncObject

synchronize note



19
20
21
22
23
24
25
# File 'lib/log4r/outputter/evernoteoutputter.rb', line 19

def sync
  @note = @evernote.note(@notebook)
  @tag = @evernote.tag(@note)
  @tag.names = @tags
  set_maxsize(@hash) # for rolling
  set_shift_age(@hash) # for rolling
end

#validate(hash) ⇒ Object

validation of evernote parameters

Raises:

  • (ArgumentError)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/log4r/outputter/evernoteoutputter.rb', line 28

def validate(hash)
  is_sandbox = hash[:sandbox] || hash['sandbox'] || false
  raise ArgumentError, "Sandbox must be type of boolean" unless is_sandbox == false || is_sandbox == true
  @auth_token = hash[:auth_token] || hash['auth_token'] || ""
  raise ArgumentError, "Must specify from auth token" if @auth_token.empty?
  notebook_name = to_utf8(hash[:notebook] || hash['notebook'] || "")
  raise ArgumentError, "Must specify from notebook" if notebook_name.empty?
  stack_name = to_utf8(hash[:stack] || hash['stack'])
  @evernote = Log4ever::Evernote.new(@auth_token, is_sandbox)
  @tags = to_utf8(hash[:tags] || hash['tags'] || [])
  notebook = @evernote.notebook
  @notebook = notebook.get(notebook_name, stack_name)
  @hash = hash
  sync
end

#write(content) ⇒ Object

write log



47
48
49
50
51
52
53
54
# File 'lib/log4r/outputter/evernoteoutputter.rb', line 47

def write(content)
  sync
  if note_size_requires_roll? || time_requires_roll? || different_tag?
    create_log(content)
  else
    update_log(content)
  end
end