ext_logger 0.2.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6fb8e5a361934db3221aaa2d96c0b04dfd2ef30b
4
- data.tar.gz: e628741ec577cdefd2226ea9c6af4721dc308921
3
+ metadata.gz: feda3a291e84b8feb211ccadb3c3cb9d6f6ed5d8
4
+ data.tar.gz: 939cce5de283f2ca4871f5ab791e2cf1ef981d54
5
5
  SHA512:
6
- metadata.gz: ac616c82566339f401c2a742748f632ee5e5c2ad9fb5bc387d14cf1dfb83b13dff127870de78213ba3dc93ddf6f6fac9863a8490f1c3e5c93a6aead9f0ed5386
7
- data.tar.gz: efb96a84b8a873d1cebfd3bee698f821c6038f5a8e654e1d4ebb84a4d11c07eb239975a5d9ae3bdf62ea1ddabc7a465004e7d083234b779fc0449c52a79f92bf
6
+ metadata.gz: b303bb5810c0ae16674522d0d9b15fb29c48bd750a1a4950ad6544c343332404599c282a9fe1f2d6b31bdb4385ed964358400ff839fc5b11a0682147865ef736
7
+ data.tar.gz: 34accf48cf82a9d5e6f179e1bf008c3fcb4ce071c58d5cf8530b2fb79b6239b393cceef3bd0b5231500fbc1e459716362f3b1ea269e9d6c5af7fbfd02c063f0f
data/.idea/workspace.xml CHANGED
@@ -22,8 +22,8 @@
22
22
  <entry file="file://$PROJECT_DIR$/README.md">
23
23
  <provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
24
24
  <state split_layout="SPLIT">
25
- <first_editor relative-caret-position="435">
26
- <caret line="29" column="95" lean-forward="false" selection-start-line="29" selection-start-column="95" selection-end-line="29" selection-end-column="95" />
25
+ <first_editor relative-caret-position="-717">
26
+ <caret line="13" column="46" lean-forward="false" selection-start-line="13" selection-start-column="46" selection-end-line="13" selection-end-column="46" />
27
27
  <folding />
28
28
  </first_editor>
29
29
  <second_editor />
@@ -31,11 +31,11 @@
31
31
  </provider>
32
32
  </entry>
33
33
  </file>
34
- <file leaf-file-name="ext_logger.gemspec" pinned="false" current-in-tab="false">
34
+ <file leaf-file-name="ext_logger.gemspec" pinned="false" current-in-tab="true">
35
35
  <entry file="file://$PROJECT_DIR$/ext_logger.gemspec">
36
36
  <provider selected="true" editor-type-id="text-editor">
37
- <state relative-caret-position="225">
38
- <caret line="15" column="219" lean-forward="false" selection-start-line="15" selection-start-column="219" selection-end-line="15" selection-end-column="219" />
37
+ <state relative-caret-position="150">
38
+ <caret line="10" column="0" lean-forward="true" selection-start-line="10" selection-start-column="0" selection-end-line="10" selection-end-column="0" />
39
39
  <folding />
40
40
  </state>
41
41
  </provider>
@@ -44,8 +44,8 @@
44
44
  <file leaf-file-name="version.rb" pinned="false" current-in-tab="false">
45
45
  <entry file="file://$PROJECT_DIR$/lib/ext_logger/version.rb">
46
46
  <provider selected="true" editor-type-id="text-editor">
47
- <state relative-caret-position="60">
48
- <caret line="4" column="0" lean-forward="true" selection-start-line="4" selection-start-column="0" selection-end-line="4" selection-end-column="0" />
47
+ <state relative-caret-position="30">
48
+ <caret line="2" column="19" lean-forward="false" selection-start-line="2" selection-start-column="19" selection-end-line="2" selection-end-column="19" />
49
49
  <folding />
50
50
  </state>
51
51
  </provider>
@@ -61,11 +61,11 @@
61
61
  </provider>
62
62
  </entry>
63
63
  </file>
