log4ever 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e1d08242eefdcd15ca81557ddf95daa8ee7fef2a
4
- data.tar.gz: e4d0d198403e78215622fc67b116d925d4f421e6
3
+ metadata.gz: 45ccb7dce4c1abba539b3fed3173d955ff910090
4
+ data.tar.gz: 535bc6d931b3934a4558d7a76dd9cecdec8dd5e2
5
5
  SHA512:
6
- metadata.gz: 874d33d73d14c566a07ce1d6529de7b47616f9e0b4d62fa507d1de2770ce95fe4ed16dd5c5aa6ca5686c067f35013eac4b835e8a448ff188be59b061f277209f
7
- data.tar.gz: 92858b9c5d65b9bf2d9e45cf561426131460c5dd946a1b1352f4e7b9eb026346790ac61b7674f226559f43ac86ddbf2c177f93b4727afbb8605a378a98a43ab6
6
+ metadata.gz: 445d7adcc42c86df9583c9fda61ac7dd69ca6c497415a11d246df6337e0d82bd238c96af5e54250de802b29e2788d59c0edd89a008c12b4386b3d56dfa0be566
7
+ data.tar.gz: 8d1acff1092c8dbf5643ffb262ab7bd74a052dad4d1f914e58e6bf0e4db8014095212953e49fcdbd99fefc99f3d4deeaad49e3c30f1f9b48fce907ab68bb3473
data/README.md CHANGED
@@ -66,6 +66,8 @@ Bug fix.
66
66
  Ruby2.0.0 support. Bug fix.
67
67
  * 0.1.4
68
68
  Add testcase.
69
+ * 0.1.5
70
+ Performance improvement.
69
71
 
70
72
  ##License
71
73
  Licensed under the MIT
@@ -3,7 +3,7 @@ require 'log4r/outputter/evernoteoutputter'
3
3
  require 'evernote_oauth'
4
4
 
5
5
  module Log4ever
6
- VERSION = '0.1.4'
6
+ VERSION = '0.1.5'
7
7
 
8
8
  class EvernoteError < StandardError; end
9
9
 
@@ -39,17 +39,20 @@ module Log4ever
39
39
  # get registered notebook or create new notebook
40
40
  # search the notebook under the stack if stack_name specific
41
41
  def notebook
42
- Notebook.new(@@auth_store)
42
+ @notebook = Notebook.new(@@auth_store) if @notebook.nil?
43
+ @notebook
43
44
  end
44
45
 
45
46
  # get registered note or create new note
46
47
  def note(notebook)
47
- Note.new(notebook, @@auth_store)
48
+ @note = Note.new(notebook, @@auth_store) if @note.nil?
49
+ @note
48
50
  end
49
51
 
50
52
  # get registered tag or create new tag
51
53
  def tag(note)
52
- Tag.new(note, @@auth_store)
54
+ @tag = Tag.new(note, @@auth_store) if @tag.nil?
55
+ @tag
53
56
  end
54
57
  end
55
58
 
@@ -76,14 +79,7 @@ module Log4ever
76
79
  end
77
80
  end
78
81
  # create new notebook if notebook is nil
79
- create(notebook_name, stack_name) if @notebook.nil?
80
- @notebook
81
- end
82
-
83
- # get newest notebook
84
- def get!(notebook_name, stack_name = nil)
85
- clear
86
- get(notebook_name, stack_name)
82
+ @notebook || create(notebook_name, stack_name)
87
83
  end
88
84
 
89
85
  # create notebook
@@ -112,23 +108,21 @@ module Log4ever
112
108
  end
113
109
 
114
110
  class Note
115
- XML_TEMPLATE_BYTE = 237
116
-
117
111
  def initialize(notebook, auth_store)
118
112
  return unless @params.nil? || @params.empty?
119
113
  @params = {}
