Class: KLog::LogStructure
- Inherits:
-
Object
- Object
- KLog::LogStructure
- Defined in:
- lib/k_log/log_structure.rb
Overview
Log Structure is flexible logger for working through a complex object graph
Defined Under Namespace
Classes: GraphNode, TablePrintIo
Instance Attribute Summary collapse
-
#convert_data_to ⇒ Object
readonly
Returns the value of attribute convert_data_to.
-
#formatter ⇒ Object
readonly
Returns the value of attribute formatter.
-
#graph ⇒ Object
readonly
Returns the value of attribute graph.
-
#graph_node ⇒ Object
readonly
Returns the value of attribute graph_node.
-
#graph_path ⇒ Object
readonly
Returns the value of attribute graph_path.
-
#heading ⇒ Object
readonly
Returns the value of attribute heading.
-
#heading_type ⇒ Object
readonly
Returns the value of attribute heading_type.
-
#indent ⇒ Object
readonly
Returns the value of attribute indent.
-
#key_format ⇒ Object
readonly
Returns the value of attribute key_format.
-
#key_width ⇒ Object
readonly
Returns the value of attribute key_width.
-
#line_width ⇒ Object
readonly
Returns the value of attribute line_width.
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
-
#output_as ⇒ Object
readonly
Returns the value of attribute output_as.
-
#output_file ⇒ Object
readonly
Returns the value of attribute output_file.
-
#recursion_depth ⇒ Object
readonly
Returns the value of attribute recursion_depth.
-
#show_array_count ⇒ Object
readonly
Returns the value of attribute show_array_count.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#title_type ⇒ Object
readonly
Returns the value of attribute title_type.
Instance Method Summary collapse
- #add_line(line) ⇒ Object
- #add_lines(lines) ⇒ Object
- #clean_content ⇒ Object
- #clean_lines ⇒ Object
- #content ⇒ Object
-
#initialize(opts) ⇒ LogStructure
constructor
Log a structure.
- #l ⇒ Object
- #log(data) ⇒ Object
Constructor Details
#initialize(opts) ⇒ LogStructure
Log a structure
Can handle Hash, Array, OpenStruct, Struct, DryStruct, Hash convertible custom classes
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/k_log/log_structure.rb', line 39 def initialize(opts) @indent = opts[:indent] || ' ' @title = opts[:title] @title_type = opts[:title_type] || :heading @heading = opts[:heading] @heading_type = opts[:heading_type] || :heading puts ':heading should be :title' if opts[:heading] puts ':heading_type should be :title_type' if opts[:heading_type] @formatter = opts[:formatter] || {} @graph = parse_graph(opts[:graph] || {}) @convert_data_to = opts[:convert_data_to] || :raw # by default leave data as is @line_width = opts[:line_width] || 80 @key_width = opts[:key_width] || 30 @show_array_count = opts[:show_array_count] || false @output_as = opts[:output_as] || [:console] @output_as = [@output_as] unless @output_as.is_a?(Array) @output_file = opts[:output_file] @recursion_depth = 0 @key_format = nil @graph_path = [] @lines = [] update_indent_label end |
Instance Attribute Details
#convert_data_to ⇒ Object (readonly)
Returns the value of attribute convert_data_to.
18 19 20 |
# File 'lib/k_log/log_structure.rb', line 18 def convert_data_to @convert_data_to end |
#formatter ⇒ Object (readonly)
Returns the value of attribute formatter.
17 18 19 |
# File 'lib/k_log/log_structure.rb', line 17 def formatter @formatter end |
#graph ⇒ Object (readonly)
Returns the value of attribute graph.
16 17 18 |
# File 'lib/k_log/log_structure.rb', line 16 def graph @graph end |
#graph_node ⇒ Object (readonly)
Returns the value of attribute graph_node.
23 24 25 |
# File 'lib/k_log/log_structure.rb', line 23 def graph_node @graph_node end |
#graph_path ⇒ Object (readonly)
Returns the value of attribute graph_path.
22 23 24 |
# File 'lib/k_log/log_structure.rb', line 22 def graph_path @graph_path end |
#heading ⇒ Object (readonly)
Returns the value of attribute heading.
11 12 13 |
# File 'lib/k_log/log_structure.rb', line 11 def heading @heading end |
#heading_type ⇒ Object (readonly)
Returns the value of attribute heading_type.
12 13 14 |
# File 'lib/k_log/log_structure.rb', line 12 def heading_type @heading_type end |
#indent ⇒ Object (readonly)
Returns the value of attribute indent.
8 9 10 |
# File 'lib/k_log/log_structure.rb', line 8 def indent @indent end |
#key_format ⇒ Object (readonly)
Returns the value of attribute key_format.
21 22 23 |
# File 'lib/k_log/log_structure.rb', line 21 def key_format @key_format end |
#key_width ⇒ Object (readonly)
Returns the value of attribute key_width.
14 15 16 |
# File 'lib/k_log/log_structure.rb', line 14 def key_width @key_width end |
#line_width ⇒ Object (readonly)
Returns the value of attribute line_width.
13 14 15 |
# File 'lib/k_log/log_structure.rb', line 13 def line_width @line_width end |
#lines ⇒ Object (readonly)
Returns the value of attribute lines.
25 26 27 |
# File 'lib/k_log/log_structure.rb', line 25 def lines @lines end |
#output_as ⇒ Object (readonly)
Returns the value of attribute output_as.
26 27 28 |
# File 'lib/k_log/log_structure.rb', line 26 def output_as @output_as end |
#output_file ⇒ Object (readonly)
Returns the value of attribute output_file.
27 28 29 |
# File 'lib/k_log/log_structure.rb', line 27 def output_file @output_file end |
#recursion_depth ⇒ Object (readonly)
Returns the value of attribute recursion_depth.
20 21 22 |
# File 'lib/k_log/log_structure.rb', line 20 def recursion_depth @recursion_depth end |
#show_array_count ⇒ Object (readonly)
Returns the value of attribute show_array_count.
15 16 17 |
# File 'lib/k_log/log_structure.rb', line 15 def show_array_count @show_array_count end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
9 10 11 |
# File 'lib/k_log/log_structure.rb', line 9 def title @title end |
#title_type ⇒ Object (readonly)
Returns the value of attribute title_type.
10 11 12 |
# File 'lib/k_log/log_structure.rb', line 10 def title_type @title_type end |
Instance Method Details
#add_line(line) ⇒ Object
102 103 104 |
# File 'lib/k_log/log_structure.rb', line 102 def add_line(line) @lines << line end |
#add_lines(lines) ⇒ Object
98 99 100 |
# File 'lib/k_log/log_structure.rb', line 98 def add_lines(lines) @lines += lines end |
#clean_content ⇒ Object
88 89 90 91 |
# File 'lib/k_log/log_structure.rb', line 88 def clean_content # remove color escape codes @clean_content ||= content.gsub(/\x1B\[\d*m/, '') end |
#clean_lines ⇒ Object
93 94 95 96 |
# File 'lib/k_log/log_structure.rb', line 93 def clean_lines # remove color escape codes lines.flat_map { |line| line.gsub(/\x1B\[\d*m/, '').split("\n") } end |
#content ⇒ Object
84 85 86 |
# File 'lib/k_log/log_structure.rb', line 84 def content @content ||= lines.join("\n") end |