64
- <file leaf-file-name="logger.rb" pinned="false" current-in-tab="true">
64
+ <file leaf-file-name="logger.rb" pinned="false" current-in-tab="false">
65
65
  <entry file="file://$PROJECT_DIR$/lib/ext_logger/logger.rb">
66
66
  <provider selected="true" editor-type-id="text-editor">
67
- <state relative-caret-position="278">
68
- <caret line="228" column="28" lean-forward="true" selection-start-line="228" selection-start-column="28" selection-end-line="228" selection-end-column="28" />
67
+ <state relative-caret-position="141">
68
+ <caret line="140" column="51" lean-forward="false" selection-start-line="140" selection-start-column="51" selection-end-line="140" selection-end-column="51" />
69
69
  <folding />
70
70
  </state>
71
71
  </provider>
@@ -105,6 +105,8 @@
105
105
  <find>@output_flag</find>
106
106
  <find>output?</find>
107
107
  <find>DATE_FORMAT_MEMBER_LIST</find>
108
+ <find>postfix</find>
109
+ <find>dput</find>
108
110
  </findStrings>
109
111
  <replaceStrings>
110
112
  <replace>now_time</replace>
@@ -116,11 +118,12 @@
116
118
  <replace>rails_root</replace>
117
119
  <replace>split_file</replace>
118
120
  <replace>is_blank?</replace>
119
- <replace>split_format</replace>
120
121
  <replace>@log_split_format</replace>
121
122
  <replace>_split_format</replace>
122
123
  <replace>pt</replace>
123
124
  <replace>put_to_console</replace>
125
+ <replace>split_format</replace>
126
+ <replace>output_debug</replace>
124
127
  </replaceStrings>
125
128
  </component>
126
129
  <component name="Git.Settings">
@@ -130,10 +133,10 @@
130
133
  <option name="CHANGED_PATHS">
131
134
  <list>
132
135
  <option value="$PROJECT_DIR$/.ruby-gemset" />
133
- <option value="$PROJECT_DIR$/ext_logger.gemspec" />
134
- <option value="$PROJECT_DIR$/lib/ext_logger/version.rb" />
135
136
  <option value="$PROJECT_DIR$/README.md" />
136
137
  <option value="$PROJECT_DIR$/lib/ext_logger/logger.rb" />
138
+ <option value="$PROJECT_DIR$/lib/ext_logger/version.rb" />
139
+ <option value="$PROJECT_DIR$/ext_logger.gemspec" />
137
140
  </list>
138
141
  </option>
139
142
  </component>
@@ -199,6 +202,31 @@
199
202
  <item name="External Libraries" type="cb654da1:ExternalLibrariesNode" />
200
203
  <item name="&lt; RVM: ruby-2.3.1 [gem_ext_logger] &gt;" type="70bed36:NamedLibraryElementNode" />
201
204
  </path>
205
+ <path>
206
+ <item name="ext_logger" type="b2602c69:ProjectViewProjectNode" />
207
+ <item name="External Libraries" type="cb654da1:ExternalLibrariesNode" />
208
+ <item name="&lt; RVM: ruby-2.3.1 [gem_ext_logger] &gt;" type="70bed36:NamedLibraryElementNode" />
209
+ <item name="2.3.0" type="462c0819:PsiDirectoryNode" />
210
+ </path>
211
+ <path>
212
+ <item name="ext_logger" type="b2602c69:ProjectViewProjectNode" />
213
+ <item name="External Libraries" type="cb654da1:ExternalLibrariesNode" />
214
+ <item name="&lt; RVM: ruby-2.3.1 [gem_ext_logger] &gt;" type="70bed36:NamedLibraryElementNode" />
215
+ <item name="site_ruby" type="462c0819:PsiDirectoryNode" />
216
+ </path>
217
+ <path>
218
+ <item name="ext_logger" type="b2602c69:ProjectViewProjectNode" />
219
+ <item name="External Libraries" type="cb654da1:ExternalLibrariesNode" />
220
+ <item name="&lt; RVM: ruby-2.3.1 [gem_ext_logger] &gt;" type="70bed36:NamedLibraryElementNode" />
221
+ <item name="2.3.0" type="462c0819:PsiDirectoryNode" />
222
+ </path>
223
+ <path>
224
+ <item name="ext_logger" type="b2602c69:ProjectViewProjectNode" />
225
+ <item name="External Libraries" type="cb654da1:ExternalLibrariesNode" />
226
+ <item name="&lt; RVM: ruby-2.3.1 [gem_ext_logger] &gt;" type="70bed36:NamedLibraryElementNode" />
227
+ <item name="2.3.0" type="462c0819:PsiDirectoryNode" />
228
+ <item name="rubygems" type="462c0819:PsiDirectoryNode" />
229
+ </path>
202
230
  </expand>
