elasticelmah 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/elasticelmah.rb +23 -2
- data/tests/elasticelmah_tests.rb +3 -0
- metadata +1 -1
data/lib/elasticelmah.rb
CHANGED
@@ -45,7 +45,7 @@ module ElasticElmah
|
|
45
45
|
return {
|
46
46
|
loggerName:l.name,
|
47
47
|
level: Log4r::LNAMES[l.level],
|
48
|
-
message: l
|
48
|
+
message: get_message_of(l),
|
49
49
|
threadName:"",
|
50
50
|
timeStamp:time_stamp,
|
51
51
|
locationInfo:{
|
@@ -56,7 +56,7 @@ module ElasticElmah
|
|
56
56
|
},
|
57
57
|
userName:"",
|
58
58
|
properties:{},
|
59
|
-
exceptionString: l
|
59
|
+
exceptionString: get_exception_string_of(l),
|
60
60
|
domain:"",
|
61
61
|
identity:""
|
62
62
|
}
|
@@ -65,6 +65,27 @@ module ElasticElmah
|
|
65
65
|
#######
|
66
66
|
private
|
67
67
|
#######
|
68
|
+
def get_message_of(l)
|
69
|
+
if l.data != nil && l.data.respond_to?(:message)
|
70
|
+
return l.data.message.to_s
|
71
|
+
else
|
72
|
+
return l.data.to_s
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def get_exception_string_of(l)
|
77
|
+
if l.tracer!=nil
|
78
|
+
return l.tracer.join("\n")
|
79
|
+
end
|
80
|
+
if l.data!=nil && l.data.respond_to?(:backtrace)
|
81
|
+
backtrace = l.data.backtrace
|
82
|
+
if backtrace != nil
|
83
|
+
return backtrace.join("\n")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
return ""
|
87
|
+
end
|
88
|
+
|
68
89
|
def create_index
|
69
90
|
@client.indices.create(index: @index, body: {
|
70
91
|
settings: {
|
data/tests/elasticelmah_tests.rb
CHANGED
@@ -49,16 +49,19 @@ class TestElasticElmahOutputterForReal < Test::Unit::TestCase
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def test_generated_from_logging_event_data
|
52
|
+
error = nil
|
52
53
|
begin
|
53
54
|
raise 'some_error'
|
54
55
|
rescue Exception => e
|
55
56
|
@logger.error(e)
|
57
|
+
error = e
|
56
58
|
end
|
57
59
|
@client.indices.flush(index: @index )
|
58
60
|
result = @client.search index: @index
|
59
61
|
assert_equal 1, result["hits"]["hits"].length
|
60
62
|
hits = result["hits"]["hits"]
|
61
63
|
assert_equal 'some_error', hits[0]["_source"]["message"]
|
64
|
+
assert_equal error.backtrace.join("\n"), hits[0]["_source"]["exceptionString"]
|
62
65
|
end
|
63
66
|
end
|
64
67
|
|