structured_log 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +27 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +620 -0
- data/Rakefile +44 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/images/array.jpg +0 -0
- data/images/attributes.png +0 -0
- data/images/comment.png +0 -0
- data/images/custom.png +0 -0
- data/images/data.png +0 -0
- data/images/exception.png +0 -0
- data/images/hash.png +0 -0
- data/images/nesting.jpg +0 -0
- data/images/potpourri.png +0 -0
- data/images/rescue.jpg +0 -0
- data/images/structured.png +0 -0
- data/images/text.jpg +0 -0
- data/images/time.png +0 -0
- data/lib/structured_log.rb +322 -0
- data/lib/structured_log/version.rb +3 -0
- data/readme_files/README.template.md +167 -0
- data/readme_files/logs/array.xml +10 -0
- data/readme_files/logs/attributes.xml +7 -0
- data/readme_files/logs/cdata.xml +12 -0
- data/readme_files/logs/comment.xml +5 -0
- data/readme_files/logs/custom_entry.xml +12 -0
- data/readme_files/logs/custom_section.xml +14 -0
- data/readme_files/logs/data.xml +20 -0
- data/readme_files/logs/exception.xml +14 -0
- data/readme_files/logs/hash.xml +10 -0
- data/readme_files/logs/potpourri.xml +13 -0
- data/readme_files/logs/potpourri_other.xml +20 -0
- data/readme_files/logs/potpourri_usual.xml +8 -0
- data/readme_files/logs/rescue.xml +28 -0
- data/readme_files/logs/sections.xml +7 -0
- data/readme_files/logs/text.xml +5 -0
- data/readme_files/logs/time.xml +17 -0
- data/readme_files/scripts/array.rb +6 -0
- data/readme_files/scripts/attributes.rb +8 -0
- data/readme_files/scripts/cdata.rb +17 -0
- data/readme_files/scripts/comment.rb +5 -0
- data/readme_files/scripts/custom_entry.rb +10 -0
- data/readme_files/scripts/custom_section.rb +15 -0
- data/readme_files/scripts/data.rb +16 -0
- data/readme_files/scripts/exception.rb +5 -0
- data/readme_files/scripts/hash.rb +11 -0
- data/readme_files/scripts/potpourri.rb +20 -0
- data/readme_files/scripts/potpourri_other.rb +17 -0
- data/readme_files/scripts/potpourri_usual.rb +12 -0
- data/readme_files/scripts/rescue.rb +12 -0
- data/readme_files/scripts/sections.rb +17 -0
- data/readme_files/scripts/text.rb +8 -0
- data/readme_files/scripts/time.rb +15 -0
- data/structured_log.gemspec +38 -0
- metadata +176 -0
@@ -0,0 +1,12 @@
|
|
1
|
+
<log>
|
2
|
+
<![CDATA[
|
3
|
+
Method put_cdata puts the data verbatim:
|
4
|
+
|
5
|
+
* Nothing is added or subtracted.
|
6
|
+
* Not even whitespace.
|
7
|
+
|
8
|
+
So you can use the method to log a formatted string.
|
9
|
+
|
10
|
+
(You'll need to add your own leading and trailing newlines, if desired.)
|
11
|
+
]]>
|
12
|
+
</log>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<log>
|
2
|
+
<section name='Without blocks'>
|
3
|
+
<element_with_text>
|
4
|
+
No child elements, just this text.
|
5
|
+
</element_with_text>
|
6
|
+
<element_with_attributes a='0' b='1'/>
|
7
|
+
<element_with_timestamp timestamp='2018-06-09-Sat-11.38.09.357'/>
|
8
|
+
<element_with_data>
|
9
|
+
3.14159
|
10
|
+
</element_with_data>
|
11
|
+
</section>
|
12
|
+
</log>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<log>
|
2
|
+
<section name='With blocks'>
|
3
|
+
<section_with_children>
|
4
|
+
<child rank='Older'/>
|
5
|
+
<child rank='Younger'/>
|
6
|
+
</section_with_children>
|
7
|
+
<section_with_duration duration_seconds='1.016'>
|
8
|
+
Block contains timed code to be timed.
|
9
|
+
</section_with_duration>
|
10
|
+
<section_with_rescue>
|
11
|
+
Block contains code to be rescued if necessary.
|
12
|
+
</section_with_rescue>
|
13
|
+
</section>
|
14
|
+
</log>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<log>
|
2
|
+
<data name='my_float' class='Float'>
|
3
|
+
<![CDATA[3.14]]>
|
4
|
+
</data>
|
5
|
+
<data name='my_fixnum' class='Fixnum'>
|
6
|
+
<![CDATA[1066]]>
|
7
|
+
</data>
|
8
|
+
<data name='my_false' class='FalseClass'>
|
9
|
+
<![CDATA[false]]>
|
10
|
+
</data>
|
11
|
+
<data name='my_time' class='Time'>
|
12
|
+
<![CDATA[2018-06-09 11:38:10 -0500]]>
|
13
|
+
</data>
|
14
|
+
<data name='my_exception' class='RuntimeError'>
|
15
|
+
<![CDATA[#<RuntimeError: Oops!>]]>
|
16
|
+
</data>
|
17
|
+
<data name='my_nil' class='NilClass'>
|
18
|
+
<![CDATA[nil]]>
|
19
|
+
</data>
|
20
|
+
</log>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<log>
|
2
|
+
<uncaught_exception timestamp='2018-06-09-Sat-11.38.10.967' class='RuntimeError'>
|
3
|
+
<message>
|
4
|
+
Oops!
|
5
|
+
</message>
|
6
|
+
<backtrace>
|
7
|
+
<![CDATA[
|
8
|
+
C:/Users/Burdette/Documents/GitHub/structured_log/readme_files/scripts/exception.rb:4:in `block in <main>'
|
9
|
+
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/structured_log-0.1.0/lib/structured_log.rb:38:in `open'
|
10
|
+
C:/Users/Burdette/Documents/GitHub/structured_log/readme_files/scripts/exception.rb:3:in `<main>'
|
11
|
+
]]>
|
12
|
+
</backtrace>
|
13
|
+
</uncaught_exception>
|
14
|
+
</log>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<log>
|
2
|
+
<section name='All together now'>
|
3
|
+
Order does not matter except in aggregating text and attributes.
|
4
|
+
<section name='Potpourri' a='0' b='1' c='2' d='3' timestamp='2018-06-09-Sat-11.38.11.279' duration_seconds='0.000'>
|
5
|
+
This section has a potpourri.3.14159false10662018-06-09 11:38:11
|
6
|
+
-0500#<RuntimeError: Oops!>
|
7
|
+
</section>
|
8
|
+
<section name='Reverse potpourri' timestamp='2018-06-09-Sat-11.38.11.279' c='2' d='3' a='0' b='1' duration_seconds='0.000'>
|
9
|
+
#<RuntimeError: Oops!>2018-06-09 11:38:11 -05001066false3.14159This
|
10
|
+
section has a potpourri.
|
11
|
+
</section>
|
12
|
+
</section>
|
13
|
+
</log>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<log>
|
2
|
+
<section name='Others'>
|
3
|
+
Other values are logged as the string returned by value.inspect.
|
4
|
+
<section name='Log instance of Float'>
|
5
|
+
3.14159
|
6
|
+
</section>
|
7
|
+
<section name='Log instance of FalseClass'>
|
8
|
+
false
|
9
|
+
</section>
|
10
|
+
<section name='Log instance of Fixnum'>
|
11
|
+
1066
|
12
|
+
</section>
|
13
|
+
<section name='Log instance of Time'>
|
14
|
+
2018-06-09 11:38:11 -0500
|
15
|
+
</section>
|
16
|
+
<section name='Log instance of RuntimeError'>
|
17
|
+
#<RuntimeError: Oops!>
|
18
|
+
</section>
|
19
|
+
</section>
|
20
|
+
</log>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<log>
|
2
|
+
<section name='The usual'>
|
3
|
+
Mixed hash, string, and special symbols are logged as usual.
|
4
|
+
<section name='Potpourri' a='0' b='1' timestamp='2018-06-09-Sat-11.38.11.670' duration_seconds='1.016'>
|
5
|
+
This section has a potpourri.
|
6
|
+
</section>
|
7
|
+
</section>
|
8
|
+
</log>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
<log>
|
2
|
+
<section name='Section with rescue'>
|
3
|
+
<comment>
|
4
|
+
This section will terminate because of the failure.
|
5
|
+
</comment>
|
6
|
+
<rescued_exception timestamp='2018-06-09-Sat-11.38.12.889' class='RuntimeError'>
|
7
|
+
<message>
|
8
|
+
This exception will be rescued and logged.
|
9
|
+
</message>
|
10
|
+
<backtrace>
|
11
|
+
<![CDATA[
|
12
|
+
C:/Users/Burdette/Documents/GitHub/structured_log/readme_files/scripts/rescue.rb:6:in `block (2 levels) in <main>'
|
13
|
+
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/structured_log-0.1.0/lib/structured_log.rb:58:in `block in section'
|
14
|
+
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/structured_log-0.1.0/lib/structured_log.rb:116:in `put_element'
|
15
|
+
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/structured_log-0.1.0/lib/structured_log.rb:57:in `section'
|
16
|
+
C:/Users/Burdette/Documents/GitHub/structured_log/readme_files/scripts/rescue.rb:4:in `block in <main>'
|
17
|
+
C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/structured_log-0.1.0/lib/structured_log.rb:38:in `open'
|
18
|
+
C:/Users/Burdette/Documents/GitHub/structured_log/readme_files/scripts/rescue.rb:3:in `<main>'
|
19
|
+
]]>
|
20
|
+
</backtrace>
|
21
|
+
</rescued_exception>
|
22
|
+
</section>
|
23
|
+
<section name='Another section'>
|
24
|
+
<comment>
|
25
|
+
This comment will be reached and logged, because of rescue above.
|
26
|
+
</comment>
|
27
|
+
</section>
|
28
|
+
</log>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<log>
|
2
|
+
<section name='Section with timestamp' timestamp='2018-06-09-Sat-11.38.13.373'>
|
3
|
+
<comment>
|
4
|
+
This section has a timestamp.
|
5
|
+
</comment>
|
6
|
+
</section>
|
7
|
+
<section name='Section with duration' duration_seconds='1.016'>
|
8
|
+
<comment>
|
9
|
+
This section has a duration.
|
10
|
+
</comment>
|
11
|
+
</section>
|
12
|
+
<section name='Section with both' timestamp='2018-06-09-Sat-11.38.14.389' duration_seconds='1.000'>
|
13
|
+
<comment>
|
14
|
+
This section has both.
|
15
|
+
</comment>
|
16
|
+
</section>
|
17
|
+
</log>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'structured_log'
|
2
|
+
|
3
|
+
text = <<EOT
|
4
|
+
|
5
|
+
Method put_cdata puts the data verbatim:
|
6
|
+
|
7
|
+
* Nothing is added or subtracted.
|
8
|
+
* Not even whitespace.
|
9
|
+
|
10
|
+
So you can use the method to log a formatted string.
|
11
|
+
|
12
|
+
(You'll need to add your own leading and trailing newlines, if desired.)
|
13
|
+
|
14
|
+
EOT
|
15
|
+
StructuredLog.open('cdata.xml') do |log|
|
16
|
+
log.put_cdata(text)
|
17
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'structured_log'
|
2
|
+
|
3
|
+
StructuredLog.open('custom_entry.xml') do |log|
|
4
|
+
log.section('Without blocks') do
|
5
|
+
log.put_element('element_with_text', 'No child elements, just this text.')
|
6
|
+
log.put_element('element_with_attributes', {:a => 0, :b => 1})
|
7
|
+
log.put_element('element_with_timestamp', :timestamp)
|
8
|
+
log.put_element('element_with_data', 3.14159)
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'structured_log'
|
2
|
+
|
3
|
+
StructuredLog.open('custom_section.xml') do |log|
|
4
|
+
log.section('With blocks') do
|
5
|
+
log.put_element('section_with_children') do
|
6
|
+
log.put_element('child', :rank => 'Older')
|
7
|
+
log.put_element('child', :rank => 'Younger')
|
8
|
+
end
|
9
|
+
log.put_element('section_with_duration', :duration, 'Block contains timed code to be timed.') do
|
10
|
+
sleep 1
|
11
|
+
end
|
12
|
+
log.put_element('section_with_rescue', :rescue, 'Block contains code to be rescued if necessary.') do
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'structured_log'
|
2
|
+
|
3
|
+
data = {
|
4
|
+
:float => 3.14,
|
5
|
+
:fixnum => 1066,
|
6
|
+
:false => false,
|
7
|
+
:time => Time.new,
|
8
|
+
:exception => RuntimeError.new('Oops!'),
|
9
|
+
:nil => nil,
|
10
|
+
}
|
11
|
+
StructuredLog.open('data.xml') do |log|
|
12
|
+
data.each_pair do |type, datum|
|
13
|
+
name = "my_#{type}"
|
14
|
+
log.put_data(name, datum)
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'structured_log'
|
2
|
+
|
3
|
+
attributes = {:a => 0, :b => 1}
|
4
|
+
more_attributes = {:c => 2, :d => 3}
|
5
|
+
text = 'This section has a potpourri.'
|
6
|
+
float = 3.14159
|
7
|
+
boolean = false
|
8
|
+
fixnum = 1066
|
9
|
+
time = Time.new
|
10
|
+
exception = RuntimeError.new('Oops!')
|
11
|
+
|
12
|
+
StructuredLog.open('potpourri.xml') do |log|
|
13
|
+
log.section('All together now', 'Order does not matter except in aggregating text and attributes.') do
|
14
|
+
args = [attributes, :rescue, text, float, :duration, more_attributes, boolean, :timestamp, fixnum, time, exception]
|
15
|
+
log.section('Potpourri', *args) do
|
16
|
+
end
|
17
|
+
log.section('Reverse potpourri', *args.reverse) do
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'structured_log'
|
2
|
+
|
3
|
+
float = 3.14159
|
4
|
+
boolean = false
|
5
|
+
fixnum = 1066
|
6
|
+
time = Time.new
|
7
|
+
exception = RuntimeError.new('Oops!')
|
8
|
+
|
9
|
+
StructuredLog.open('potpourri_other.xml') do |log|
|
10
|
+
log.section('Others', 'Other values are logged as the string returned by value.inspect.')do
|
11
|
+
[float, boolean, fixnum, time, exception].each do |value|
|
12
|
+
element_name = "Log instance of #{value.class}"
|
13
|
+
log.section(element_name, value) do
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'structured_log'
|
2
|
+
|
3
|
+
attributes = {:a => 0, :b => 1}
|
4
|
+
text = 'This section has a potpourri.'
|
5
|
+
|
6
|
+
StructuredLog.open('potpourri_usual.xml') do |log|
|
7
|
+
log.section('The usual', 'Mixed hash, string, and special symbols are logged as usual.') do
|
8
|
+
log.section('Potpourri', attributes, text, :timestamp, :duration, :rescue) do
|
9
|
+
sleep 1
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'structured_log'
|
2
|
+
|
3
|
+
StructuredLog.open('rescue.xml') do |log|
|
4
|
+
log.section('Section with rescue', :rescue) do
|
5
|
+
log.comment('This section will terminate because of the failure.')
|
6
|
+
fail 'This exception will be rescued and logged.'
|
7
|
+
log.comment('This comment will not be reached.')
|
8
|
+
end
|
9
|
+
log.section('Another section') do
|
10
|
+
log.comment('This comment will be reached and logged, because of rescue above.')
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'structured_log'
|
2
|
+
|
3
|
+
StructuredLog.open('sections.xml') do |log|
|
4
|
+
# Any code can be here.
|
5
|
+
log.section('Outer') do
|
6
|
+
# Any code can be here.
|
7
|
+
log.section('Mid') do
|
8
|
+
# Any code can be here.
|
9
|
+
log.section('Inner') do
|
10
|
+
# Any code can be here.
|
11
|
+
end
|
12
|
+
# Any code can be here.
|
13
|
+
end
|
14
|
+
# Any code can be here.
|
15
|
+
end
|
16
|
+
# Any code can be here.
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'structured_log'
|
2
|
+
|
3
|
+
StructuredLog.open('time.xml') do |log|
|
4
|
+
log.section('Section with timestamp', :timestamp) do
|
5
|
+
log.comment('This section has a timestamp.')
|
6
|
+
end
|
7
|
+
log.section('Section with duration', :duration) do
|
8
|
+
log.comment('This section has a duration.')
|
9
|
+
sleep 1
|
10
|
+
end
|
11
|
+
log.section('Section with both', :duration, :timestamp) do
|
12
|
+
log.comment('This section has both.')
|
13
|
+
sleep 1
|
14
|
+
end
|
15
|
+
end
|