203
231
  <select />
204
232
  </subPane>
@@ -248,12 +276,12 @@
248
276
  <workItem from="1543393243729" duration="348000" />
249
277
  <workItem from="1543398726895" duration="2281000" />
250
278
  <workItem from="1543543683820" duration="89000" />
251
- <workItem from="1544081694369" duration="15431000" />
279
+ <workItem from="1544081694369" duration="19403000" />
252
280
  </task>
253
281
  <servers />
254
282
  </component>
255
283
  <component name="TimeTrackingManager">
256
- <option name="totallyTimeSpent" value="19978000" />
284
+ <option name="totallyTimeSpent" value="23950000" />
257
285
  </component>
258
286
  <component name="ToolWindowManager">
259
287
  <frame x="0" y="0" width="1280" height="800" extended-state="0" />
@@ -262,10 +290,10 @@
262
290
  <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.2494043" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
263
291
  <window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
264
292
  <window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="true" content_ui="tabs" />
265
- <window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
293
+ <window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="9" side_tool="false" content_ui="tabs" />
266
294
  <window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
267
295
  <window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
268
- <window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
296
+ <window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="8" side_tool="false" content_ui="tabs" />
269
297
  <window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="true" content_ui="tabs" />
270
298
  <window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
271
299
  <window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
@@ -516,18 +544,18 @@
516
544
  </state>
517
545
  </provider>
518
546
  </entry>
519
- <entry file="file://$PROJECT_DIR$/lib/ext_logger/version.rb">
547
+ <entry file="file://$PROJECT_DIR$/lib/ext_logger/logger.rb">
520
548
  <provider selected="true" editor-type-id="text-editor">
521
- <state relative-caret-position="60">
522
- <caret line="4" column="0" lean-forward="true" selection-start-line="4" selection-start-column="0" selection-end-line="4" selection-end-column="0" />
549
+ <state relative-caret-position="141">
550
+ <caret line="140" column="51" lean-forward="false" selection-start-line="140" selection-start-column="51" selection-end-line="140" selection-end-column="51" />
523
551
  <folding />
524
552
  </state>
525
553
  </provider>
526
554
  </entry>
527
- <entry file="file://$PROJECT_DIR$/ext_logger.gemspec">
555
+ <entry file="file://$PROJECT_DIR$/lib/ext_logger/version.rb">
528
556
  <provider selected="true" editor-type-id="text-editor">
529
- <state relative-caret-position="225">
530
- <caret line="15" column="219" lean-forward="false" selection-start-line="15" selection-start-column="219" selection-end-line="15" selection-end-column="219" />
557
+ <state relative-caret-position="30">
558
+ <caret line="2" column="19" lean-forward="false" selection-start-line="2" selection-start-column="19" selection-end-line="2" selection-end-column="19" />
531
559
  <folding />
532
560
  </state>
533
561
  </provider>
@@ -535,18 +563,18 @@
535
563
  <entry file="file://$PROJECT_DIR$/README.md">
536
564
  <provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
537
565
  <state split_layout="SPLIT">
538
- <first_editor relative-caret-position="435">
539
- <caret line="29" column="95" lean-forward="false" selection-start-line="29" selection-start-column="95" selection-end-line="29" selection-end-column="95" />
566
+ <first_editor relative-caret-position="-717">
567
+ <caret line="13" column="46" lean-forward="false" selection-start-line="13" selection-start-column="46" selection-end-line="13" selection-end-column="46" />
540
568
  <folding />
