k_log 0.0.14 → 0.0.19

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: '09e7a754932b0c5135aedab7479843432f91e4cb07fca8c02a9b43a39348a030'
4
- data.tar.gz: 7afea8a76865110473bb5e4637407a740344cb3a14dd5d867946a088d9cb5f89
3
+ metadata.gz: 243999c48416e082085f9c72519cd2cc97bb8585389ee6848592f18dc2cfc6bd
4
+ data.tar.gz: '009abfdd9b635d89f6e31f8197516f0dd612ce14adc9dfb7f005c9a9da458684'
5
5
  SHA512:
6
- metadata.gz: 0ad9e7d14ef6baea84d98656e2c05b12c8323336781c4ece398eb9c0980b167456aa890778e840d2b0cc568d61527558f331d789d9409df9e88408643a15c6e2
7
- data.tar.gz: 135951199b19c6c7af7357d4419ddfffe251f52c5afd78cdc0d49b46db9d09612745300d8dc6d081a552e4598645293a2a2189440732ac4881f444c82ff7c173
6
+ metadata.gz: f19cf492a22aaf8dbc89dcd9246aacc5732e3db7844d17030d63091e672c4fb201d11c221bbe24450cb1d8745b16d8b70bb21994cc821387ee703aaea4bbc69f
7
+ data.tar.gz: f0355d0438831db47d1ec390ba7d336b763d76f8d1d23f9520c98a1641901f0114c9961e9ac5d158daa8cddf5658782c6311721aeea5f01cd6dbe7ba24a80c80
data/.rubocop.yml CHANGED
@@ -44,11 +44,17 @@ Layout/LineLength:
44
44
  Lint/UnusedMethodArgument:
45
45
  AllowUnusedKeywordArguments: true
46
46
 
47
+ Style/Documentation:
48
+ Enabled: false
49
+
47
50
  Style/BlockComments:
48
51
  Enabled: false
49
52
  Include:
50
53
  - "**/spec/*"
51
54
 
55
+ Layout/EndOfLine:
56
+ EnforcedStyle: lf
57
+
52
58
  # My Preferences - Start
53
59
  Metrics/ClassLength:
54
60
  Enabled: false
data/lib/k_log.rb CHANGED
@@ -6,6 +6,7 @@ require 'k_log/version'
6
6
  require 'k_log/log_formatter'
7
7
  require 'k_log/log_helper'
8
8
  require 'k_log/log_util'
9
+ require 'k_log/logging'
9
10
 
10
11
  # Simple console log helpers
11
12
  module KLog
@@ -30,4 +31,9 @@ end
30
31
 
31
32
  KLog.logger = KLog.default_logger
32
33
 
33
- puts "KLog::Version: #{KLog::VERSION}" if ENV['KLUE_DEBUG']&.to_s&.downcase == 'true'
34
+ if ENV['KLUE_DEBUG']&.to_s&.downcase == 'true'
35
+ namespace = 'KLog::Version'
36
+ file_path = $LOADED_FEATURES.find { |f| f.include?('k_log/version') }
37
+ version = KLog::VERSION.ljust(9)
38
+ puts "#{namespace.ljust(35)} : #{version.ljust(9)} : #{file_path}"
39
+ end
@@ -0,0 +1,129 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KLog
4
+ class Examples
5
+ include KLog::Logging
6
+
7
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
8
+ def examples
9
+ examples_simple
10
+ examples_complex
11
+ end
12
+
13
+ def examples_simple
14
+ log.debug 'some debug message'
15
+ log.info 'some info message'
16
+ log.warn 'some warning message'
17
+ log.error 'some error message'
18
+ log.fatal 'some fatal message'
19
+
20
+ log.kv('First Name', 'David')
21
+ log.kv('Last Name', 'Cruwys')
22
+ log.kv('Age', 45)
23
+ log.kv('Sex', 'male')
24
+
25
+ log.heading('Heading')
26
+ log.subheading('Sub Heading')
27
+ log.section_heading('Section Heading')
28
+
29
+ data = OpenStruct.new
30
+ data.title = 'Software Architect'
31
+ data.age = 45
32
+ data.name = 'David'
33
+ data.names = %w[David Bill]
34
+ data.status = :debug
35
+ data.statuses = %i[debug info blah]
36
+ log.open_struct(data, section_heading: 'Display Open Struct')
37
+ end
38
+
39
+ def examples_complex
40
+ log.block ['Line 1', 12, 'Line 3', true, 'Line 5']
41
+
42
+ log.progress(0, 'Section 1')
43
+ log.progress
44
+ log.progress
45
+ save_progress = log.progress
46
+
47
+ log.progress(10, 'Section 2')
48
+ log.progress
49
+ log.progress
50
+ log.progress
51
+
52
+ log.progress(save_progress, 'Section 1')
53
+ log.progress
54
+ log.progress
55
+ log.progress
56
+
57
+ log.line
58
+ log.line(20)
59
+ log.line(20, character: '-')
60
+
61
+ yaml1 = {}
62
+ yaml1['title'] = 'Software Architect'
63
+ yaml1['age'] = 45
64
+ yaml1['name'] = 'David'
65
+
66
+ yaml3 = {}
67
+ yaml3['title'] = 'Developer'
68
+ yaml3['age'] = 20
69
+ yaml3['name'] = 'Jin'
70
+
71
+ log.yaml(yaml1)
72
+
73
+ yaml2 = OpenStruct.new
74
+ yaml2.title = 'Software Architect'
75
+ yaml2.age = 45
76
+ yaml2.name = 'David'
77
+
78
+ log.yaml(yaml2)
79
+
80
+ mixed_yaml_array = [yaml1, yaml2]
81
+
82
+ # This fails because we don't correctly pre-process the array
83
+ log.yaml(mixed_yaml_array)
84
+
85
+ hash_yaml_array = [yaml1, yaml3]
86
+
87
+ log.yaml(hash_yaml_array)
88
+
89
+ begin
90
+ raise 'Here is an error'
91
+ rescue StandardError => e
92
+ log.exception(e)
93
+ end
94
+ end
95
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
96
+
97
+ private
98
+
99
+ def debug_multi_lines(lines)
100
+ lines.each do |line|
101
+ debug(line)
102
+ end
103
+ end
104
+
105
+ def info_multi_lines(lines)
106
+ lines.each do |line|
107
+ info(line)
108
+ end
109
+ end
110
+
111
+ def warn_multi_lines(lines)
112
+ lines.each do |line|
113
+ warn(line)
114
+ end
115
+ end
116
+
117
+ def error_multi_lines(lines)
118
+ lines.each do |line|
119
+ error(line)
120
+ end
121
+ end
122
+
123
+ def fatal_multi_lines(lines)
124
+ lines.each do |line|
125
+ fatal(line)
126
+ end
127
+ end
128
+ end
129
+ end
@@ -89,7 +89,7 @@ module KLog
89
89
 
