logue 1.0.18 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +0 -0
- data/.glarkrc +0 -0
- data/.idea/.gitignore +10 -0
- data/.idea/aws.xml +11 -0
- data/.idea/codeStyles/Project.xml +7 -0
- data/.idea/codeStyles/codeStyleConfig.xml +5 -0
- data/.idea/inspectionProfiles/Project_Default.xml +11 -0
- data/.idea/libraries/pkg.xml +16 -0
- data/.idea/logue.iml +53 -0
- data/.idea/misc.xml +9 -0
- data/.idea/modules.xml +8 -0
- data/.idea/vcs.xml +6 -0
- data/Gemfile +0 -0
- data/Gemfile.lock +8 -8
- data/LICENSE.txt +0 -0
- data/README.md +0 -0
- data/lib/logue/{colorlog.rb → colorable.rb} +6 -27
- data/lib/logue/core/applog.rb +18 -0
- data/lib/logue/core/base_loggable.rb +58 -0
- data/lib/logue/core/base_writer.rb +23 -0
- data/lib/logue/core/dynamic.rb +17 -0
- data/lib/logue/core/object_util.rb +6 -0
- data/lib/logue/elements/base_element.rb +21 -0
- data/lib/logue/elements/block_element.rb +16 -0
- data/lib/logue/elements/element.rb +13 -0
- data/lib/logue/elements/element_factory.rb +50 -0
- data/lib/logue/elements/element_lines.rb +23 -0
- data/lib/logue/elements/elements_log.rb +21 -0
- data/lib/logue/elements/elements_loggable.rb +17 -0
- data/lib/logue/elements/elements_writer.rb +33 -0
- data/lib/logue/elements/enum_element.rb +12 -0
- data/lib/logue/elements/hash_element.rb +9 -0
- data/lib/logue/elements/indexed_element.rb +15 -0
- data/lib/logue/elements/msg_element.rb +13 -0
- data/lib/logue/elements/msg_obj_element.rb +13 -0
- data/lib/logue/elements/struct_element.rb +9 -0
- data/lib/logue/elements/verbose_element.rb +18 -0
- data/lib/logue/filter.rb +8 -49
- data/lib/logue/{location_format.rb → format/location_format.rb} +16 -11
- data/lib/logue/format/pathutil.rb +36 -0
- data/lib/logue/legacy_logger.rb +7 -18
- data/lib/logue/level.rb +0 -11
- data/lib/logue/levels/level_logger.rb +55 -0
- data/lib/logue/lines/line_base.rb +4 -0
- data/lib/logue/lines/line_block.rb +11 -0
- data/lib/logue/lines/line_msg_block.rb +12 -0
- data/lib/logue/lines/line_msg_obj.rb +19 -0
- data/lib/logue/lines/lines_factory.rb +19 -0
- data/lib/logue/lines/lines_writer.rb +29 -0
- data/lib/logue/locations/frame.rb +19 -0
- data/lib/logue/locations/location.rb +17 -0
- data/lib/logue/locations/location_writer.rb +13 -0
- data/lib/logue/{stack.rb → locations/stack.rb} +5 -7
- data/lib/logue/log.rb +27 -60
- data/lib/logue/loggable.rb +4 -20
- data/lib/logue/logger.rb +28 -81
- data/lib/logue/version.rb +1 -4
- data/lib/logue/writer.rb +2 -31
- data/lib/logue/writer2.rb +5 -0
- data/lib/logue.rb +3 -3
- data/logue.gemspec +3 -3
- metadata +58 -22
- data/lib/logue/element.rb +0 -16
- data/lib/logue/frame.rb +0 -37
- data/lib/logue/line.rb +0 -44
- data/lib/logue/location.rb +0 -24
- data/lib/logue/pathutil.rb +0 -39
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 9f60d8d9300dafd78cc242301c85454bef6739f7dad2b2a663dc7d8a3b3f9615
|
|
4
|
+
data.tar.gz: fc01ceb406615d287d83aecefc4975fb4cbade6220d54239a45525c78bc10eb4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d1adb9e5af42ff364a21ce3edbdb7270b7cd60a5164e2342781aa1ac32dabd151bae608e6726c84d3ecb08cc1838e51cf64149fc2ca8249309a8b148d1a12892
|
|
7
|
+
data.tar.gz: a6d621ea51c8072d538fbd9311aa491cbc34abbf389527d223c45c6c57e81ff292a23a3a0350ec663f17a1180284711c152229ec6b1814dad0688fe78a77e439
|
data/.gitignore
CHANGED
|
File without changes
|
data/.glarkrc
CHANGED
|
File without changes
|
data/.idea/.gitignore
ADDED
data/.idea/aws.xml
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="accountSettings">
|
|
4
|
+
<option name="activeRegion" value="us-east-1" />
|
|
5
|
+
<option name="recentlyUsedRegions">
|
|
6
|
+
<list>
|
|
7
|
+
<option value="us-east-1" />
|
|
8
|
+
</list>
|
|
9
|
+
</option>
|
|
10
|
+
</component>
|
|
11
|
+
</project>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<component name="InspectionProjectProfileManager">
|
|
2
|
+
<profile version="1.0">
|
|
3
|
+
<option name="myName" value="Project Default" />
|
|
4
|
+
<inspection_tool class="RubyDefParenthesesInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
|
5
|
+
<inspection_tool class="SpellCheckingInspection" enabled="true" level="TYPO" enabled_by_default="true">
|
|
6
|
+
<option name="processCode" value="false" />
|
|
7
|
+
<option name="processLiterals" value="false" />
|
|
8
|
+
<option name="processComments" value="true" />
|
|
9
|
+
</inspection_tool>
|
|
10
|
+
</profile>
|
|
11
|
+
</component>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<component name="libraryTable">
|
|
2
|
+
<library name="pkg">
|
|
3
|
+
<CLASSES>
|
|
4
|
+
<root url="jar://$PROJECT_DIR$/pkg/logue-1.0.3.zip!/" />
|
|
5
|
+
<root url="jar://$PROJECT_DIR$/pkg/logue-1.0.0.zip!/" />
|
|
6
|
+
<root url="jar://$PROJECT_DIR$/pkg/logue-1.0.2.zip!/" />
|
|
7
|
+
<root url="jar://$PROJECT_DIR$/pkg/logue-1.0.1.zip!/" />
|
|
8
|
+
<root url="jar://$PROJECT_DIR$/pkg/logue-1.0.7.zip!/" />
|
|
9
|
+
<root url="jar://$PROJECT_DIR$/pkg/logue-1.0.8.zip!/" />
|
|
10
|
+
<root url="jar://$PROJECT_DIR$/pkg/logue-0.0.1.zip!/" />
|
|
11
|
+
<root url="jar://$PROJECT_DIR$/pkg/logue-1.0.6.zip!/" />
|
|
12
|
+
</CLASSES>
|
|
13
|
+
<JAVADOC />
|
|
14
|
+
<SOURCES />
|
|
15
|
+
</library>
|
|
16
|
+
</component>
|
data/.idea/logue.iml
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
|
3
|
+
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
4
|
+
<exclude-output />
|
|
5
|
+
<content url="file://$MODULE_DIR$">
|
|
6
|
+
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
|
|
7
|
+
<sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
|
|
8
|
+
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
|
|
9
|
+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
|
10
|
+
<excludeFolder url="file://$MODULE_DIR$/pkg" />
|
|
11
|
+
</content>
|
|
12
|
+
<orderEntry type="inheritedJdk" />
|
|
13
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
14
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v2.1.4, RVM: ruby-2.4.10) [gem]" level="application" />
|
|
15
|
+
<orderEntry type="library" scope="PROVIDED" name="paramesan (v0.1.1, RVM: ruby-2.4.10) [gem]" level="application" />
|
|
16
|
+
<orderEntry type="library" scope="PROVIDED" name="power_assert (v3.0.1, RVM: ruby-2.4.10) [gem]" level="application" />
|
|
17
|
+
<orderEntry type="library" scope="PROVIDED" name="rainbow (v3.0.0, RVM: ruby-2.4.10) [gem]" level="application" />
|
|
18
|
+
<orderEntry type="library" scope="PROVIDED" name="rake (v13.0.6, RVM: ruby-2.4.10) [gem]" level="application" />
|
|
19
|
+
<orderEntry type="library" scope="PROVIDED" name="test-unit (v3.6.1, RVM: ruby-2.4.10) [gem]" level="application" />
|
|
20
|
+
</component>
|
|
21
|
+
<component name="RModuleSettingsStorage">
|
|
22
|
+
<LOAD_PATH number="2" string0="$MODULE_DIR$" string1="$MODULE_DIR$/test" />
|
|
23
|
+
<I18N_FOLDERS number="0" />
|
|
24
|
+
</component>
|
|
25
|
+
<component name="RakeTasksCache">
|
|
26
|
+
<option name="myRootTask">
|
|
27
|
+
<RakeTaskImpl id="rake">
|
|
28
|
+
<subtasks>
|
|
29
|
+
<RakeTaskImpl description="Build logue-1.0.19.gem into the pkg directory" fullCommand="build" id="build" />
|
|
30
|
+
<RakeTaskImpl description="Remove any temporary products" fullCommand="clean" id="clean" />
|
|
31
|
+
<RakeTaskImpl description="Remove any generated files" fullCommand="clobber" id="clobber" />
|
|
32
|
+
<RakeTaskImpl description="Build and install logue-1.0.19.gem into system gems" fullCommand="install" id="install" />
|
|
33
|
+
<RakeTaskImpl id="install">
|
|
34
|
+
<subtasks>
|
|
35
|
+
<RakeTaskImpl description="Build and install logue-1.0.19.gem into system gems without network access" fullCommand="install:local" id="local" />
|
|
36
|
+
</subtasks>
|
|
37
|
+
</RakeTaskImpl>
|
|
38
|
+
<RakeTaskImpl description="Create tag v1.0.19 and build and push logue-1.0.19.gem to https://rubygems.org" fullCommand="release[remote]" id="release[remote]" />
|
|
39
|
+
<RakeTaskImpl description="Run tests" fullCommand="test" id="test" />
|
|
40
|
+
<RakeTaskImpl description="" fullCommand="default" id="default" />
|
|
41
|
+
<RakeTaskImpl description="" fullCommand="release" id="release" />
|
|
42
|
+
<RakeTaskImpl id="release">
|
|
43
|
+
<subtasks>
|
|
44
|
+
<RakeTaskImpl description="" fullCommand="release:guard_clean" id="guard_clean" />
|
|
45
|
+
<RakeTaskImpl description="" fullCommand="release:rubygem_push" id="rubygem_push" />
|
|
46
|
+
<RakeTaskImpl description="" fullCommand="release:source_control_push" id="source_control_push" />
|
|
47
|
+
</subtasks>
|
|
48
|
+
</RakeTaskImpl>
|
|
49
|
+
</subtasks>
|
|
50
|
+
</RakeTaskImpl>
|
|
51
|
+
</option>
|
|
52
|
+
</component>
|
|
53
|
+
</module>
|
data/.idea/misc.xml
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="MarkdownSettingsMigration">
|
|
4
|
+
<option name="stateVersion" value="1" />
|
|
5
|
+
</component>
|
|
6
|
+
<component name="ProjectRootManager" version="2" languageLevel="JDK_20" project-jdk-name="RVM: ruby-2.4.10" project-jdk-type="RUBY_SDK">
|
|
7
|
+
<output url="file://$PROJECT_DIR$/out" />
|
|
8
|
+
</component>
|
|
9
|
+
</project>
|
data/.idea/modules.xml
ADDED
data/.idea/vcs.xml
ADDED
data/Gemfile
CHANGED
|
File without changes
|
data/Gemfile.lock
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
logue (1.0
|
|
4
|
+
logue (1.1.0)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
8
8
|
specs:
|
|
9
9
|
paramesan (0.1.1)
|
|
10
|
-
power_assert (
|
|
10
|
+
power_assert (3.0.1)
|
|
11
11
|
rainbow (3.0.0)
|
|
12
|
-
rake (
|
|
13
|
-
test-unit (3.
|
|
12
|
+
rake (13.0.6)
|
|
13
|
+
test-unit (3.6.1)
|
|
14
14
|
power_assert
|
|
15
15
|
|
|
16
16
|
PLATFORMS
|
|
17
17
|
ruby
|
|
18
18
|
|
|
19
19
|
DEPENDENCIES
|
|
20
|
-
bundler (
|
|
20
|
+
bundler (>= 2.0)
|
|
21
21
|
logue!
|
|
22
22
|
paramesan (~> 0.1.1)
|
|
23
23
|
rainbow (~> 3.0.0)
|
|
24
|
-
rake (~>
|
|
25
|
-
test-unit (
|
|
24
|
+
rake (~> 13.0.1)
|
|
25
|
+
test-unit (= 3.6.1)
|
|
26
26
|
|
|
27
27
|
BUNDLED WITH
|
|
28
|
-
1.
|
|
28
|
+
2.1.4
|
data/LICENSE.txt
CHANGED
|
File without changes
|
data/README.md
CHANGED
|
File without changes
|
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
#!/usr/bin/ruby -w
|
|
2
|
-
# -*- ruby -*-
|
|
3
|
-
#
|
|
4
|
-
# = colorlog.rb
|
|
5
|
-
#
|
|
6
|
-
# Logging Module
|
|
7
|
-
#
|
|
8
|
-
# Author:: Jeff Pace <jeugenepace@gmail.com>
|
|
9
|
-
# Documentation:: Author
|
|
10
|
-
#
|
|
11
|
-
|
|
12
1
|
require 'rainbow/x11_color_names'
|
|
13
2
|
require 'rainbow/color'
|
|
14
3
|
require 'logue/level'
|
|
4
|
+
require 'logue/core/dynamic'
|
|
15
5
|
|
|
16
6
|
#
|
|
17
7
|
# == ColorLog
|
|
@@ -24,9 +14,12 @@ require 'logue/level'
|
|
|
24
14
|
#
|
|
25
15
|
|
|
26
16
|
module Logue
|
|
27
|
-
module
|
|
17
|
+
module Colorable
|
|
18
|
+
include Dynamic
|
|
19
|
+
|
|
28
20
|
def method_missing meth, *args, &blk
|
|
29
|
-
|
|
21
|
+
code = valid_colors[meth]
|
|
22
|
+
if code
|
|
30
23
|
add_color_method meth.to_s, code + 30
|
|
31
24
|
send meth, *args, &blk
|
|
32
25
|
else
|
|
@@ -42,23 +35,9 @@ module Logue
|
|
|
42
35
|
super + valid_colors.keys
|
|
43
36
|
end
|
|
44
37
|
|
|
45
|
-
def add_color_method color, code
|
|
46
|
-
instance_eval ColorLog.color_method_source(color, code)
|
|
47
|
-
end
|
|
48
|
-
|
|
49
38
|
def valid_colors
|
|
50
39
|
# Rainbow::X11ColorNames::NAMES
|
|
51
40
|
Rainbow::Color::Named::NAMES
|
|
52
41
|
end
|
|
53
|
-
|
|
54
|
-
class << self
|
|
55
|
-
def color_method_source color, code
|
|
56
|
-
Array.new.tap do |a|
|
|
57
|
-
a << 'def ' + color.to_s + '(msg = "", lvl = Logue::Level::DEBUG, classname: nil, &blk)'
|
|
58
|
-
a << ' log("\e[' + code.to_s + 'm#{msg}\e[0m", level: lvl, classname: classname, &blk)'
|
|
59
|
-
a << 'end'
|
|
60
|
-
end.join "\n"
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
42
|
end
|
|
64
43
|
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/usr/bin/ruby -w
|
|
2
|
+
# -*- ruby -*-
|
|
3
|
+
#
|
|
4
|
+
# = loggable.rb
|
|
5
|
+
#
|
|
6
|
+
# Logging Module
|
|
7
|
+
#
|
|
8
|
+
# Author:: Jeff Pace <jeugenepace@gmail.com>
|
|
9
|
+
# Documentation:: Author
|
|
10
|
+
#
|
|
11
|
+
|
|
12
|
+
require 'logue/logger'
|
|
13
|
+
require 'logue/log'
|
|
14
|
+
require 'logue/core/object_util'
|
|
15
|
+
|
|
16
|
+
#
|
|
17
|
+
# == Loggable
|
|
18
|
+
#
|
|
19
|
+
# Including this module in a class gives access to the logger methods.
|
|
20
|
+
#
|
|
21
|
+
# == Examples
|
|
22
|
+
#
|
|
23
|
+
# See the unit tests in loggable_test.rb
|
|
24
|
+
#
|
|
25
|
+
# == Usage
|
|
26
|
+
#
|
|
27
|
+
# class YourClass
|
|
28
|
+
# include Logue::Loggable
|
|
29
|
+
#
|
|
30
|
+
# def some_method
|
|
31
|
+
# log "my message"
|
|
32
|
+
#
|
|
33
|
+
# That will log from the given class and method, showing the line number from
|
|
34
|
+
# which the logger was called.
|
|
35
|
+
#
|
|
36
|
+
# def another_method
|
|
37
|
+
# stack "my message"
|
|
38
|
+
#
|
|
39
|
+
# That will produce a stack trace from the given location.
|
|
40
|
+
#
|
|
41
|
+
|
|
42
|
+
module Logue
|
|
43
|
+
module BaseLoggable
|
|
44
|
+
[:stack, :log].each do |methname|
|
|
45
|
+
# level as positional and named arguments, for compatibility backward and with logger
|
|
46
|
+
define_method methname do |msg = ObjectUtil::NONE, obj = nil, lvl = nil, level: nil, &blk|
|
|
47
|
+
lvalue = level || lvl || Level::DEBUG
|
|
48
|
+
logger.send methname, msg, obj, level: lvalue, classname: self.class.to_s, &blk
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
[:debug, :info, :warn, :error, :fatal, :write].each do |methname|
|
|
53
|
+
define_method methname do |msg = ObjectUtil::NONE, obj = nil, &blk|
|
|
54
|
+
logger.send methname, msg, obj, classname: self.class.to_s, &blk
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module Logue
|
|
2
|
+
class BaseWriter
|
|
3
|
+
attr_accessor :output
|
|
4
|
+
attr_accessor :colors
|
|
5
|
+
attr_accessor :colorize_line
|
|
6
|
+
|
|
7
|
+
def initialize output: $stdout, colors: Array.new, colorize_line: false
|
|
8
|
+
@output = output
|
|
9
|
+
@colors = colors
|
|
10
|
+
@colorize_line = colorize_line
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def print lstr, lvl
|
|
14
|
+
str = @colors[lvl] ? lstr.color(lvl) : lstr
|
|
15
|
+
@output.puts str
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def write location, str, level
|
|
19
|
+
lstr = location + " " + str
|
|
20
|
+
print lstr, level
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module Logue
|
|
2
|
+
module Dynamic
|
|
3
|
+
def add_color_method color, code
|
|
4
|
+
add_class_method color do |msg = '', obj = nil, level = Level::DEBUG, &blk|
|
|
5
|
+
colmsg = "\e[#{code}m#{msg}\e[0m"
|
|
6
|
+
log colmsg, obj, level: level, &blk
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def add_class_method meth, &impl
|
|
11
|
+
eigenclass = class << self; self; end
|
|
12
|
+
eigenclass.class_eval do
|
|
13
|
+
define_method meth, impl
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Logue
|
|
2
|
+
class BaseElement
|
|
3
|
+
attr_reader :writer
|
|
4
|
+
attr_reader :context
|
|
5
|
+
|
|
6
|
+
def initialize context, writer
|
|
7
|
+
@context = context
|
|
8
|
+
@writer = writer
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def write_msg_object msg, object
|
|
12
|
+
factory = ElementFactory.new @writer
|
|
13
|
+
element = factory.to_element msg, object, @context
|
|
14
|
+
element.write_element
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def write_line str
|
|
18
|
+
@writer.write_line str
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'logue/elements/base_element'
|
|
2
|
+
|
|
3
|
+
module Logue
|
|
4
|
+
class BlockElement < BaseElement
|
|
5
|
+
def initialize msg, context, writer, &blk
|
|
6
|
+
super context, writer
|
|
7
|
+
@msg = msg
|
|
8
|
+
@blk = blk
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def write_element
|
|
12
|
+
obj = @blk.call
|
|
13
|
+
write_msg_object @msg, obj
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
require 'logue/elements/element'
|
|
2
|
+
require 'logue/elements/msg_obj_element'
|
|
3
|
+
require 'logue/elements/block_element'
|
|
4
|
+
require 'logue/elements/hash_element'
|
|
5
|
+
require 'logue/elements/struct_element'
|
|
6
|
+
require 'logue/elements/indexed_element'
|
|
7
|
+
require 'logue/elements/msg_element'
|
|
8
|
+
require 'logue/core/object_util'
|
|
9
|
+
|
|
10
|
+
module Logue
|
|
11
|
+
class ElementFactory
|
|
12
|
+
def initialize writer
|
|
13
|
+
@writer = writer
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def to_element msg, obj, context
|
|
17
|
+
case obj
|
|
18
|
+
when Element
|
|
19
|
+
obj
|
|
20
|
+
when Struct
|
|
21
|
+
to_complex_element StructElement, msg, obj, context
|
|
22
|
+
when Hash
|
|
23
|
+
to_complex_element HashElement, msg, obj, context
|
|
24
|
+
when Enumerable
|
|
25
|
+
to_complex_element IndexedElement, msg, obj, context
|
|
26
|
+
else
|
|
27
|
+
to_msg_element msg, obj, context
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def to_complex_element cls, msg, obj, context
|
|
32
|
+
if obj && context.include?(obj.object_id)
|
|
33
|
+
MsgObjElement.new msg, obj.object_id.to_s + " (recursed)", context, @writer
|
|
34
|
+
else
|
|
35
|
+
newlist = context.dup
|
|
36
|
+
newlist << obj.object_id
|
|
37
|
+
cls.new msg, obj, newlist, @writer
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def to_msg_element msg, obj, context
|
|
42
|
+
# avoid using == on obj:
|
|
43
|
+
if obj.nil? || (obj.instance_of?(Object) && obj == ObjectUtil::NONE) || (obj.instance_of?(Symbol) && obj == :none)
|
|
44
|
+
MsgElement.new msg, context, @writer
|
|
45
|
+
else
|
|
46
|
+
MsgObjElement.new msg, obj, context, @writer
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'logue/core/base_writer'
|
|
2
|
+
require 'logue/elements/element_factory'
|
|
3
|
+
require 'logue/core/object_util'
|
|
4
|
+
|
|
5
|
+
module Logue
|
|
6
|
+
class ElementLines
|
|
7
|
+
def initialize io, location = ""
|
|
8
|
+
@io = io
|
|
9
|
+
@factory = ElementFactory.new self
|
|
10
|
+
@location = location
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def write_line str
|
|
14
|
+
lstr = @location + " " + str
|
|
15
|
+
@io.puts lstr
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def add_msg_obj msg, obj, context = Array.new
|
|
19
|
+
element = @factory.to_element msg, obj, context
|
|
20
|
+
element.write_element
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'logue/log'
|
|
2
|
+
require 'logue/elements/elements_writer'
|
|
3
|
+
|
|
4
|
+
#
|
|
5
|
+
# == ElementsLog
|
|
6
|
+
#
|
|
7
|
+
# ElementsLog uses the extended format for formatting complex elements instead
|
|
8
|
+
# of using only their to-string methods.
|
|
9
|
+
#
|
|
10
|
+
# See Log.
|
|
11
|
+
#
|
|
12
|
+
module Logue
|
|
13
|
+
class ElementsLog < Log
|
|
14
|
+
def self.reset
|
|
15
|
+
logger = Logger.new writer: ElementsWriter.new
|
|
16
|
+
Log.logger = logger
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
reset
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'logue/logger'
|
|
2
|
+
require 'logue/log'
|
|
3
|
+
require 'logue/core/base_loggable'
|
|
4
|
+
|
|
5
|
+
module Logue
|
|
6
|
+
module ElementsLoggable
|
|
7
|
+
include BaseLoggable
|
|
8
|
+
|
|
9
|
+
def logger
|
|
10
|
+
@logger ||= Log.logger
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def logger= logger
|
|
14
|
+
@logger = logger
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'logue/core/base_writer'
|
|
2
|
+
require 'logue/elements/element_lines'
|
|
3
|
+
require 'logue/elements/block_element'
|
|
4
|
+
require 'logue/core/object_util'
|
|
5
|
+
|
|
6
|
+
module Logue
|
|
7
|
+
class ElementsWriter < BaseWriter
|
|
8
|
+
def write_msg_obj location, msg, obj, level
|
|
9
|
+
# we're not using the level, which at this point only is for colorizing output
|
|
10
|
+
lines = ElementLines.new @output, location
|
|
11
|
+
factory = ElementFactory.new lines
|
|
12
|
+
element = factory.to_element msg, obj, Array.new
|
|
13
|
+
write_element element
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def write_msg_blk location, msg, level, &blk
|
|
17
|
+
# we're not using the level, which at this point only is for colorizing output
|
|
18
|
+
lines = ElementLines.new @output, location
|
|
19
|
+
element = BlockElement.new msg, Array.new, lines, &blk
|
|
20
|
+
write_element element
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def write_block location, level, &blk
|
|
24
|
+
lines = ElementLines.new @output, location
|
|
25
|
+
element = BlockElement.new ObjectUtil::NONE, Array.new, lines, &blk
|
|
26
|
+
write_element element
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def write_element element
|
|
30
|
+
element.write_element
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'logue/elements/enum_element'
|
|
2
|
+
|
|
3
|
+
module Logue
|
|
4
|
+
class IndexedElement < EnumerableElement
|
|
5
|
+
def write_element
|
|
6
|
+
if @object.respond_to? :size
|
|
7
|
+
write_msg_object "#{@msg}.#", @object.size
|
|
8
|
+
end
|
|
9
|
+
@object.each_with_index do |value, index|
|
|
10
|
+
newmsg = "#{@msg}[#{index}]"
|
|
11
|
+
write_msg_object newmsg, value
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|