541
569
  </first_editor>
542
570
  <second_editor />
543
571
  </state>
544
572
  </provider>
545
573
  </entry>
546
- <entry file="file://$PROJECT_DIR$/lib/ext_logger/logger.rb">
574
+ <entry file="file://$PROJECT_DIR$/ext_logger.gemspec">
547
575
  <provider selected="true" editor-type-id="text-editor">
548
- <state relative-caret-position="278">
549
- <caret line="228" column="28" lean-forward="true" selection-start-line="228" selection-start-column="28" selection-end-line="228" selection-end-column="28" />
576
+ <state relative-caret-position="150">
577
+ <caret line="10" column="0" lean-forward="true" selection-start-line="10" selection-start-column="0" selection-end-line="10" selection-end-column="0" />
550
578
  <folding />
551
579
  </state>
552
580
  </provider>
data/README.md CHANGED
@@ -4,6 +4,18 @@ Welcome to your new gem! In this directory, you'll find the files you need to be
4
4
 
5
5
  ```explain
6
6
  Extended Logger class, log output to console in non-production environment.
7
+ 2018-12-06(0.2.0):
8
+ The internal structure changes greatly.
9
+ Adding Exception Output Processing:
10
+ logger.exception(e) # The 'e' is exception object.
11
+ Adding hash parameters:
12
+ :age (shift_age with Logger object),
13
+ :size (shift_size with Logger object),
14
+ :split_format (log file output according to Ruby time format).
15
+
16
+ 2018-11-28(0.1.3):
17
+ Additional instance method ‘record_memory’ to record memory consumption.
18
+ Fixed a path problem during log initialization.
7
19
  ```
8
20
 
9
21
  ## Installation
@@ -54,7 +66,19 @@ Or install it yourself as:
54
66
  logger.warn("abcdefg")
55
67
  ```
56
68
 
57
- 6. Output of memory usage (Extended logger.warn):
69
+ 6. Output of fatal log (Extended logger.fatal):
70
+
71
+ ```ruby
72
+ logger.fatal("abcdefg")
73
+ ```
74
+
75
+ 7. Output of exception log (Extended logger.error):
76
+
77
+ ```ruby
78
+ logger.exception(e) # when rescure Exception => e
79
+ ```
80
+
81
+ 7. Output of memory usage (Extended logger.warn):
58
82
 
59
83
  ```ruby
60
84
  logger.record_memory # at the begin of programme
data/ext_logger.gemspec CHANGED
@@ -9,13 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Ruby"]
10
10
  spec.email = ["wu.chao@maisiteng.com"]
11
11
 
12
- spec.summary = %q{Extended Logger class, log output to console in non-production environment.}
13
- spec.description = %q{
14
- Extended Logger class, log output to console in non-production environment.\n
15
- Additional instance method ‘record_memory’ to record memory consumption.\n
16
- 2018-12-06(0.2.0): The internal structure changes greatly, adding hash parameters: age (shift_age with Logger object), size (shift_size with Logger object), split_format (log file output according to Ruby time format).\n
17
- 2018-11-28(0.1.3): Fixed a path problem during log initialization.
18
- }
12
+ spec.summary = %q{Extended Logger class, output log content to console in non-production environment.}
13
+ spec.description = %q{Extended Logger class, output log content to console in non-production environment. Auto split log file by parameters:split_format }
19
14
  spec.homepage = ""
20
15
  spec.license = "MIT"
21
16
 
@@ -4,23 +4,23 @@ require 'logger'
4
4
  class ExtLogger
5
5
 
6
6
  DATE_FORMAT_MEMBER_LIST = %w(%Y %y %m %d %wday %H %M %S)
7
- LOG_NAME = '{log_name}' # log name pseudo-code
7
+ LOG_NAME = '{log_name}' # Log name pseudo-code
8
8
  ENV_HASH = {
9
9
  dev: 'development',
10
10
  stg: 'staging',
11
11
  pro: 'production',
12
12
  }