90
90
  unless title.nil?
91
91
  result.push(title)
92
- result.push(line(70, ','))
92
+ result.push(line(70, '-'))
93
93
  end
94
94
 
95
95
  result.push messages if messages.is_a?(String) || messages.is_a?(Integer)
@@ -50,6 +50,7 @@ module KLog
50
50
  #----------------------------------------------------------------------------------------------------
51
51
 
52
52
  # Write a Key/Value Pair
53
+ # Need to change this to named_param
53
54
  def kv(key, value, key_width = 30)
54
55
  message = LogHelper.kv(key, value, key_width)
55
56
  @logger.info(message)
@@ -132,6 +133,10 @@ module KLog
132
133
 
133
134
  # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity, Metrics/AbcSize
134
135
  def open_struct(data, indent = '', **opts)
136
+ KLog.logger.heading(opts[:heading], 88) unless opts[:heading].nil?
137
+ KLog.logger.subheading(opts[:subheading], 88) unless opts[:subheading].nil?
138
+ KLog.logger.section_heading(opts[:section_heading], 88) unless opts[:section_heading].nil?
139
+
135
140
  data.each_pair do |key, value|
136
141
  case value
137
142
  when OpenStruct
@@ -152,8 +157,8 @@ module KLog
152
157
  puts LogHelper.section_heading(opts[:subheading], 88) unless opts[:subheading].nil?
153
158
 
154
159
  if value.length.positive?
155
- if value.first.is_a?(String)
156
- KLog.logger.kv "#{indent}#{key}", value.join(', ')
160
+ if value.first.is_a?(String) || value.first.is_a?(Symbol)
161
+ KLog.logger.kv "#{indent}#{key}", value.map(&:to_s).join(', ')
157
162
  else
158
163
  tp value, value.first.to_h.keys
159
164
  end
@@ -206,6 +211,12 @@ module KLog
206
211
  end
207
212
  # rubocop:enable Metrics/AbcSize
208
213
 
214
+ def kv_hash(hash)
215
+ hash.each do |key, value|
216
+ kv(key, value)
217
+ end
218
+ end
219
+
209
220
  # NOTE: using pretty_inspect is an existing namespace conflict
210
221
  def pretty_params(params)
211
222
  line
@@ -233,6 +244,27 @@ module KLog
233
244
  end
234
245
  end
235
246
 
247
+ def visual_compare_hashes(hash1, hash2)
248
+ content1 = JSON.pretty_generate(hash1)
249
+ content2 = JSON.pretty_generate(hash2)
250
+
251
+ file1 = Tempfile.new('hash1')
252
+ file1.write(content1)
253
+ file1.close
254
+
255
+ file2 = Tempfile.new('hash2')
256
+ file2.write(content2)
257
+ file2.close
258
+
259
+ system "code --diff #{file1.path} #{file2.path}"
260
+
261
+ # Provide enough time for vscode to open and display the files before deleting them
262
+ sleep 1
263
+
264
+ file1.unlink
265
+ file2.unlink
266
+ end
267
+
236
268
  #----------------------------------------------------------------------------------------------------
237
269
  # Internal Methods
238
270
  #----------------------------------------------------------------------------------------------------
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KLog
4
+ module Logging
5
+ def log
6
+ @log ||= KLog.logger
7
+ end
8
+ end
9
+ 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.14'
4
+ VERSION = '0.0.19'
5
5
  end
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.14
4
+ version: 0.0.19
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-04-01 00:00:00.000000000 Z
11
+ date: 2021-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: table_print
@@ -52,9 +52,11 @@ files:
52
52
  - hooks/update-version
53
53
  - k_log.gemspec
54
54
  - lib/k_log.rb
55
+ - lib/k_log/examples.rb
55
56
  - lib/k_log/log_formatter.rb
56
57
  - lib/k_log/log_helper.rb
57
58
  - lib/k_log/log_util.rb
59
+ - lib/k_log/logging.rb
58
60
  - lib/k_log/version.rb
59
61
  - usage.png
60
62
  homepage: http://appydave.com/gems/k-log