logster 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +19 -19
- data/.rubocop.yml +1 -1
- data/.travis.yml +16 -16
- data/CHANGELOG.md +169 -166
- data/Gemfile +4 -4
- data/Guardfile +8 -8
- data/LICENSE.txt +22 -22
- data/README.md +99 -99
- data/Rakefile +21 -21
- data/assets/fonts/FontAwesome.otf +0 -0
- data/assets/fonts/fontawesome-webfont.eot +0 -0
- data/assets/fonts/fontawesome-webfont.svg +639 -639
- data/assets/fonts/fontawesome-webfont.ttf +0 -0
- data/assets/fonts/fontawesome-webfont.woff +0 -0
- data/assets/fonts/fontawesome-webfont.woff2 +0 -0
- data/assets/images/Icon-144_rounded.png +0 -0
- data/assets/images/Icon-144_square.png +0 -0
- data/assets/images/icon_144x144.png +0 -0
- data/assets/images/icon_64x64.png +0 -0
- data/assets/javascript/client-app.js +100 -100
- data/assets/stylesheets/client-app.css +0 -0
- data/build_client_app.sh +0 -0
- data/client-app/.editorconfig +20 -20
- data/client-app/.ember-cli +9 -9
- data/client-app/.eslintignore +19 -19
- data/client-app/.eslintrc.js +46 -46
- data/client-app/.gitignore +23 -23
- data/client-app/.travis.yml +27 -27
- data/client-app/.watchmanconfig +3 -3
- data/client-app/README.md +57 -57
- data/client-app/app/app.js +14 -14
- data/client-app/app/components/actions-menu.js +37 -37
- data/client-app/app/components/env-tab.js +44 -44
- data/client-app/app/components/message-info.js +65 -65
- data/client-app/app/components/message-row.js +45 -45
- data/client-app/app/components/panel-resizer.js +74 -74
- data/client-app/app/components/tab-contents.js +27 -27
- data/client-app/app/components/tab-link.js +5 -5
- data/client-app/app/components/tabbed-section.js +32 -32
- data/client-app/app/components/time-formatter.js +25 -25
- data/client-app/app/components/update-time.js +21 -21
- data/client-app/app/controllers/index.js +105 -105
- data/client-app/app/controllers/show.js +13 -13
- data/client-app/app/index.html +29 -29
- data/client-app/app/initializers/app-init.js +72 -72
- data/client-app/app/lib/preload.js +14 -14
- data/client-app/app/lib/utilities.js +140 -140
- data/client-app/app/models/message-collection.js +178 -178
- data/client-app/app/models/message.js +100 -100
- data/client-app/app/resolver.js +3 -3
- data/client-app/app/router.js +14 -14
- data/client-app/app/routes/index.js +57 -57
- data/client-app/app/routes/show.js +14 -14
- data/client-app/app/styles/app.css +521 -521
- data/client-app/app/templates/application.hbs +2 -2
- data/client-app/app/templates/components/actions-menu.hbs +12 -12
- data/client-app/app/templates/components/env-tab.hbs +10 -10
- data/client-app/app/templates/components/message-info.hbs +41 -41
- data/client-app/app/templates/components/message-row.hbs +15 -15
- data/client-app/app/templates/components/panel-resizer.hbs +3 -3
- data/client-app/app/templates/components/tabbed-section.hbs +10 -10
- data/client-app/app/templates/components/time-formatter.hbs +1 -1
- data/client-app/app/templates/index.hbs +58 -58
- data/client-app/app/templates/show.hbs +7 -7
- data/client-app/config/environment.js +51 -51
- data/client-app/config/optional-features.json +3 -3
- data/client-app/config/targets.js +18 -18
- data/client-app/ember-cli-build.js +29 -29
- data/client-app/package-lock.json +11365 -11365
- data/client-app/package.json +56 -56
- data/client-app/testem.js +25 -25
- data/client-app/tests/index.html +34 -34
- data/client-app/tests/integration/components/actions-menu-test.js +26 -26
- data/client-app/tests/integration/components/env-tab-test.js +73 -73
- data/client-app/tests/integration/components/message-info-test.js +26 -26
- data/client-app/tests/integration/components/message-row-test.js +26 -26
- data/client-app/tests/integration/components/panel-resizer-test.js +26 -26
- data/client-app/tests/integration/components/tab-contents-test.js +26 -26
- data/client-app/tests/integration/components/tab-link-test.js +26 -26
- data/client-app/tests/integration/components/tabbed-section-test.js +26 -26
- data/client-app/tests/integration/components/time-formatter-test.js +26 -26
- data/client-app/tests/integration/components/update-time-test.js +26 -26
- data/client-app/tests/test-helper.js +8 -8
- data/client-app/tests/unit/controllers/index-test.js +12 -12
- data/client-app/tests/unit/controllers/show-test.js +12 -12
- data/client-app/tests/unit/initializers/app-init-test.js +31 -31
- data/client-app/tests/unit/routes/index-test.js +11 -11
- data/client-app/tests/unit/routes/show-test.js +11 -11
- data/lib/examples/sidekiq_logster_reporter.rb +21 -21
- data/lib/logster.rb +54 -54
- data/lib/logster/base_store.rb +141 -141
- data/lib/logster/configuration.rb +25 -25
- data/lib/logster/defer_logger.rb +14 -14
- data/lib/logster/ignore_pattern.rb +65 -65
- data/lib/logster/logger.rb +113 -113
- data/lib/logster/message.rb +212 -212
- data/lib/logster/middleware/debug_exceptions.rb +26 -26
- data/lib/logster/middleware/reporter.rb +55 -55
- data/lib/logster/middleware/viewer.rb +221 -221
- data/lib/logster/rails/railtie.rb +63 -63
- data/lib/logster/redis_store.rb +566 -566
- data/lib/logster/scheduler.rb +54 -40
- data/lib/logster/version.rb +3 -3
- data/lib/logster/web.rb +14 -14
- data/logster.gemspec +35 -35
- data/test/examples/test_sidekiq_reporter_example.rb +46 -46
- data/test/fake_data/Gemfile +4 -4
- data/test/fake_data/generate.rb +10 -10
- data/test/logster/middleware/test_reporter.rb +19 -19
- data/test/logster/middleware/test_viewer.rb +96 -96
- data/test/logster/test_base_store.rb +147 -147
- data/test/logster/test_defer_logger.rb +34 -34
- data/test/logster/test_ignore_pattern.rb +41 -41
- data/test/logster/test_logger.rb +86 -86
- data/test/logster/test_message.rb +119 -119
- data/test/logster/test_redis_rate_limiter.rb +230 -230
- data/test/logster/test_redis_store.rb +720 -720
- data/test/test_helper.rb +38 -38
- data/vendor/assets/javascripts/logster.js.erb +39 -39
- metadata +2 -2
@@ -1,147 +1,147 @@
|
|
1
|
-
require_relative '../test_helper'
|
2
|
-
require 'logster/base_store'
|
3
|
-
require 'logster/ignore_pattern'
|
4
|
-
|
5
|
-
class TestBaseStore < Minitest::Test
|
6
|
-
|
7
|
-
def setup
|
8
|
-
@store = Logster::TestStore.new
|
9
|
-
@store.clear_all
|
10
|
-
end
|
11
|
-
|
12
|
-
def teardown
|
13
|
-
@store.clear_all
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_report_skip_empty
|
17
|
-
@store.skip_empty = true
|
18
|
-
@store.report(Logger::WARN, "test", nil)
|
19
|
-
@store.report(Logger::WARN, "test", '')
|
20
|
-
@store.report(Logger::WARN, "test", "foo") #
|
21
|
-
@store.skip_empty = false
|
22
|
-
@store.report(Logger::WARN, "test", nil) #
|
23
|
-
|
24
|
-
assert_equal(2, @store.count)
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_report_skip_level
|
28
|
-
@store.level = nil
|
29
|
-
@store.report(Logger::DEBUG, "test", "A") #
|
30
|
-
@store.level = Logger::WARN
|
31
|
-
@store.report(Logger::DEBUG, "test", "A")
|
32
|
-
@store.report(Logger::INFO, "test", "B")
|
33
|
-
@store.report(Logger::WARN, "test", "C") #
|
34
|
-
@store.report(Logger::ERROR, "test", "D") #
|
35
|
-
assert_equal(3, @store.count)
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_report_skip_ignore
|
39
|
-
@store.report(Logger::WARN, "test", "Can't verify CSRF token authenticity")
|
40
|
-
@store.report(Logger::FATAL, "test", "ActiveRecord::RecordNotFound (Couldn't find Upload with 'id'=9947)")
|
41
|
-
@store.report(Logger::WARN, "test", "B")
|
42
|
-
@store.ignore = [
|
43
|
-
/^ActiveRecord::RecordNotFound \(Couldn't find Upload/,
|
44
|
-
/^Can't verify CSRF token authenticity/
|
45
|
-
]
|
46
|
-
@store.report(Logger::WARN, "test", "Can't verify CSRF token authenticity")
|
47
|
-
@store.report(Logger::FATAL, "test", "ActiveRecord::RecordNotFound (Couldn't find Upload with 'id'=9947)")
|
48
|
-
@store.report(Logger::FATAL, "test", "ActiveRecord::RecordNotFound (Couldn't find Upload with 'id'=9489+78946947)")
|
49
|
-
@store.report(Logger::WARN, "test", "B")
|
50
|
-
|
51
|
-
assert_equal(4, @store.count)
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_ignore_pattern_basic
|
55
|
-
@store.ignore = [
|
56
|
-
Logster::IgnorePattern.new(nil, username: 'CausingErrors')
|
57
|
-
]
|
58
|
-
@store.report(Logger::WARN, "test", "Foobar") #
|
59
|
-
@store.report(Logger::WARN, "test", "Foobar", env: { username: 'CausingErrors' })
|
60
|
-
@store.report(Logger::WARN, "test", "Foobar", env: nil)
|
61
|
-
@store.report(Logger::WARN, "test", "Something Else", env: { username: 'CausingErrors' })
|
62
|
-
@store.report(Logger::WARN, "test", "Something Else", env: { 'username' => 'CausingErrors' })
|
63
|
-
@store.report(Logger::WARN, "test", "Something Else", env: { username: 'GoodPerson' }) #
|
64
|
-
@store.report(Logger::WARN, "test", "Can't verify CSRF token authenticity") #
|
65
|
-
|
66
|
-
assert_equal(4, @store.count)
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_ignore_pattern_real
|
70
|
-
@store.ignore = [
|
71
|
-
/^ActionController::RoutingError \(No route matches/,
|
72
|
-
Logster::IgnorePattern.new("Can't verify CSRF token authenticity", REQUEST_URI: /\/trackback\/$/)
|
73
|
-
]
|
74
|
-
# blocked
|
75
|
-
@store.report(Logger::WARN, "whatever", "Can't verify CSRF token authenticity",
|
76
|
-
env: {
|
77
|
-
HTTP_HOST: 'meta.discourse.org',
|
78
|
-
REQUEST_URI: '/t/use-more-standard-smiley-codes-instead-of-smile/1822/trackback/',
|
79
|
-
REQUEST_METHOD: 'POST',
|
80
|
-
HTTP_USER_AGENT: 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)',
|
81
|
-
params: {
|
82
|
-
title: 'Something Spammy',
|
83
|
-
url: 'http://spam.example.net/whatever/spam.html',
|
84
|
-
excerpt: 'http://spam.example.com/pdf/blahblah.html free viagra',
|
85
|
-
blog_name: 'get free spam for cheap'
|
86
|
-
}
|
87
|
-
}
|
88
|
-
)
|
89
|
-
# logged
|
90
|
-
@store.report(Logger::WARN, "whatever", "Can't verify CSRF token authenticity",
|
91
|
-
env: {
|
92
|
-
HTTP_HOST: 'meta.discourse.org',
|
93
|
-
REQUEST_URI: '/session',
|
94
|
-
REQUEST_METHOD: 'POST',
|
95
|
-
HTTP_USER_AGENT: 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36',
|
96
|
-
params: {
|
97
|
-
username: 'user',
|
98
|
-
password: 'password',
|
99
|
-
form_authenticity_token: 'incorrect'
|
100
|
-
}
|
101
|
-
}
|
102
|
-
)
|
103
|
-
assert_equal(1, @store.count)
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_timestamp
|
107
|
-
time = Time.now - 24 * 60 * 60
|
108
|
-
message = @store.report(Logger::WARN, "test", "B", timestamp: time)
|
109
|
-
|
110
|
-
assert_equal(time, message.timestamp)
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_backtrace
|
114
|
-
# Create an error with a backtrace
|
115
|
-
error = TypeError.new
|
116
|
-
begin
|
117
|
-
raise error
|
118
|
-
rescue => e
|
119
|
-
error = e
|
120
|
-
end
|
121
|
-
|
122
|
-
# Backtrace can be passed via backtrace param or env
|
123
|
-
message = @store.report(Logger::WARN, "test", "A", backtrace: error.backtrace)
|
124
|
-
assert_equal(error.backtrace.join("\n"), message.backtrace)
|
125
|
-
message = @store.report(Logger::WARN, "test", "B", env: { backtrace: error.backtrace })
|
126
|
-
assert_equal(error.backtrace.join("\n"), message.backtrace)
|
127
|
-
|
128
|
-
# Via env takes priority
|
129
|
-
message = @store.report(Logger::WARN, "test", "C", backtrace: "Garbage", env: { backtrace: error.backtrace })
|
130
|
-
assert_equal(error.backtrace.join("\n"), message.backtrace)
|
131
|
-
|
132
|
-
# Backtrace is always a string
|
133
|
-
# Cannot do an equal assert here, because it uses `caller` when not provided
|
134
|
-
message = @store.report(Logger::WARN, "test", "D", backtrace: nil)
|
135
|
-
assert_kind_of(String, message.backtrace)
|
136
|
-
message = @store.report(Logger::WARN, "test", "E", env: { backtrace: nil })
|
137
|
-
assert_kind_of(String, message.backtrace)
|
138
|
-
message = @store.report(Logger::WARN, "test", "F", backtrace: nil, env: { backtrace: nil })
|
139
|
-
assert_kind_of(String, message.backtrace)
|
140
|
-
message = @store.report(Logger::WARN, "test", "G")
|
141
|
-
assert_kind_of(String, message.backtrace)
|
142
|
-
|
143
|
-
# Arrays are turned into strings via join \n
|
144
|
-
message = @store.report(Logger::WARN, "test", "H", backtrace: ["Foo", "Bar"])
|
145
|
-
assert_equal("Foo\nBar", message.backtrace)
|
146
|
-
end
|
147
|
-
end
|
1
|
+
require_relative '../test_helper'
|
2
|
+
require 'logster/base_store'
|
3
|
+
require 'logster/ignore_pattern'
|
4
|
+
|
5
|
+
class TestBaseStore < Minitest::Test
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@store = Logster::TestStore.new
|
9
|
+
@store.clear_all
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
@store.clear_all
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_report_skip_empty
|
17
|
+
@store.skip_empty = true
|
18
|
+
@store.report(Logger::WARN, "test", nil)
|
19
|
+
@store.report(Logger::WARN, "test", '')
|
20
|
+
@store.report(Logger::WARN, "test", "foo") #
|
21
|
+
@store.skip_empty = false
|
22
|
+
@store.report(Logger::WARN, "test", nil) #
|
23
|
+
|
24
|
+
assert_equal(2, @store.count)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_report_skip_level
|
28
|
+
@store.level = nil
|
29
|
+
@store.report(Logger::DEBUG, "test", "A") #
|
30
|
+
@store.level = Logger::WARN
|
31
|
+
@store.report(Logger::DEBUG, "test", "A")
|
32
|
+
@store.report(Logger::INFO, "test", "B")
|
33
|
+
@store.report(Logger::WARN, "test", "C") #
|
34
|
+
@store.report(Logger::ERROR, "test", "D") #
|
35
|
+
assert_equal(3, @store.count)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_report_skip_ignore
|
39
|
+
@store.report(Logger::WARN, "test", "Can't verify CSRF token authenticity")
|
40
|
+
@store.report(Logger::FATAL, "test", "ActiveRecord::RecordNotFound (Couldn't find Upload with 'id'=9947)")
|
41
|
+
@store.report(Logger::WARN, "test", "B")
|
42
|
+
@store.ignore = [
|
43
|
+
/^ActiveRecord::RecordNotFound \(Couldn't find Upload/,
|
44
|
+
/^Can't verify CSRF token authenticity/
|
45
|
+
]
|
46
|
+
@store.report(Logger::WARN, "test", "Can't verify CSRF token authenticity")
|
47
|
+
@store.report(Logger::FATAL, "test", "ActiveRecord::RecordNotFound (Couldn't find Upload with 'id'=9947)")
|
48
|
+
@store.report(Logger::FATAL, "test", "ActiveRecord::RecordNotFound (Couldn't find Upload with 'id'=9489+78946947)")
|
49
|
+
@store.report(Logger::WARN, "test", "B")
|
50
|
+
|
51
|
+
assert_equal(4, @store.count)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_ignore_pattern_basic
|
55
|
+
@store.ignore = [
|
56
|
+
Logster::IgnorePattern.new(nil, username: 'CausingErrors')
|
57
|
+
]
|
58
|
+
@store.report(Logger::WARN, "test", "Foobar") #
|
59
|
+
@store.report(Logger::WARN, "test", "Foobar", env: { username: 'CausingErrors' })
|
60
|
+
@store.report(Logger::WARN, "test", "Foobar", env: nil)
|
61
|
+
@store.report(Logger::WARN, "test", "Something Else", env: { username: 'CausingErrors' })
|
62
|
+
@store.report(Logger::WARN, "test", "Something Else", env: { 'username' => 'CausingErrors' })
|
63
|
+
@store.report(Logger::WARN, "test", "Something Else", env: { username: 'GoodPerson' }) #
|
64
|
+
@store.report(Logger::WARN, "test", "Can't verify CSRF token authenticity") #
|
65
|
+
|
66
|
+
assert_equal(4, @store.count)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_ignore_pattern_real
|
70
|
+
@store.ignore = [
|
71
|
+
/^ActionController::RoutingError \(No route matches/,
|
72
|
+
Logster::IgnorePattern.new("Can't verify CSRF token authenticity", REQUEST_URI: /\/trackback\/$/)
|
73
|
+
]
|
74
|
+
# blocked
|
75
|
+
@store.report(Logger::WARN, "whatever", "Can't verify CSRF token authenticity",
|
76
|
+
env: {
|
77
|
+
HTTP_HOST: 'meta.discourse.org',
|
78
|
+
REQUEST_URI: '/t/use-more-standard-smiley-codes-instead-of-smile/1822/trackback/',
|
79
|
+
REQUEST_METHOD: 'POST',
|
80
|
+
HTTP_USER_AGENT: 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)',
|
81
|
+
params: {
|
82
|
+
title: 'Something Spammy',
|
83
|
+
url: 'http://spam.example.net/whatever/spam.html',
|
84
|
+
excerpt: 'http://spam.example.com/pdf/blahblah.html free viagra',
|
85
|
+
blog_name: 'get free spam for cheap'
|
86
|
+
}
|
87
|
+
}
|
88
|
+
)
|
89
|
+
# logged
|
90
|
+
@store.report(Logger::WARN, "whatever", "Can't verify CSRF token authenticity",
|
91
|
+
env: {
|
92
|
+
HTTP_HOST: 'meta.discourse.org',
|
93
|
+
REQUEST_URI: '/session',
|
94
|
+
REQUEST_METHOD: 'POST',
|
95
|
+
HTTP_USER_AGENT: 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36',
|
96
|
+
params: {
|
97
|
+
username: 'user',
|
98
|
+
password: 'password',
|
99
|
+
form_authenticity_token: 'incorrect'
|
100
|
+
}
|
101
|
+
}
|
102
|
+
)
|
103
|
+
assert_equal(1, @store.count)
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_timestamp
|
107
|
+
time = Time.now - 24 * 60 * 60
|
108
|
+
message = @store.report(Logger::WARN, "test", "B", timestamp: time)
|
109
|
+
|
110
|
+
assert_equal(time, message.timestamp)
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_backtrace
|
114
|
+
# Create an error with a backtrace
|
115
|
+
error = TypeError.new
|
116
|
+
begin
|
117
|
+
raise error
|
118
|
+
rescue => e
|
119
|
+
error = e
|
120
|
+
end
|
121
|
+
|
122
|
+
# Backtrace can be passed via backtrace param or env
|
123
|
+
message = @store.report(Logger::WARN, "test", "A", backtrace: error.backtrace)
|
124
|
+
assert_equal(error.backtrace.join("\n"), message.backtrace)
|
125
|
+
message = @store.report(Logger::WARN, "test", "B", env: { backtrace: error.backtrace })
|
126
|
+
assert_equal(error.backtrace.join("\n"), message.backtrace)
|
127
|
+
|
128
|
+
# Via env takes priority
|
129
|
+
message = @store.report(Logger::WARN, "test", "C", backtrace: "Garbage", env: { backtrace: error.backtrace })
|
130
|
+
assert_equal(error.backtrace.join("\n"), message.backtrace)
|
131
|
+
|
132
|
+
# Backtrace is always a string
|
133
|
+
# Cannot do an equal assert here, because it uses `caller` when not provided
|
134
|
+
message = @store.report(Logger::WARN, "test", "D", backtrace: nil)
|
135
|
+
assert_kind_of(String, message.backtrace)
|
136
|
+
message = @store.report(Logger::WARN, "test", "E", env: { backtrace: nil })
|
137
|
+
assert_kind_of(String, message.backtrace)
|
138
|
+
message = @store.report(Logger::WARN, "test", "F", backtrace: nil, env: { backtrace: nil })
|
139
|
+
assert_kind_of(String, message.backtrace)
|
140
|
+
message = @store.report(Logger::WARN, "test", "G")
|
141
|
+
assert_kind_of(String, message.backtrace)
|
142
|
+
|
143
|
+
# Arrays are turned into strings via join \n
|
144
|
+
message = @store.report(Logger::WARN, "test", "H", backtrace: ["Foo", "Bar"])
|
145
|
+
assert_equal("Foo\nBar", message.backtrace)
|
146
|
+
end
|
147
|
+
end
|
@@ -1,34 +1,34 @@
|
|
1
|
-
require_relative '../test_helper'
|
2
|
-
require 'logster/defer_logger'
|
3
|
-
require 'logster/logger'
|
4
|
-
|
5
|
-
class TestDeferLogger < Minitest::Test
|
6
|
-
def setup
|
7
|
-
@store = TestStore.new
|
8
|
-
@defer_logger = Logster::DeferLogger.new(@store)
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_defer_logger_inherits_logger
|
12
|
-
assert(Logster::Logger === @defer_logger)
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_work_is_done_async
|
16
|
-
queue = Logster::Scheduler.queue
|
17
|
-
assert_equal(0, queue.size)
|
18
|
-
|
19
|
-
@defer_logger.add(4, "hi this a test", "prog")
|
20
|
-
|
21
|
-
assert_equal(1, queue.size)
|
22
|
-
queue << :terminate
|
23
|
-
Logster::Scheduler.thread.join
|
24
|
-
assert_equal(1, @store.calls.size)
|
25
|
-
|
26
|
-
# we need to make sure the backtrace is passed from the main thread.
|
27
|
-
# Otherwise we'd only get a partial backtrace from
|
28
|
-
# the point the new thread was spawned
|
29
|
-
backtrace = @store.calls.first[3][:backtrace]
|
30
|
-
assert_instance_of(Array, backtrace)
|
31
|
-
|
32
|
-
assert_equal(0, queue.size)
|
33
|
-
end
|
34
|
-
end
|
1
|
+
require_relative '../test_helper'
|
2
|
+
require 'logster/defer_logger'
|
3
|
+
require 'logster/logger'
|
4
|
+
|
5
|
+
class TestDeferLogger < Minitest::Test
|
6
|
+
def setup
|
7
|
+
@store = TestStore.new
|
8
|
+
@defer_logger = Logster::DeferLogger.new(@store)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_defer_logger_inherits_logger
|
12
|
+
assert(Logster::Logger === @defer_logger)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_work_is_done_async
|
16
|
+
queue = Logster::Scheduler.queue
|
17
|
+
assert_equal(0, queue.size)
|
18
|
+
|
19
|
+
@defer_logger.add(4, "hi this a test", "prog")
|
20
|
+
|
21
|
+
assert_equal(1, queue.size)
|
22
|
+
queue << :terminate
|
23
|
+
Logster::Scheduler.thread.join
|
24
|
+
assert_equal(1, @store.calls.size)
|
25
|
+
|
26
|
+
# we need to make sure the backtrace is passed from the main thread.
|
27
|
+
# Otherwise we'd only get a partial backtrace from
|
28
|
+
# the point the new thread was spawned
|
29
|
+
backtrace = @store.calls.first[3][:backtrace]
|
30
|
+
assert_instance_of(Array, backtrace)
|
31
|
+
|
32
|
+
assert_equal(0, queue.size)
|
33
|
+
end
|
34
|
+
end
|
@@ -1,41 +1,41 @@
|
|
1
|
-
require_relative '../test_helper'
|
2
|
-
require 'logster/ignore_pattern'
|
3
|
-
|
4
|
-
class TestIgnorePattern < Minitest::Test
|
5
|
-
|
6
|
-
def test_string_message_pattern
|
7
|
-
msg = Logster::Message.new(Logger::WARN, "test", "my error")
|
8
|
-
msg_frog = Logster::Message.new(Logger::WARN, "test", "a frog")
|
9
|
-
msg_nil = Logster::Message.new(Logger::WARN, "test", nil)
|
10
|
-
|
11
|
-
pattern = Logster::IgnorePattern.new("ERROR")
|
12
|
-
|
13
|
-
assert pattern.matches? msg
|
14
|
-
assert !pattern.matches?(msg_frog)
|
15
|
-
assert !pattern.matches?(msg_nil)
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_env_pattern
|
19
|
-
msg = Logster::Message.new(Logger::WARN, "test", "my error")
|
20
|
-
msg.env = { "frogs" => "are big" }
|
21
|
-
|
22
|
-
pattern = Logster::IgnorePattern.new(nil, frogs: "big")
|
23
|
-
|
24
|
-
assert pattern.matches? msg
|
25
|
-
|
26
|
-
msg.env = { legs: nil }
|
27
|
-
assert !(pattern.matches? msg)
|
28
|
-
|
29
|
-
msg.env = { legs: 3 }
|
30
|
-
assert !(pattern.matches? msg)
|
31
|
-
|
32
|
-
msg.env = { frogs: "small" }
|
33
|
-
assert !pattern.matches?(msg)
|
34
|
-
|
35
|
-
pattern = Logster::IgnorePattern.new(nil, "small")
|
36
|
-
assert pattern.matches? msg
|
37
|
-
|
38
|
-
msg.env = { frogs: "big" }
|
39
|
-
assert !(pattern.matches? msg)
|
40
|
-
end
|
41
|
-
end
|
1
|
+
require_relative '../test_helper'
|
2
|
+
require 'logster/ignore_pattern'
|
3
|
+
|
4
|
+
class TestIgnorePattern < Minitest::Test
|
5
|
+
|
6
|
+
def test_string_message_pattern
|
7
|
+
msg = Logster::Message.new(Logger::WARN, "test", "my error")
|
8
|
+
msg_frog = Logster::Message.new(Logger::WARN, "test", "a frog")
|
9
|
+
msg_nil = Logster::Message.new(Logger::WARN, "test", nil)
|
10
|
+
|
11
|
+
pattern = Logster::IgnorePattern.new("ERROR")
|
12
|
+
|
13
|
+
assert pattern.matches? msg
|
14
|
+
assert !pattern.matches?(msg_frog)
|
15
|
+
assert !pattern.matches?(msg_nil)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_env_pattern
|
19
|
+
msg = Logster::Message.new(Logger::WARN, "test", "my error")
|
20
|
+
msg.env = { "frogs" => "are big" }
|
21
|
+
|
22
|
+
pattern = Logster::IgnorePattern.new(nil, frogs: "big")
|
23
|
+
|
24
|
+
assert pattern.matches? msg
|
25
|
+
|
26
|
+
msg.env = { legs: nil }
|
27
|
+
assert !(pattern.matches? msg)
|
28
|
+
|
29
|
+
msg.env = { legs: 3 }
|
30
|
+
assert !(pattern.matches? msg)
|
31
|
+
|
32
|
+
msg.env = { frogs: "small" }
|
33
|
+
assert !pattern.matches?(msg)
|
34
|
+
|
35
|
+
pattern = Logster::IgnorePattern.new(nil, "small")
|
36
|
+
assert pattern.matches? msg
|
37
|
+
|
38
|
+
msg.env = { frogs: "big" }
|
39
|
+
assert !(pattern.matches? msg)
|
40
|
+
end
|
41
|
+
end
|
data/test/logster/test_logger.rb
CHANGED
@@ -1,86 +1,86 @@
|
|
1
|
-
require_relative '../test_helper'
|
2
|
-
require 'logster/logger'
|
3
|
-
require 'logger'
|
4
|
-
|
5
|
-
class TestStore
|
6
|
-
attr_accessor :calls
|
7
|
-
|
8
|
-
def report(*args)
|
9
|
-
(@calls ||= []) << args
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
class TestLogger < Minitest::Test
|
14
|
-
|
15
|
-
def setup
|
16
|
-
@store = TestStore.new
|
17
|
-
@logger = Logster::Logger.new(@store)
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_only_logs_valid_encoding
|
21
|
-
@logger.add(4, "a \xE4 test", "prog")
|
22
|
-
_, _, message = @store.calls[0]
|
23
|
-
assert_equal true, message.valid_encoding?
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_per_thread_override
|
27
|
-
@logger.override_level = 2
|
28
|
-
|
29
|
-
@logger.add(0, "test", "prog", backtrace: "backtrace", env: { a: "x" })
|
30
|
-
Thread.new do
|
31
|
-
@logger.add(0, "test", "prog", backtrace: "backtrace", env: { a: "x" })
|
32
|
-
end.join
|
33
|
-
|
34
|
-
@logger.override_level = nil
|
35
|
-
@logger.add(0, "test", "prog", backtrace: "backtrace", env: { a: "x" })
|
36
|
-
|
37
|
-
assert_equal 2, @store.calls.length
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_backtrace
|
41
|
-
@logger.add(0, "test", "prog", backtrace: "backtrace", env: { a: "x" })
|
42
|
-
assert_equal "backtrace", @store.calls[0][3][:backtrace]
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_chain
|
46
|
-
io = StringIO.new
|
47
|
-
@logger.chain Logger.new(io)
|
48
|
-
@logger.warn "boom"
|
49
|
-
|
50
|
-
assert_match(/W,.*boom/, io.string)
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_backtrace_with_chain
|
54
|
-
@other_store = TestStore.new
|
55
|
-
@logger.chain(Logster::Logger.new(@other_store))
|
56
|
-
|
57
|
-
@logger.add(0, "test", "prog", backtrace: "backtrace", env: { a: "x" })
|
58
|
-
|
59
|
-
[@store, @other_store].each do |store|
|
60
|
-
assert_equal "backtrace", store.calls[0][3][:backtrace]
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_progname_parameter
|
65
|
-
@logger.add(0, "test")
|
66
|
-
progname = @store.calls[0][1]
|
67
|
-
assert_nil progname
|
68
|
-
end
|
69
|
-
|
70
|
-
class PlayLogger
|
71
|
-
attr_accessor :skip_store
|
72
|
-
def initialize(tester)
|
73
|
-
@tester = tester
|
74
|
-
end
|
75
|
-
|
76
|
-
def add(s, m, p, &block)
|
77
|
-
@tester.assert(skip_store)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_chain_with_ignore
|
82
|
-
@logger.chain PlayLogger.new(self)
|
83
|
-
@logger.skip_store = true
|
84
|
-
@logger.warn("testing")
|
85
|
-
end
|
86
|
-
end
|
1
|
+
require_relative '../test_helper'
|
2
|
+
require 'logster/logger'
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
class TestStore
|
6
|
+
attr_accessor :calls
|
7
|
+
|
8
|
+
def report(*args)
|
9
|
+
(@calls ||= []) << args
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class TestLogger < Minitest::Test
|
14
|
+
|
15
|
+
def setup
|
16
|
+
@store = TestStore.new
|
17
|
+
@logger = Logster::Logger.new(@store)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_only_logs_valid_encoding
|
21
|
+
@logger.add(4, "a \xE4 test", "prog")
|
22
|
+
_, _, message = @store.calls[0]
|
23
|
+
assert_equal true, message.valid_encoding?
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_per_thread_override
|
27
|
+
@logger.override_level = 2
|
28
|
+
|
29
|
+
@logger.add(0, "test", "prog", backtrace: "backtrace", env: { a: "x" })
|
30
|
+
Thread.new do
|
31
|
+
@logger.add(0, "test", "prog", backtrace: "backtrace", env: { a: "x" })
|
32
|
+
end.join
|
33
|
+
|
34
|
+
@logger.override_level = nil
|
35
|
+
@logger.add(0, "test", "prog", backtrace: "backtrace", env: { a: "x" })
|
36
|
+
|
37
|
+
assert_equal 2, @store.calls.length
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_backtrace
|
41
|
+
@logger.add(0, "test", "prog", backtrace: "backtrace", env: { a: "x" })
|
42
|
+
assert_equal "backtrace", @store.calls[0][3][:backtrace]
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_chain
|
46
|
+
io = StringIO.new
|
47
|
+
@logger.chain Logger.new(io)
|
48
|
+
@logger.warn "boom"
|
49
|
+
|
50
|
+
assert_match(/W,.*boom/, io.string)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_backtrace_with_chain
|
54
|
+
@other_store = TestStore.new
|
55
|
+
@logger.chain(Logster::Logger.new(@other_store))
|
56
|
+
|
57
|
+
@logger.add(0, "test", "prog", backtrace: "backtrace", env: { a: "x" })
|
58
|
+
|
59
|
+
[@store, @other_store].each do |store|
|
60
|
+
assert_equal "backtrace", store.calls[0][3][:backtrace]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_progname_parameter
|
65
|
+
@logger.add(0, "test")
|
66
|
+
progname = @store.calls[0][1]
|
67
|
+
assert_nil progname
|
68
|
+
end
|
69
|
+
|
70
|
+
class PlayLogger
|
71
|
+
attr_accessor :skip_store
|
72
|
+
def initialize(tester)
|
73
|
+
@tester = tester
|
74
|
+
end
|
75
|
+
|
76
|
+
def add(s, m, p, &block)
|
77
|
+
@tester.assert(skip_store)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_chain_with_ignore
|
82
|
+
@logger.chain PlayLogger.new(self)
|
83
|
+
@logger.skip_store = true
|
84
|
+
@logger.warn("testing")
|
85
|
+
end
|
86
|
+
end
|