13
13
 
14
- @debug = false
15
- @logger = nil
16
- @log_path = ''
17
- @log_split_format = '' # log name postfix, default blank.
18
- @output_flag = true # flag of output to console
14
+ @debug = false # Controller debug content output to console
15
+ @logger = nil # Initialize logger object
16
+ @log_path = '' # Log path
17
+ @log_split_format = '' # Split format character in log, default blank.
18
+ @output_flag = true # Controller normal content output to console
19
19
 
20
- # new / initialize
20
+ # Initialize
21
21
  def initialize(*args)
22
22
  func_name = "[#{self.to_s}.initialize]"
23
- dput "#{func_name} args.size: #{args.size}"
23
+ output_debug "#{func_name} args.size: #{args.size}"
24
24
  init(args[0]) if args.size == 1
25
25
 
26
26
  if args.size == 2
@@ -42,68 +42,88 @@ class ExtLogger
42
42
  @logger = Logger.new(*args)
43
43
  end
44
44
 
45
- # set debug
45
+ # Set debug
46
46
  def set_debug(_bool=true)
47
47
  @debug = _bool
48
48
  end
49
49
 
50
- # set output flag
50
+ # Set output flag
51
51
  def set_output_flag(type=true)
52
52
  @output_flag = type
53
53
  end
54
54
 
55
- # output info
55
+ # Output info
56
56
  def info(*args)
57
- put_to_console('INFO', *args)
57
+ output_normal('INFO', *args)
58
58
 
59
59
  @logger.info(*args)
60
60
  end
61
61
 
62
- # output debug
62
+ # Output debug
63
63
  def debug(*args)
64
- put_to_console('DEBUG', *args)
64
+ output_normal('DEBUG', *args)
65
65
 
66
66
  @logger.debug(*args)
67
67
  end
68
68
 
69
- # output error
69
+ # Output error
70
70
  def error(*args)
71
- put_to_console('ERROR', *args)
71
+ output_normal('ERROR', *args)
72
72
 
73
73
  @logger.error(*args)
74
74
  end
75
75
 
76
76
  # output warning
77
77
  def warn(*args)
78
- put_to_console('WARN', *args)
78
+ output_normal('WARN', *args)
79
79
 
80
80
  @logger.warn(*args)
81
81
  end
82
82
 
83
- # output fatal
83
+ # Output fatal
84
84
  def fatal(*args)
85
- put_to_console('FATAL', *args)
85
+ output_normal('FATAL', *args)
86
86
 
87
87
  @logger.fatal(*args)
88
88
  end
89
89
 
90
- # output exception
90
+ # Output exception
91
91
  def exception(*args)
92
92
  func_name = "[@logger.EXCEPTION]"
93
93
 
94
94
  if args.size == 1
95
- dput "#{func_name} args[0].class: #{args[0].class}"
95
+ output_debug "#{func_name} args[0].class: #{args[0].class}"
96
96
  str = args[0].message + args[0].backtrace.join("\n")
97
97
  args = [str]
98
98
  end
99
- put_to_console('EXCEPTION', *args)
99
+ output_normal('EXCEPTION', *args)
100
100
 
101
- @logger.error(*args)
101
+ _output_type = 'error'
102
+ if args.size == 2
103
+ output_debug "#{func_name} args[1].class: #{args[1].class}"
104
+ if args[1].is_a?(Hash)
105
+ _output_type = args[1][:type] if !args[1][:type].blank?
106
+ end
107
+ end
108
+
109
+ # Change logger ouput type
110
+ case _output_type
111
+ when 'info'
112
+ @logger.info(*args)
113
+ when 'debug'
114
+ @logger.debug(*args)
115
+ when 'warn'
116
+ @logger.warn(*args)
117
+ when 'fatal'
118
+ @logger.fatal(*args)
119
+ else
120
+ @logger.error(*args)
121
+ end
102
122
  end
103
123
 
