k_log 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 72de9a7d2c858aed9802f1853ab7d141bd3fbb4641456148b294d6d8bb0f4bfc
4
- data.tar.gz: 80199689b1bff33b5033e9c8a475ff97009fd2605f8fcfc99deac3172ef6ee9a
3
+ metadata.gz: f34eecb4cb24782290842b9e92e5ea8aefd756622719ec08f9db89c34922df89
4
+ data.tar.gz: 13dca8550835143913a74152f9cbedc16c724077fbe8d36f460920b9b54b9c69
5
5
  SHA512:
6
- metadata.gz: 6948881ccd96667754275eecedc0be3d6eab65d8f0f97f18def65bbf2727395eb35a2197ff3a9db49c8759880aec18afd8082864f70d029f859f6f8af6fa4534
7
- data.tar.gz: d03583cf50fa5d29c46ef7c7271c5d951277ce2718b8e2f5bc738792954da5c02d6082bde44c3a494de2fc990b19ec5c738115ae6900f06848873604e8263c91
6
+ metadata.gz: 4a869ac41dee2845a7270ab4248452f8fcebd6c8a055dbfdb849e43f428144eabeae7553c13f723982ff90c897d9fe959de97fbe1eb81945c666c1abdbe62931
7
+ data.tar.gz: d3f1a36c7d775088dc9139965118f46131527f801385f355d7b3c75630b767cdb6036d865e018857736c94f7f2d1efe623731eeaadaf41e6460d96a6406e289f
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  > K Log provides console logging helpers and formatters
4
4
 
5
+ This code is old and probably needs to be written differently, but it solves my problem of having formatted console logging within different Apps and Gems that I write.
6
+
5
7
  ## Installation
6
8
 
7
9
  Add this line to your application's Gemfile:
@@ -62,14 +64,18 @@ L.kv('Last Name', 'Cruwys')
62
64
  L.kv('Age', 45)
63
65
  L.kv('Sex', 'male')
64
66
 
65
- L.line
66
- L.line(20)
67
- L.line(20, character: '-')
68
-
69
67
  L.heading('Heading')
70
68
  L.subheading('Sub Heading')
