log4ever 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -1
- data/README.md +10 -2
- data/gem/log4ever-0.0.2.gem +0 -0
- data/lib/log4r/evernote.rb +44 -4
- data/lib/log4r/outputter/evernoteoutputter.rb +13 -26
- data/log4ever.gemspec +1 -1
- data/spec/log4ever_spec.rb +27 -5
- metadata +3 -2
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -7,7 +7,7 @@ log4ever is simple logger for evernote. It is available as an extension of [log4
|
|
7
7
|
require 'log4r/evernote'
|
8
8
|
|
9
9
|
logger = Log4r::Logger.new("Evernote")
|
10
|
-
logger.
|
10
|
+
logger.level = Log4r::INFO
|
11
11
|
formatter = Log4r::PatternFormatter.new(
|
12
12
|
:pattern => "%d %C[%l]: %M ",
|
13
13
|
:date_format => "%Y/%m/%d %H:%M:%Sm"
|
@@ -32,7 +32,15 @@ Output:
|
|
32
32
|
|
33
33
|
2012-08-06 21:12:31 Evernote[INFO]: log output
|
34
34
|
|
35
|
-
The output results are stored in Evernote.
|
35
|
+
The output results are stored in Evernote.
|
36
|
+
|
37
|
+
###ChangeLog
|
38
|
+
* 0.0.1
|
39
|
+
First release.
|
40
|
+
* 0.0.2
|
41
|
+
Remove unnecessary processing.
|
42
|
+
* 0.0.3
|
43
|
+
If tag, notebook does not exist, it will be created.
|
36
44
|
|
37
45
|
##License
|
38
46
|
Licensed under the MIT
|
Binary file
|
data/lib/log4r/evernote.rb
CHANGED
@@ -15,7 +15,7 @@ require "Evernote/EDAM/note_store"
|
|
15
15
|
require "Evernote/EDAM/limits_constants.rb"
|
16
16
|
|
17
17
|
module Log4ever
|
18
|
-
VERSION = '0.0.
|
18
|
+
VERSION = '0.0.3'
|
19
19
|
class TypeError < StandardError; end
|
20
20
|
module ShiftAge
|
21
21
|
DAILY = 1
|
@@ -28,6 +28,7 @@ module Log4r
|
|
28
28
|
include Log4ever
|
29
29
|
class MyEvernote
|
30
30
|
@@note_store = nil
|
31
|
+
|
31
32
|
def initialize(env, auth_token)
|
32
33
|
if @@note_store.nil?
|
33
34
|
@env = env
|
@@ -54,7 +55,9 @@ module Log4r
|
|
54
55
|
|
55
56
|
# get registerd tag list
|
56
57
|
def get_tags(tag_names)
|
57
|
-
tag_names.map
|
58
|
+
tag_names.map do |tag_name|
|
59
|
+
get_tag(tag_name) || create_tag(tag_name)
|
60
|
+
end
|
58
61
|
end
|
59
62
|
|
60
63
|
# get registered tag object
|
@@ -62,11 +65,24 @@ module Log4r
|
|
62
65
|
return if tag_name.empty?
|
63
66
|
tag_name = to_ascii(tag_name)
|
64
67
|
@@note_store.listTags(@@auth_token).each do |tag|
|
65
|
-
|
68
|
+
if tag_name == tag.name
|
69
|
+
Logger.log_internal { "Get tag: #{tag_name}" }
|
70
|
+
return tag
|
71
|
+
end
|
66
72
|
end
|
67
73
|
nil
|
68
74
|
end
|
75
|
+
|
76
|
+
# create tag object
|
77
|
+
def create_tag(tag_name)
|
78
|
+
tag = Evernote::EDAM::Type::Tag.new
|
79
|
+
tag.name = tag_name
|
80
|
+
tag_obj = @@note_store.createTag(@@auth_token, tag)
|
81
|
+
Logger.log_internal { "Create tag: #{tag_name}" }
|
82
|
+
tag_obj
|
83
|
+
end
|
69
84
|
|
85
|
+
# encode for evernote internal charset
|
70
86
|
def to_ascii(str)
|
71
87
|
str.force_encoding("ASCII-8BIT") unless str.nil?
|
72
88
|
end
|
@@ -75,16 +91,37 @@ module Log4r
|
|
75
91
|
class Notebook < MyEvernote
|
76
92
|
def initialize(notebook_name, stack_name)
|
77
93
|
return unless @notebook.nil?
|
94
|
+
get(notebook_name, stack_name) || create(notebook_name, stack_name)
|
95
|
+
end
|
96
|
+
|
97
|
+
# get notebook object
|
98
|
+
def getNotebookObject; @notebook end
|
99
|
+
|
100
|
+
# get notebook
|
101
|
+
def get(notebook_name, stack_name)
|
78
102
|
@@note_store.listNotebooks(@@auth_token).each do |notebook|
|
79
103
|
notebook_name = to_ascii(notebook_name)
|
80
104
|
stack_name = to_ascii(stack_name)
|
81
105
|
if notebook.name == notebook_name && notebook.stack == stack_name
|
106
|
+
Logger.log_internal { "Get notebook: #{stack_name}/#{notebook_name}" }
|
82
107
|
@notebook = notebook
|
83
108
|
break
|
84
109
|
end
|
85
110
|
end
|
111
|
+
return @notebook
|
86
112
|
end
|
87
|
-
|
113
|
+
|
114
|
+
# create notebook
|
115
|
+
def create(notebook_name, stack_name)
|
116
|
+
notebook = Evernote::EDAM::Type::Notebook.new
|
117
|
+
notebook.name = notebook_name
|
118
|
+
notebook.stack = stack_name
|
119
|
+
@notebook = @@note_store.createNotebook(@@auth_token, notebook)
|
120
|
+
Logger.log_internal { "Create notebook: #{stack_name}/#{notebook_name}" }
|
121
|
+
@notebook
|
122
|
+
end
|
123
|
+
|
124
|
+
# notebook guid
|
88
125
|
def guid; @notebook.guid end
|
89
126
|
|
90
127
|
# clear notebook object
|
@@ -109,6 +146,9 @@ module Log4r
|
|
109
146
|
getNote
|
110
147
|
end
|
111
148
|
|
149
|
+
# get note object
|
150
|
+
def getNoteObject; @note end
|
151
|
+
|
112
152
|
# content size
|
113
153
|
def size
|
114
154
|
content.bytesize > 0 ? content.bytesize - XML_TEMPLATE_BYTE : 0
|
@@ -45,26 +45,28 @@ module Log4r
|
|
45
45
|
def canonical_log(logevent); super end
|
46
46
|
|
47
47
|
def write(content)
|
48
|
-
@content = content
|
49
48
|
if note_size_requires_roll? || time_requires_roll?
|
50
|
-
create_log
|
49
|
+
create_log(content)
|
51
50
|
else
|
52
|
-
update_log
|
51
|
+
update_log(content)
|
53
52
|
end
|
54
53
|
end
|
55
54
|
|
56
55
|
private
|
57
|
-
|
56
|
+
# write log to note
|
57
|
+
def create_log(content)
|
58
58
|
@note.clear
|
59
59
|
@note.title = @name + " - " + Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
60
60
|
@note.tags = @tags
|
61
|
-
@note.content =
|
61
|
+
@note.content = content
|
62
62
|
@note.create
|
63
63
|
Logger.log_internal { "Create note: #{@note.guid}" }
|
64
64
|
end
|
65
65
|
|
66
|
-
|
67
|
-
|
66
|
+
# update log in note
|
67
|
+
def update_log(content)
|
68
|
+
@note.addContent(content)
|
69
|
+
@note.tags = @tags
|
68
70
|
@note.update
|
69
71
|
Logger.log_internal { "Update note: #{@note.guid}" }
|
70
72
|
end
|
@@ -74,10 +76,12 @@ module Log4r
|
|
74
76
|
@note.size == 0 || (@maxsize > 0 && @note.size >= @maxsize)
|
75
77
|
end
|
76
78
|
|
79
|
+
# whether or not to rotate rolling
|
77
80
|
def time_requires_roll?
|
78
81
|
!@endTime.nil? && Time.now.to_i >= @endTime
|
79
82
|
end
|
80
|
-
|
83
|
+
|
84
|
+
# max amount of log in note
|
81
85
|
def set_maxsize(options)
|
82
86
|
if options.has_key?(:maxsize) || options.has_key?('maxsize')
|
83
87
|
maxsize = options[:maxsize] || options['maxsize']
|
@@ -104,24 +108,8 @@ module Log4r
|
|
104
108
|
@maxsize = 0
|
105
109
|
end
|
106
110
|
end
|
107
|
-
|
108
|
-
def set_maxtime(options)
|
109
|
-
if options.has_key?(:maxtime) || options.has_key?('maxtime')
|
110
|
-
_maxtime = (options[:maxtime] or options['maxtime']).to_i
|
111
|
-
if _maxtime.class != Fixnum
|
112
|
-
raise TypeError, "Argument 'maxtime' must be an Fixnum", caller
|
113
|
-
end
|
114
|
-
if _maxtime == 0
|
115
|
-
raise TypeError, "Argument 'maxtime' must be > 0", caller
|
116
|
-
end
|
117
|
-
@maxtime = _maxtime
|
118
|
-
@startTime = Time.now
|
119
|
-
else
|
120
|
-
@maxtime = 0
|
121
|
-
@startTime = 0
|
122
|
-
end
|
123
|
-
end
|
124
111
|
|
112
|
+
# rolling interval
|
125
113
|
def set_shift_age(options)
|
126
114
|
if options.has_key?(:shift_age) || options.has_key?('shift_age')
|
127
115
|
_shift_age = (options[:shift_age] or options['shift_age']).to_i
|
@@ -133,7 +121,6 @@ module Log4r
|
|
133
121
|
Log4ever::ShiftAge::MONTHLY].include? _shift_age
|
134
122
|
raise TypeError, "Argument 'shift_age' must be > 0", caller
|
135
123
|
end
|
136
|
-
|
137
124
|
now = Time.now
|
138
125
|
case _shift_age
|
139
126
|
when Log4ever::ShiftAge::DAILY
|
data/log4ever.gemspec
CHANGED
data/spec/log4ever_spec.rb
CHANGED
@@ -34,19 +34,18 @@ describe Log4ever, 'が実行する処理' do
|
|
34
34
|
before do
|
35
35
|
@config_xml = Log4ever::config_xml
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
describe 'Log4rのEvernote書き出し処理' do
|
39
39
|
it '書き出しが成功すること' do
|
40
40
|
log_content = "aaa"
|
41
41
|
formatter_content = "\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\s.*?\[.*?\]:\s(.*)\\n"
|
42
|
-
|
43
|
-
logger.outputters =
|
42
|
+
@params[:maxsize] = 1
|
43
|
+
logger.outputters = EvernoteOutputter.new('evernote', @params)
|
44
44
|
logger.debug(log_content)
|
45
|
-
|
46
45
|
@evernote = MyEvernote.new(@params[:env], @params[:auth_token])
|
47
46
|
@notebook = @evernote.get_notebook(@params[:notebook], @params[:stack])
|
48
47
|
@note = @evernote.get_note(@notebook)
|
49
|
-
write_log = @note.content_xml.children[1].children.reverse[
|
48
|
+
write_log = @note.content_xml.children[1].children.reverse[0].text
|
50
49
|
if /\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\s.*?\[.*?\]:\s(.*)/ =~ write_log
|
51
50
|
log_content.should == $1.strip
|
52
51
|
else
|
@@ -91,4 +90,27 @@ describe Log4ever, 'が実行する処理' do
|
|
91
90
|
}.should raise_error(ArgumentError)
|
92
91
|
end
|
93
92
|
end
|
93
|
+
|
94
|
+
describe 'Log4everの処理' do
|
95
|
+
it 'ノートブックが存在しない場合、新規作成されること' do
|
96
|
+
logger.outputters = evernoteOutputter
|
97
|
+
@evernote = MyEvernote.new(@params[:env], @params[:auth_token])
|
98
|
+
notebook_name = Time.now.to_i.to_s
|
99
|
+
notebook = @evernote.get_notebook(notebook_name, @params[:stack])
|
100
|
+
obj = notebook.get(notebook_name, @params[:stack])
|
101
|
+
obj.name.should == notebook_name
|
102
|
+
obj.stack.should == @params[:stack]
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'タグが存在しない場合、新規作成されること' do
|
106
|
+
@params[:tags] = [Time.now.to_i.to_s]
|
107
|
+
@params[:maxsize] = 1
|
108
|
+
logger.outputters = EvernoteOutputter.new('evernote', @params)
|
109
|
+
logger.debug("test")
|
110
|
+
evernote = MyEvernote.new(@params[:env], @params[:auth_token])
|
111
|
+
notebook = evernote.get_notebook(@params[:notebook], @params[:stack])
|
112
|
+
note = evernote.get_note(notebook)
|
113
|
+
note.getNoteObject.tagGuids[0].should_not be_empty
|
114
|
+
end
|
115
|
+
end
|
94
116
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: log4ever
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-14 00:00:00.000000000 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
description: log4ever is simple logger for evernote. It is available as an extension
|
@@ -29,6 +29,7 @@ files:
|
|
29
29
|
- config/evernote.auth.test.yml
|
30
30
|
- config/log4r.xml
|
31
31
|
- gem/log4ever-0.0.1.gem
|
32
|
+
- gem/log4ever-0.0.2.gem
|
32
33
|
- lib/log4r/evernote.rb
|
33
34
|
- lib/log4r/evernote/lib/Evernote/EDAM/errors_constants.rb
|
34
35
|
- lib/log4r/evernote/lib/Evernote/EDAM/errors_types.rb
|