104
- # output the memory usage
105
- # example: record_memory()
106
- # example: record_memory('end')
124
+ # Output the memory usage
125
+ # Example: record_memory()
126
+ # Example: record_memory('end')
107
127
  def record_memory(type='start')
108
128
  func_name = "[@logger.record_memory]"
109
129
  begin
@@ -145,17 +165,17 @@ class ExtLogger
145
165
  @record_memory_error = 1
146
166
  end
147
167
  rescue Exception=>e
148
- self.error e.backtrace.join("\n")
168
+ self.exception e
149
169
  end
150
170
  end
151
171
 
152
172
  private
153
- # private function for initialize
173
+ # Private function for initialize
154
174
  def init(path, opt={})
155
175
  func_name = "[#{self.to_s}.init]"
156
176
  @debug = true if opt[:debug]
157
177
 
158
- dput "#{func_name} path: #{path}, opt: #{opt}"
178
+ output_debug "#{func_name} path: #{path}, opt: #{opt}"
159
179
  _path = ''
160
180
  if path.is_a?(String)
161
181
  rails_flag = false
@@ -168,10 +188,10 @@ class ExtLogger
168
188
  _path = path
169
189
  end
170
190
  _path = _path.gsub('./', ::Dir.pwd + '/')
171
- set_path(_path) # save original log path with postfix
191
+ set_path(_path) # Save original log path
172
192
  end
173
193
 
174
- # check the directory is exist.
194
+ # Check the directory is exist.
175
195
  if !::Dir.exist?(_path)
176
196
  _path_array = _path.split('/').select{|item| !item.nil? && item != ''}
177
197
  _path = rails_flag ? rails_root : ''
@@ -183,15 +203,15 @@ class ExtLogger
183
203
  end
184
204
  end
185
205
 
186
- # process parameters
206
+ # Process parameters
187
207
  if !is_blank?(opt[:split_format])
188
208
  set_split_format(opt[:split_format])
189
209
  end
190
- dput "#{func_name} split_format: #{get_split_format}"
210
+ output_debug "#{func_name} split_format: #{get_split_format}"
191
211
  end
192
212
 
193
213
 
194
- # check postfix contain the format member
214
+ # Check split_format contain the format member
195
215
  def has_date_format_member
196
216
  func_name = "[#{self.to_s}.has_date_format_member]"
197
217
 
@@ -205,11 +225,11 @@ class ExtLogger
205
225
  end
206
226
  end
207
227
 
208
- dput "#{func_name} @log_split_format: #{@log_split_format}, _has_flag: #{_has_flag}"
228
+ output_debug "#{func_name} @log_split_format: #{@log_split_format}, _has_flag: #{_has_flag}"
209
229
  return _has_flag
210
230
  end
211
231
 
212
- # split log file
232
+ # Split log file
213
233
  def split_file
214
234
  func_name = "[#{self.to_s}.split_file]"
215
235
  if has_date_format_member
@@ -222,13 +242,13 @@ class ExtLogger
222
242
  end
223
243
 
224
244
  if File.exist?(_file_path)
225
- # get create datetime of file
245
+ # Get create datetime of current log file
226
246
  _file_date = File.ctime(_file_path)
227
- dput "#{func_name} Current log ctime: ##{_file_date}, mtime: #{File.atime(_file_path)}, atime: #{File.mtime(_file_path)}"
247
+ output_debug "#{func_name} Current log ctime: ##{_file_date}, mtime: #{File.atime(_file_path)}, atime: #{File.mtime(_file_path)}"
228
248
 
229
249
  _now_time = Time.now
230
- _split_format = get_split_format.gsub('%S', '')
231
- dput "#{func_name} _now_time: #{_now_time.strftime(_split_format)}"
250
+ _split_format = get_split_format.gsub('%S', '').gsub('%s', '') if !@debug # Non-debug state, does not support seconds splitting files.
251
+ output_debug "#{func_name} _now_time: #{_now_time.strftime(_split_format)}"
232
252
  if _file_date.strftime(_split_format) != _now_time.strftime(_split_format)