69
+
70
+ L.block ['Line 1', 12, 'Line 3', true, 'Line 5']
71
+
72
+ L.progress(0, 'Section 1')
73
+ L.progress
74
+ L.progress
71
75
  ```
72
76
 
77
+ ![Usage](usage.png)
78
+
73
79
  ## Development
74
80
 
75
81
  Checkout the repo
@@ -80,15 +86,6 @@ git clone klueless-io/k_log
80
86
 
81
87
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
82
88
 
83
- You can also run `bin/console` for an interactive prompt that will allow you to experiment.
84
-
85
- ```bash
86
- bin/console
87
-
88
- Aaa::Bbb::Program.execute()
89
- # => ""
90
- ```
91
-
92
89
  `k_log` is setup with Guard, run `guard`, this will watch development file changes and run tests automatically, if successful, it will then run rubocop for style quality.
93
90
 
94
91
  To release a new version, update the version number in `version.rb`, build the gem and push the `.gem` file to [rubygems.org](https://rubygems.org).
data/STORIES.md CHANGED
@@ -12,22 +12,15 @@ As a Developer, I need formatted console logs, so that information presents clea
12
12
 
13
13
  - A range of helper methods that write formatted log entries to the console
14
14
 
15
- ### Tasks next on list
15
+ ## Stories and tasks
16
+
17
+ ### Tasks - completed
16
18
 
17
19
  Setup RubyGems and RubyDoc
18
20
 
19
21
  - Build and deploy gem to [rubygems.org](https://rubygems.org/gems/k_log)
20
22
  - Attach documentation to [rubydoc.info](https://rubydoc.info/github/to-do-/k_log/master)
21
23
 
22
- Setup GitHub Action (test and lint)
23
-
24
- - Setup Rspec action
25
- - Setup RuboCop action
26
-
27
- ## Stories and tasks
28
-
29
- ### Tasks - completed
30
-
31
24
  Setup project management, requirement and SCRUM documents
32
25
 
33
26
  - Setup readme file
@@ -35,6 +28,11 @@ Setup project management, requirement and SCRUM documents
35
28
  - Setup a project backlog
36
29
  - Setup an examples/usage document
37
30
 
31
+ Setup GitHub Action (test and lint)
32
+
33
+ - Setup Rspec action
34
+ - Setup RuboCop action
35
+
38
36
  Setup new Ruby GEM
39
37
 
40
38
  - Build out a standard GEM structure
data/hooks/pre-commit CHANGED
@@ -8,7 +8,7 @@ require 'English'
8
8
 
9
9
  exit 0 if ARGV.include?('--no-verify')
10
10
 
11
- warning_keywords = %w[console.log]
11
+ warning_keywords = %w[]
12
12
  keywords = %w[binding.pry console.dir byebug debugger]
13
13
  files_changed = `git diff-index --name-only HEAD --`.split
14
14
 
@@ -23,7 +23,7 @@ files_changed -= ['Gemfile']
23
23
  files_changed -= ['Gemfile.lock']
24
24
  files_changed -= ['.gitignore']
25
25
 
26
- files_changed = files_changed.reject { |f| f.downcase.end_with?('.MD') }
26
+ files_changed = files_changed.reject { |f| f.downcase.end_with?('.mds') }
27
27
  files_changed = files_changed.reject { |f| f.downcase.end_with?('.json') }
28
28
  files_changed = files_changed.reject { |f| f.downcase.end_with?('.yml') }
29
29
 
data/lib/k_log.rb CHANGED
@@ -1,10 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'logger'
3
4
  require 'k_log/version'
5
+ require 'k_log/log_formatter'
6
+ require 'k_log/log_helper'
7
+ require 'k_log/log_util'
4
8
 
9
+ # Simple console log helpers
5
10
  module KLog
6
11
  # raise KLog::Error, 'Sample message'
7
12
  class Error < StandardError; end
8
13
 
9
- # Your code goes here...
14
+ class << self
15
+ attr_accessor :logger
16
+ end
10
17
  end
18
+
19
+ # KLog.logger = Logger.new($stdout)
20
+ # KLog.logger.level = Logger::DEBUG
21
+ # KLog.logger.formatter = KLog::LogFormatter.new
22
+
23
+ # L = KLog::LogUtil.new(KLog.logger)
@@ -1,36 +1,32 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module KDsl
4
- module Logger
5
- # Styled Log formatter
6
- class LogFormatter < ::Logger::Formatter
7
- attr_accessor :show_caller
3
+ module KLog
4
+ # Styled Log formatter
5
+ class LogFormatter < ::Logger::Formatter
6
+ SEVERITY_TO_COLOR_MAP = {
7
+ 'DEBUG' => '34',
8
+ 'INFO' => '32',
9
+ 'WARN' => '33',
10
+ 'ERROR' => '31',
11
+ 'FATAL' => '37'
12
+ }.freeze
8
13
 
9
- SEVERITY_TO_COLOR_MAP = {
10
- 'DEBUG' => '34',
11
- 'INFO' => '32',
12
- 'WARN' => '33',
13
- 'ERROR' => '31',
14
- 'FATAL' => '37'
15
- }.freeze
14
+ def call(severity, _timestamp, _prog_name, msg)
15
+ severity = severity.upcase
16
16
 
17
- def call(severity, _timestamp, _progname, msg)
18
- severity = severity.upcase
17
+ color = SEVERITY_TO_COLOR_MAP[severity]
19
18
 
20
- color = SEVERITY_TO_COLOR_MAP[severity]
19
+ severity_value = format("\033[#{color}m%<severity>-5.5s\033[0m", { severity: severity })
21
20
 
22
- severity_value = format("\033[#{color}m%<severity>-5.5s\033[0m", { severity: severity })
21
+ msg = msg.is_a?(String) ? msg : msg.inspect
23
22
 
24
- msg = msg.is_a?(String) ? msg : msg.inspect
25
-
26
- format(
27
- "%<time>s %<severity>s %<message>s\n", {
28
- time: Time.now.strftime('%d|%H:%M:%S'),
29
- severity: severity_value,
30
- message: msg
31
- }
32
- )
33
- end
23
+ format(
24
+ "%<time>s %<severity>s %<message>s\n", {
25
+ time: Time.now.strftime('%d|%H:%M:%S'),
26
+ severity: severity_value,
27
+ message: msg
28
+ }
29
+ )
34
30
  end
35
31
  end
36
32
  end
@@ -1,119 +1,112 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Log Helper is an internal class that takes care of a lot of the formating of different content types
4
- # e.g key/values, lines, progress counters and headings
5
- # it is different to the formatter becuase the formatter is used by Rails Logger to change the output stream style and format
6
- class LogHelper
7
- @progress_section = ''
8
- @progress_position = 0
9
-
10
- class << self
11
- attr_accessor :progress_position
12
- attr_accessor :progress_section
13
- end
14
-
15
- def self.kv(key, value, key_width = 30)
16
- "#{green(key.to_s.ljust(key_width))}: #{value}"
17
- end
18
-
19
- def self.progress(pos = nil, section = nil)
20
- @progress_position = pos.nil? ? @progress_position : pos
3
+ # Log Helper is an internal class that takes care of a lot of the formatting
4
+ # of different content types e.g key/values, lines, progress counters and headings
5
+ # it is different to the formatter because the formatter is used by Rails Logger
6
+ # to change the output stream style and format
7
+ module KLog
8
+ # Simple console log helpers
9
+ class LogHelper
10
+ @progress_section = ''
11
+ @progress_position = 0
12
+
13
+ class << self
14
+ attr_accessor :progress_position
15
+ attr_accessor :progress_section
16
+ end
21
17
 
22
- unless section.nil?
23
- # Pl.info 'here'
24
- @progress_section = section
18
+ def self.kv(key, value, key_width = 30)
19
+ "#{green(key.to_s.ljust(key_width))}: #{value}"
25
20
  end
26
21
 
27
- # puts '@progress_position'
28
- # puts @progress_position
29
- # puts '@progress_section'
30
- # puts @progress_section
22
+ def self.progress(pos = nil, section = nil)
23
+ @progress_position = pos.nil? ? @progress_position : pos
31
24
 
32
- section_length = 28
25
+ @progress_section = section unless section.nil?
33
26
 
34
- section = if @progress_section.nil?
35
- ' ' * section_length
36
- else
37
- ' ' + @progress_section.ljust(section_length - 1, ' ')
38
- end
27
+ section_length = 28
39
28
 
40
- # puts 'section'
41
- # puts section
29
+ section = if @progress_section.nil?
30
+ ' ' * section_length
31
+ else
32
+ " #{@progress_section.ljust(section_length - 1, ' ')}"
33
+ end
42
34
 
43
- result = '..' + section + ':' + @progress_position.to_s.rjust(4)
35
+ result = "..#{section}:#{@progress_position.to_s.rjust(4)}"
44
36
 
45
- @progress_position += 1
37
+ @progress_position += 1
46
38
 
47
- result
48
- end
39
+ result
40
+ end
49
41
 
50
- def self.line(size = 70, character = '=')
51
- green(character * size)
52
- end
42
+ def self.line(size = 70, character = '=')
43
+ green(character * size)
44
+ end
53
45
 
54
- def self.heading(heading, size = 70)
55
- line = line(size)
46
+ def self.heading(heading, size = 70)
47
+ line = line(size)
56
48
 
57
- [
58
- line,
59
- heading,
60
- line
61
- ]
62
- end
49
+ [
50
+ line,
51
+ heading,
52
+ line
53
+ ]
54
+ end
63
55
 
64
- def self.subheading(heading, size = 70)
65
- line = line(size, '-')
66
- [
67
- line,
68
- heading,
69
- line
70
- ]
71
- end
56
+ def self.subheading(heading, size = 70)
57
+ line = line(size, '-')
58
+ [
59
+ line,
60
+ heading,
61
+ line
62
+ ]
63
+ end
72
64
 
73
- # A section heading
74
- #
75
- # example:
76
- # [ I am a heading ]----------------------------------------------------
77
- def self.section_heading(heading, size = 70)
78
- heading = "[ #{heading} ]"
79
- line = line(size - heading.length, '-')
65
+ # A section heading
66
+ #
67
+ # example:
68
+ # [ I am a heading ]----------------------------------------------------
69
+ def self.section_heading(heading, size = 70)
70
+ heading = "[ #{heading} ]"
71
+ line = line(size - heading.length, '-')
80
72
 
81
- # It is important that you set the colour after you have calculated the size
82
- "#{green(heading)}#{line}"
83
- end
73
+ # It is important that you set the colour after you have calculated the size
74
+ "#{green(heading)}#{line}"
75
+ end
84
76
 
85
- # :sql_array should be an array with SQL and values
86
- # example: L.sql(["name = :name and group_id = :value OR parent_id = :value", name: "foo'bar", value: 4])
87
- # def sql(sql_array)
88
- # value = ActiveRecord::Base.send(:sanitize_sql_array, sql_array)
77
+ # :sql_array should be an array with SQL and values
78
+ # example: L.sql(["name = :name and group_id = :value OR parent_id = :value", name: "foo'bar", value: 4])
79
+ # def sql(sql_array)
80
+ # value = ActiveRecord::Base.send(:sanitize_sql_array, sql_array)
89
81
 
90
- # info(value)
91
- # end
82
+ # info(value)
83
+ # end
92
84
 
93
- # rubocop:disable Metrics/CyclomaticComplexity
94
- def self.block(messages, include_line = true, title: nil)
95
- result = include_line ? [line] : []
85
+ # rubocop:disable Metrics/CyclomaticComplexity
86
+ def self.block(messages, include_line: true, title: nil)
87
+ result = include_line ? [line] : []
96
88
 
97
- unless title.nil?
98
- result.push(title)
99
- result.push(line(70, ','))
100
- end
89
+ unless title.nil?
90
+ result.push(title)
91
+ result.push(line(70, ','))
92
+ end
101
93
 
102
- result.push messages if messages.is_a?(String) || messages.is_a?(Integer)
94
+ result.push messages if messages.is_a?(String) || messages.is_a?(Integer)
103
95
 
104
- if messages.is_a? Array
105
- messages.each do |message|
106
- result.push message
96
+ if messages.is_a? Array
97
+ messages.each do |message|
98
+ result.push message
99
+ end
107
100
  end
108
- end
109
101
 
110
- result.push line if include_line
102
+ result.push line if include_line
111
103
 
112
- result
113
- end
114
- # rubocop:enable Metrics/CyclomaticComplexity
104
+ result
105
+ end
106
+ # rubocop:enable Metrics/CyclomaticComplexity
115
107
 
116
- def self.green(value)
117
- "\033[32m#{value}\033[0m"
108
+ def self.green(value)
109
+ "\033[32m#{value}\033[0m"
110
+ end
118
111
  end
119
112
  end
@@ -1,332 +1,345 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Format Logger Util provides static helper methods that delegate responsibility to the underlying
4
- # Format Logger, you can use the Util instead Rails.logger so that you have access to IDE intellisense around
5
- # available methods and so that you can use the same logger calls from controllers/models which normally have
6
- # access to to a logger variable and services which do not have access to a logger varialbe
3
+ # Format Logger Util provides static helper methods that delegate responsibility
4
+ # to the underlying Format Logger, you can use the Util instead Rails.logger so
5
+ # that you have access to IDE intellisense around available methods and so you
6
+ # can use the same logger calls from controllers/models which normally have
7
+ # access to to a logger variable and services which do not have access to a
8
+ # logger variable
7
9
  #
8
- # I usually alias the call to FormatLoggerUtil by doing L = FormatLoggerUtil
10
+ # I usually alias the call to LogUtil by doing L = LogUtil
9
11
 
10
12
  # require_relative 'format_logger'
11
13
  # require_relative 'format_logger_helper'
12
14
 
13
- class LogUtil
14
- def initialize(logger)
15
- @logger = logger
16
- @fuck = true
17
- end
15
+ module KLog
16
+ # Simple console log helpers
17
+ class LogUtil
18
+ def initialize(logger)
19
+ @logger = logger
20
+ end
18
21
 
19
- # include ActiveSupport::LoggerThreadSafeLevel
20
- # include LoggerSilence
22
+ # include ActiveSupport::LoggerThreadSafeLevel
23
+ # include LoggerSilence
21
24
 
22
- #----------------------------------------------------------------------------------------------------
23
- # Standard Accessors that are on the standard rails Logger
24
- #----------------------------------------------------------------------------------------------------
25
- def debug(value)
26
- @logger.debug(value)
27
- end
25
+ #----------------------------------------------------------------------------------------------------
26
+ # Standard Accessors that are on the standard rails Logger
27
+ #----------------------------------------------------------------------------------------------------
28
+ def debug(value)
29
+ @logger.debug(value)
30
+ end
28
31
 
29
- def info(value)
30
- @logger.info(value)
31
- end
32
+ def info(value)
33
+ @logger.info(value)
34
+ end
32
35
 
33
- def warn(value)
34
- @logger.warn(value)
35
- end
36
+ def warn(value)
37
+ @logger.warn(value)
38
+ end
36
39
 
37
- def error(value)
38
- @logger.error(value)
39
- end
40
+ def error(value)
41
+ @logger.error(value)
42
+ end
40
43
 
41
- def fatal(value)
42
- @logger.fatal(value)
43
- end
44
+ def fatal(value)
45
+ @logger.fatal(value)
46
+ end
44
47
 
45
- #----------------------------------------------------------------------------------------------------
46
- # Helper Log output Methods
47
- #----------------------------------------------------------------------------------------------------
48
+ #----------------------------------------------------------------------------------------------------
49
+ # Helper Log output Methods
50
+ #----------------------------------------------------------------------------------------------------
48
51
 
49
- # Write a Key/Value Pair
50
- def kv(key, value, key_width = 30)
51
- message = LogHelper.kv(key, value, key_width)
52
- @logger.info(message)
53
- end
52
+ # Write a Key/Value Pair
53
+ def kv(key, value, key_width = 30)
54
+ message = LogHelper.kv(key, value, key_width)
55
+ @logger.info(message)
56
+ end
54
57
 
55
- # Write a progress point, progress will update on it's own
56
- def progress(pos = nil, section = nil)
57
- message = LogHelper.progress(pos, section)
58
- # @logger.debug(message)
59
- @logger.info(message)
58
+ # Write a progress point, progress will update on it's own
59
+ def progress(pos = nil, section = nil)
60
+ message = LogHelper.progress(pos, section)
61
+ # @logger.debug(message)
62
+ @logger.info(message)
60
63
 
61
- LogHelper.progress_position
62
- end
64
+ LogHelper.progress_position
65
+ end
63
66
 
64
- # prints out a line to the log
65
- def line(size = 70, character: '=')
66
- message = LogHelper.line(size, character)
67
+ # prints out a line to the log
68
+ def line(size = 70, character: '=')
69
+ message = LogHelper.line(size, character)
67
70
 
68
- @logger.info(message)
69
- end
71
+ @logger.info(message)
72
+ end
70
73
 
71
- def heading(heading, size = 70)
72
- lines = LogHelper.heading(heading, size)
73
- info_multi_lines(lines)
74
- end
74
+ def heading(heading, size = 70)
75
+ lines = LogHelper.heading(heading, size)
76
+ info_multi_lines(lines)
77
+ end
75
78
 
76
- def subheading(heading, size = 70)
77
- lines = LogHelper.subheading(heading, size)
79
+ def subheading(heading, size = 70)
80
+ lines = LogHelper.subheading(heading, size)
78
81
 
79
- info_multi_lines(lines)
80
- end
82
+ info_multi_lines(lines)
83
+ end
81
84
 
82
- # A section heading
83
- #
84
- # example:
85
- # [ I am a heading ]----------------------------------------------------
86
- def section_heading(heading, size = 70)
87
- heading = LogHelper.section_heading(heading, size)
85
+ # A section heading
86
+ #
87
+ # example:
88
+ # [ I am a heading ]----------------------------------------------------
89
+ def section_heading(heading, size = 70)
90
+ heading = LogHelper.section_heading(heading, size)
88
91
 
89
- info(heading)
90
- end
92
+ info(heading)
93
+ end
91
94
 
92
- def block(messages, include_line = true, title: nil)
93
- lines = LogHelper.block(messages, include_line, title: title)
95
+ def block(messages, include_line: true, title: nil)
96
+ lines = LogHelper.block(messages, include_line: include_line, title: title)
94
97
 
95
- info_multi_lines(lines)
96
- end
98
+ info_multi_lines(lines)
99
+ end
97
100
 
98
- # # :sql_array should be an array with SQL and values or with SQL and Hash
99
- # # example:
100
- # # L.sql(["name = :name and group_id = :value OR parent_id = :value", name: "foo'bar", value: 4])
101
- # # L.sql([sql_exact_match_skills_in_use, {names: self.segments_container.segment_values}])
102
- # def sql(sql_array)
103
- # value = ActiveRecord::Base.send(:sanitize_sql_array, sql_array)
101
+ # # :sql_array should be an array with SQL and values or with SQL and Hash
102
+ # # example:
103
+ # # L.sql(["name = :name and group_id = :value OR parent_id = :value", name: "foo'bar", value: 4])
104
+ # # L.sql([sql_exact_match_skills_in_use, {names: self.segments_container.segment_values}])
105
+ # def sql(sql_array)
106
+ # value = ActiveRecord::Base.send(:sanitize_sql_array, sql_array)
104
107
 
105
- # info(value)
106
- # end
108
+ # info(value)
109
+ # end
107
110
 
108
- def yaml(data, is_line = true)
109
- line if is_line
111
+ def yaml(data, is_line: true)
112
+ require 'yaml'
113
+ line if is_line
110
114
 
111
- @logger.info(data.to_yaml) if data.is_a?(Hash)
115
+ @logger.info(data.to_yaml) if data.is_a?(Hash)
112
116
 
113
- @logger.info(data.marshal_dump.to_yaml) if data.is_a?(OpenStruct)
117
+ @logger.info(data.marshal_dump.to_yaml) if data.is_a?(OpenStruct)
114
118
 
115
- if data.is_a? Array
116
- data.each do |d|
117
- @logger.info(d.to_yaml)
119
+ if data.is_a? Array
120
+ data.each do |d|
121
+ @logger.info(d.to_yaml)
122
+ end
118
123
  end
119
- end
120
124
 
121
- line if is_line
122
- end
125
+ line if is_line
126
+ end
123
127
 
124
- def json(data)
125
- @logger.info(JSON.pretty_generate(data))
126
- end
127
- alias j json
128
-
129
- def open_struct(data, indent = '', **opts)
130
- data.each_pair do |key, value|
131
- if value.is_a?(OpenStruct)
132
- if value['rows'].is_a?(Array)
133
- # L.subheading(key)
134
- opts[:subheading] = key
135
- open_struct(value, indent, **opts)
136
- opts.delete(:subheading)
137
- else
138
- L.kv "#{indent}#{key}", ''
139
- indent = "#{indent} "
140
- open_struct(value, indent, **opts)
141
- indent = indent.chomp(' ')
142
- end
143
- elsif value.is_a?(Array)
144
- next if opts[:skip_array].present?
145
- # puts LogHelper.subheading(key, 88)# if opts[:subheading].present?
146
- puts LogHelper.subheading(opts[:subheading], 88) if opts[:subheading].present?
147
- if value.length > 0
148
- if value.first.is_a?(String)
149
- L.kv "#{indent}#{key}", value.join(', ')
128
+ def json(data)
129
+ @logger.info(JSON.pretty_generate(data))
130
+ end
131
+ alias j json
132
+
133
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity, Metrics/AbcSize
134
+ def open_struct(data, indent = '', **opts)
135
+ data.each_pair do |key, value|
136
+ case value
137
+ when OpenStruct
138
+ if value['rows'].is_a?(Array)
139
+ # L.subheading(key)
140
+ opts[:subheading] = key
141
+ open_struct(value, indent, **opts)
142
+ opts.delete(:subheading)
150
143
  else
151
- tp value, value.first.to_h.keys
144
+ L.kv "#{indent}#{key}", ''
145
+ indent = "#{indent} "
146
+ open_struct(value, indent, **opts)
147
+ indent = indent.chomp(' ')
148
+ end
149
+ when Array
150
+ next if opts[:skip_array].present?
151
+
152
+ # puts LogHelper.subheading(key, 88)# if opts[:subheading].present?
153
+ puts LogHelper.subheading(opts[:subheading], 88) if opts[:subheading].present?
154
+ if value.length.positive?
155
+ if value.first.is_a?(String)
156
+ L.kv "#{indent}#{key}", value.join(', ')
157
+ else
158
+ tp value, value.first.to_h.keys
159
+ end
152
160
  end
161
+ else
162
+ L.kv "#{indent}#{key}", value
153
163
  end
154
- else
155
- L.kv "#{indent}#{key}", value
156
164
  end
165
+ nil
157
166
  end
158
- nil
159
- end
160
- alias ostruct open_struct
161
- alias o open_struct
167
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity, Metrics/AbcSize
168
+ alias ostruct open_struct
169
+ alias o open_struct
162
170
 
163
- def exception(e)
164
- line
171
+ def exception(exception)
172
+ line
165
173
 
166
- @logger.info(e.message)
167
- @logger.info(e.backtrace.join("\n"))
174
+ @logger.info(exception.message)
175
+ @logger.info(exception.backtrace.join("\n"))
168
176
 
169
- line
170
- end
177
+ line
178
+ end
171
179
 
172
- #----------------------------------------------------------------------------------------------------
173
- # Pretty Loggers
174
- #----------------------------------------------------------------------------------------------------
180
+ #----------------------------------------------------------------------------------------------------
181
+ # Pretty Loggers
182
+ #----------------------------------------------------------------------------------------------------
175
183
 
176
- # NOTE: using pretty_inspect is an existing namespace conflict
177
- def pretty_class(instance)
178
- c = instance.class
184
+ # NOTE: using pretty_inspect is an existing namespace conflict
185
+ # rubocop:disable Metrics/AbcSize
186
+ def pretty_class(instance)
187
+ c = instance.class
179
188
 
180
- line
189
+ line
181
190
 
182
- kv('Full Class', c.name)
183
- kv('Module', c.name.deconstantize)
184
- kv('Class', c.name.demodulize)
191
+ kv('Full Class', c.name)
192
+ kv('Module', c.name.deconstantize)
193
+ kv('Class', c.name.demodulize)
185
194
 
186
- source_location = c.instance_methods(false).map { |m|
187
- c.instance_method(m).source_location.first
188
- }.uniq
195
+ source_location = c.instance_methods(false).map do |m|
196
+ c.instance_method(m).source_location.first
197
+ end.uniq
189
198
 
190
- begin
191
- kv('Source Location', source_location)
192
- rescue => e
193
- warn e
199
+ begin
200
+ kv('Source Location', source_location)
201
+ rescue StandardError => e
202
+ warn e
203
+ end
204
+
205
+ line
194
206
  end
207
+ # rubocop:enable Metrics/AbcSize
195
208
 
196
- line
197
- end
209
+ # NOTE: using pretty_inspect is an existing namespace conflict
210
+ def pretty_params(params)
211
+ line
198
212
 
199
- # NOTE: using pretty_inspect is an existing namespace conflict
200
- def pretty_params(params)
201
- line
213
+ params.each do |k, v|
214
+ if params[k].is_a?(Hash)
202
215
 
203
- params.each do |k,v|
204
- if (params[k].is_a?(Hash))
216
+ params[k].each do |child_k, child_v|
217
+ kv("#{k}[#{child_k}]", child_v)
218
+ end
205
219
 
206
- params[k].each do |childK, childV|
207
- kv("#{k}[#{childK}]",childV)
220
+ else
221
+ kv(k, v)
208
222
  end
209
-
210
- else
211
- kv(k, v)
212
223
  end
213
- end
214
224
 
215
- line
216
- end
225
+ line
226
+ end
217
227
 
218
- def help_all_symbols
219
- # Produces a lot of data, need some sort of filter I think before this is useful
220
- Symbol.all_symbols.each do |s|
221
- info s
222
- # debug s
228
+ def help_all_symbols
229
+ # Produces a lot of data, need some sort of filter I think before this is useful
230
+ Symbol.all_symbols.each do |s|
231
+ info s
232
+ # debug s
233
+ end
223
234
  end
224
- end
225
235
 
226
- #----------------------------------------------------------------------------------------------------
227
- # Internal Methods
228
- #----------------------------------------------------------------------------------------------------
236
+ #----------------------------------------------------------------------------------------------------
237
+ # Internal Methods
238
+ #----------------------------------------------------------------------------------------------------
229
239
 
230
- def self.samples
231
- L.debug 'some debug message'
232
- L.info 'some info message'
233
- L.warn 'some warning message'
234
- L.error 'some error message'
235
- L.fatal 'some fatal message'
240
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
241
+ def self.examples
242
+ L.debug 'some debug message'
243
+ L.info 'some info message'
244
+ L.warn 'some warning message'
245
+ L.error 'some error message'
246
+ L.fatal 'some fatal message'
236
247
 
237
- L.kv('First Name', 'David')
238
- L.kv('Last Name', 'Cruwys')
239
- L.kv('Age', 45)
240
- L.kv('Sex', 'male')
248
+ L.kv('First Name', 'David')
249
+ L.kv('Last Name', 'Cruwys')
250
+ L.kv('Age', 45)
251
+ L.kv('Sex', 'male')
241
252
 
242
- L.progress(0, 'Section 1')
243
- L.progress
244
- L.progress
245
- save_progress = L.progress
253
+ L.heading('Heading')
254
+ L.subheading('Sub Heading')
246
255
 
247
- L.progress(10, 'Section 2')
248
- L.progress
249
- L.progress
250
- L.progress
256
+ L.block ['Line 1', 12, 'Line 3', true, 'Line 5']
251
257
 
252
- L.progress(save_progress, 'Section 1')
253
- L.progress
254
- L.progress
255
- L.progress
258
+ L.progress(0, 'Section 1')
259
+ L.progress
260
+ L.progress
261
+ save_progress = L.progress
256
262
 
257
- L.line
258
- L.line(20)
259
- L.line(20, character: '-')
263
+ L.progress(10, 'Section 2')
264
+ L.progress
265
+ L.progress
266
+ L.progress
260
267
 
261
- L.heading('Heading')
262
- L.subheading('Sub Heading')
268
+ L.progress(save_progress, 'Section 1')
269
+ L.progress
270
+ L.progress
271
+ L.progress
263
272
 
264
- L.block ['Line 1', 12, 'Line 3', true,'Line 5']
273
+ L.line
274
+ L.line(20)
275
+ L.line(20, character: '-')
265
276
 
266
- yaml1 = Hash.new
267
- yaml1['title'] = 'Software Architect'
268
- yaml1['age'] = 45
269
- yaml1['name'] = 'David'
277
+ yaml1 = {}
278
+ yaml1['title'] = 'Software Architect'
279
+ yaml1['age'] = 45
280
+ yaml1['name'] = 'David'
270
281
 
271
- yaml3 = Hash.new
272
- yaml3['title'] = 'Develoer'
273
- yaml3['age'] = 20
274
- yaml3['name'] = 'Jin'
282
+ yaml3 = {}
283
+ yaml3['title'] = 'Developer'
284
+ yaml3['age'] = 20
285
+ yaml3['name'] = 'Jin'
275
286
 
276
- L.yaml(yaml1)
287
+ L.yaml(yaml1)
277
288
 
278
- yaml2 = OpenStruct.new
279
- yaml2.title = 'Software Architect'
280
- yaml2.age = 45
281
- yaml2.name = 'David'
289
+ yaml2 = OpenStruct.new
290
+ yaml2.title = 'Software Architect'
291
+ yaml2.age = 45
292
+ yaml2.name = 'David'
282
293
 
283
- L.yaml(yaml2)
294
+ L.yaml(yaml2)
284
295
 
285
- mixed_yaml_array = [yaml1, yaml2]
296
+ mixed_yaml_array = [yaml1, yaml2]
286
297
 
287
- # This fails because we don't correctly pre-process the array
288
- L.yaml(mixed_yaml_array)
298
+ # This fails because we don't correctly pre-process the array
299
+ L.yaml(mixed_yaml_array)
289
300
 
290
- hash_yaml_array = [yaml1, yaml3]
301
+ hash_yaml_array = [yaml1, yaml3]
291
302
 
292
- L.yaml(hash_yaml_array)
303
+ L.yaml(hash_yaml_array)
293
304
 
294
- begin
295
- raise 'Here is an error'
296
- rescue StandardError => e
297
- L.exception(e)
305
+ begin
306
+ raise 'Here is an error'
307
+ rescue StandardError => e
308
+ L.exception(e)
309
+ end
298
310
  end
299
- end
311
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
300
312
 
301
- private
313
+ private
302
314
 
303
- def debug_multi_lines(lines)
304
- lines.each do |line|
305
- debug(line)
315
+ def debug_multi_lines(lines)
316
+ lines.each do |line|
317
+ debug(line)
318
+ end
306
319
  end
307
- end
308
320
 
309
- def info_multi_lines(lines)
310
- lines.each do |line|
311
- info(line)
321
+ def info_multi_lines(lines)
322
+ lines.each do |line|
323
+ info(line)
324
+ end
312
325
  end
313
- end
314
326
 
315
- def warn_multi_lines(lines)
316
- lines.each do |line|
317
- warn(line)
327
+ def warn_multi_lines(lines)
328
+ lines.each do |line|
329
+ warn(line)
330
+ end
318
331
  end
319
- end
320
332
 
321
- def error_multi_lines(lines)
322
- lines.each do |line|
323
- error(line)
333
+ def error_multi_lines(lines)
334
+ lines.each do |line|
335
+ error(line)
336
+ end
324
337
  end
325
- end
326
338
 
327
- def fatal_multi_lines(lines)
328
- lines.each do |line|
329
- fatal(line)
339
+ def fatal_multi_lines(lines)
340
+ lines.each do |line|
341
+ fatal(line)
342
+ end
330
343
  end
331
344
  end
332
345
  end
data/lib/k_log/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KLog
4
- VERSION = '0.0.4'
4
+ VERSION = '0.0.6'
5
5
  end
data/usage.png ADDED
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: k_log
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cruwys
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-30 00:00:00.000000000 Z
11
+ date: 2021-03-31 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: " KLog provides console logging helpers and formatters\n"
14
14
  email:
@@ -42,6 +42,7 @@ files:
42
42
  - lib/k_log/log_helper.rb
43
43
  - lib/k_log/log_util.rb
44
44
  - lib/k_log/version.rb
45
+ - usage.png
45
46
  homepage: http://appydave.com/gems/k-log
46
47
  licenses:
47
48
  - MIT