120
- @auth_store = auth_store
121
- @notebook = notebook
122
- if !@notebook.kind_of? ::Evernote::EDAM::Type::Notebook
123
- raise EvernoteError, "Expected kind of Notebook, got #{@notebook.class}", caller
124
- elsif !@notebook.respond_to? 'guid'
125
- raise NoMethodError, "#{@notebook.class} do not has method: guid", caller
114
+ if !notebook.kind_of? ::Evernote::EDAM::Type::Notebook
115
+ raise EvernoteError, "Expected kind of Notebook, got #{notebook.class}", caller
116
+ elsif !notebook.respond_to? 'guid'
117
+ raise NoMethodError, "#{notebook.class} do not has method: guid", caller
126
118
  end
119
+ @notebook = notebook
120
+ @auth_store = auth_store
127
121
  end
128
122
 
129
123
  # content size
130
124
  def size
131
- content.bytesize > 0 ? content.bytesize - XML_TEMPLATE_BYTE : 0
125
+ content.bytesize
132
126
  end
133
127
 
134
128
  # note guid
@@ -164,10 +158,22 @@ module Log4ever
164
158
  "<div style=\"font-family: Courier New\">" + text + "</div></en-note>"
165
159
  end
166
160
 
161
+ # get note content text
162
+ def content
163
+ return @content_ unless @content_.nil?
164
+ @note.nil? and get
165
+ @content_ = !@note.nil? && !@note.guid.nil? ? @auth_store.note_store.getNoteContent(@auth_store.auth_token, @note.guid) : ""
166
+ end
167
+
168
+ # get note content xml object
169
+ def content_xml
170
+ return @content_xml unless @content_xml.nil?
171
+ @content_xml = Nokogiri::XML(content)
172
+ end
173
+
167
174
  # create note
168
175
  def create
169
176
  @auth_store.note_store.createNote(@auth_store.auth_token, createNote)
170
- clear
171
177
  end
172
178
 
173
179
  # update note
@@ -175,13 +181,6 @@ module Log4ever
175
181
  @auth_store.note_store.updateNote(@auth_store.auth_token, updateNote)
176
182
  end
177
183
 
178
- # clear note object
179
- def clear
180
- @params = {}
181
- @note = @content_ = @content_xml = nil
182
- initialize(@notebook)
183
- end
184
-
185
184
  # get latest note object
186
185
  def get
187
186
  return @note unless @note.nil?
@@ -200,10 +199,9 @@ module Log4ever
200
199
  @note
201
200
  end
202
201
 
203
- # get latest note object(newest object)
202
+ # force get latest note object
204
203
  def get!
205
- clear
206
- get
204
+ clear and get
207
205
  end
208
206
 
209
207
  # create note object
@@ -228,22 +226,9 @@ module Log4ever
228
226
  Time.at(ut.to_f)
229
227
  end
230
228
 
231
- # get note content text
232
- def content
233
- return @content_ unless @content_.nil?
234
- @note.nil? and get
235
- @content_ = !@note.nil? && !@note.guid.nil? ? @auth_store.note_store.getNoteContent(@auth_store.auth_token, @note.guid) : ""
236
- end
237
-
238
- # get note content xml object
239
- def content_xml
240
- return @content_xml unless @content_xml.nil?
241
- @content_xml = Nokogiri::XML(content)
242
- end
243
-
244
- # clear note object
229
+ # clear
245
230
  def clear
246
- @note = nil
231
+ @note = @content_ = @content_xml = nil
247
232
  end
248
233
  end
249
234
 
@@ -271,18 +256,6 @@ module Log4ever
271
256
  end
272
257
  end
273
258
 
274
- # get newest tag objects
275
- def get!
276
- clear
277
- get
278
- end
279
-
280
- # clear note object
281
- def clear
282
- @tags = nil
283
- @tag_guids = nil
284
- end
285
-
286
259
  private
287
260
  # create tag object
288
261
  def create(tag_name)
@@ -13,41 +13,41 @@ module Log4r
13
13
  def initialize(_name, hash = {})
14
14
  super(_name, hash)
15
15
  validate(hash)
16
- end
17
-
18
- # synchronize note
19
- def sync
20
- @note = @evernote.note(@notebook)
21
- @tag = @evernote.tag(@note)
16
+ evernote = Log4ever::Evernote.new(@auth_token, @is_sandbox)
17
+ @notebook = evernote.notebook.get(@notebook_name, @stack_name)
18
+ @note = evernote.note(@notebook)
19
+ @tag = evernote.tag(@note)
22
20
  @tag.names = @tags