233
253
  @logger.close
234
254
 
@@ -246,63 +266,65 @@ class ExtLogger
246
266
  end
247
267
  end
248
268
 
249
- # check output flag & env
250
- def put_to_console(*args)
269
+ # Check output flag & env
270
+ def output_normal(*args)
251
271
  _flag = false
252
272
  _flag = rails_env != ENV_HASH[:pro] if @output_flag
253
273
 
254
274
  if args.size > 1
255
275
  func_name = "[@logger.#{args[0]}]"
256
- dput "#{func_name} *args: #{args}"
276
+ output_debug "#{func_name} *args: #{args}"
257
277
 
258
278
  puts "#{args[0]}: #{args[1]}" if args[1].is_a?(String)
259
279
  end
260
- split_file # split file with split_format
280
+ split_file # Split file with split_format
261
281
  end
262
282
 
263
- # set log path
283
+ # Set log path
264
284
  def set_path(str)
265
285
  @log_path = str
266
286
  end
267
287
 
268
- # get log path
288
+ # Get log path
269
289
  def get_path
270
290
  return @log_path
271
291
  end
272
292
 
273
- # set format for log name
293
+ # Set format for split character
274
294
  def set_split_format(str)
275
295
  @log_split_format = "_#{str.to_s}" if str.is_a?(String) && !is_blank?(str)
276
296
  end
277
297
 
298
+ # Get format for split character
278
299
  def get_split_format
279
300
  return @log_split_format
280
301
  end
281
302
 
282
- # validation the Rails object
303
+ # Validation the Rails object
283
304
  def valid_rails
284
305
  defined?(::Rails)
285
306
  end
286
307
 
287
- # get the path of folder or rails project
308
+ # Get the path of folder or rails project
288
309
  def rails_root
289
310
  valid_rails && ::Rails.root ? ::Rails.root.to_s : ::Dir.pwd
290
311
  end
291
312
 
292
- # get the env
313
+ # Get the env
293
314
  def rails_env
294
315
  valid_rails && ::Rails.env ? ::Rails.env : ENV_HASH[:dev]
295
316
  end
296
317
 
318
+ # Empty judgement for object
297
319
  def is_blank?(obj)
298
320
  func_name = "[#{self.to_s}.is_blank?]"
299
- # dput "#{func_name} obj.class: #{obj.class}"
321
+ output_debug "#{func_name} obj.class: #{obj.class}"
300
322
  return true if obj.nil?
301
323
  return (obj.is_a?(String) || obj.is_a?(Array) || obj.is_a?(Hash)) && obj.empty?
302
324
  end
303
325
 
304
- # puts to console by debug=true
305
- def dput(str)
326
+ # Put content to console by debug=true
327
+ def output_debug(str)
306
328
  puts str if @debug
307
329
  end
308
330
 
@@ -1,4 +1,4 @@
1
1
  require 'logger'
2
2
  class ExtLogger < Logger
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ext_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruby
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-06 00:00:00.000000000 Z
11
+ date: 2018-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,12 +38,8 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
- description: |2
42
-
43
- Extended Logger class, log output to console in non-production environment.\n
44
- Additional instance method ‘record_memory’ to record memory consumption.\n
45
- 2018-12-06(0.2.0): The internal structure changes greatly, adding hash parameters: age (shift_age with Logger object), size (shift_size with Logger object), split_format (log file output according to Ruby time format).\n
46
- 2018-11-28(0.1.3): Fixed a path problem during log initialization.
41
+ description: 'Extended Logger class, output log content to console in non-production
42
+ environment. Auto split log file by parameters:split_format '
47
43
  email:
48
44
  - wu.chao@maisiteng.com
49
45
  executables: []
@@ -93,5 +89,5 @@ rubyforge_project:
93
89
  rubygems_version: 2.6.12
94
90
  signing_key:
95
91
  specification_version: 4
96
- summary: Extended Logger class, log output to console in non-production environment.
92
+ summary: Extended Logger class, output log content to console in non-production environment.
97
93
  test_files: []