23
- set_maxsize(@hash) # for rolling
24
- set_shift_age(@hash) # for rolling
21
+ set_maxsize(hash) # for rolling
22
+ set_shift_age(hash) # for rolling
23
+ @hash = hash
25
24
  end
26
25
 
27
26
  # validation of evernote parameters
28
27
  def validate(hash)
29
- is_sandbox = hash[:sandbox] || hash['sandbox'] || false
30
- raise ArgumentError, "Sandbox must be type of boolean" unless is_sandbox == false || is_sandbox == true
28
+ @is_sandbox = hash[:sandbox] || hash['sandbox'] || false
29
+ raise ArgumentError, "Sandbox must be type of boolean" unless @is_sandbox == false || @is_sandbox == true
31
30
  @auth_token = hash[:auth_token] || hash['auth_token'] || ""
32
31
  raise ArgumentError, "Must specify from auth token" if @auth_token.empty?
33
- notebook_name = to_utf8(hash[:notebook] || hash['notebook'] || "")
34
- raise ArgumentError, "Must specify from notebook" if notebook_name.empty?
35
- stack_name = to_utf8(hash[:stack] || hash['stack'])
36
- @evernote = Log4ever::Evernote.new(@auth_token, is_sandbox)
32
+ @notebook_name = to_utf8(hash[:notebook] || hash['notebook'] || "")
33
+ raise ArgumentError, "Must specify from notebook" if @notebook_name.empty?
34
+ @stack_name = to_utf8(hash[:stack] || hash['stack'])
37
35
  @tags = to_utf8(hash[:tags] || hash['tags'] || [])
38
- notebook = @evernote.notebook
39
- @notebook = notebook.get(notebook_name, stack_name)
40
- @hash = hash
41
- sync
42
36
  end
43
37
 
44
38
  def canonical_log(logevent); super end
45
39
 
40
+ # sync
41
+ def sync_note
42
+ @note.get!
43
+ update_maxtime(@hash) # update rolling status
44
+ end
45
+
46
46
  # write log
47
47
  def write(content)
48
- sync
49
48
  if note_size_requires_roll? || time_requires_roll? || different_tag?
50
49
  create_log(content)
50
+ sync_note
51
51
  else
52
52
  update_log(content)
53
53
  end
@@ -56,7 +56,6 @@ module Log4r
56
56
  private
57
57
  # write log to note
58
58
  def create_log(content)
59
- @note.clear
60
59
  @note.title = to_utf8(@name) + " - " + Time.now.strftime("%Y-%m-%d %H:%M:%S")
61
60
  @note.tags = @tag.get
62
61
  @note.content = to_utf8(content)
@@ -74,7 +73,7 @@ module Log4r
74
73
 
75
74
  # more expensive, only for startup
76
75
  def note_size_requires_roll?
77
- @note.size == 0 || (@maxsize > 0 && @note.size >= @maxsize)
76
+ @note.size == 0 || (@maxsize > 0 && @note.size > @maxsize)
78
77
  end
79
78
 
80
79
  # whether or not to rotate
@@ -145,6 +144,8 @@ module Log4r
145
144
  end
146
145
  end
147
146
 
147
+ alias_method :update_maxtime, :set_shift_age
148
+
148
149
  # encode for evernote internal charset
149
150
  # convert character encoding to UTF-8 from Shift_JIS or EUC-JP
150
151
  def to_utf8(mixed)
@@ -14,7 +14,7 @@ Gem::Specification.new do |gem|
14
14
  gem.add_dependency('activesupport', '>= 4.0.4')
15
15
  gem.add_dependency('i18n', '>= 0.6.9')
16
16
  gem.add_dependency('evernote_oauth', '>= 0.2.3')
17
- gem.version = '0.1.4'
17
+ gem.version = '0.1.5'
18
18
  gem.license = 'MIT'
19
19
  end
20
20
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: log4ever
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - mapserver2007
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-21 00:00:00.000000000 Z
11
+ date: 2014-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: log4r