ext_logger 0.2.3 → 0.2.4

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: e327be78a79e86fbf1a18f53a45b76f934ffd52a
4
- data.tar.gz: 591b1655e9ca5ab4f342f703e5c0c38ed75c10c1
3
+ metadata.gz: d139d7caebd5dfb7ce8369a0c6e0eb71f0acf7fc
4
+ data.tar.gz: 589e394683491926ffb694d9c028595a674cf8e5
5
5
  SHA512:
6
- metadata.gz: cc5b0daedf948dedcdb23c713b5becbe947c3b144b862f987a3ba38ce0a42effa8428c9d3a384e8b90086c3ac84854bfc90a32c6dffe0bf3fecb871b8ab495d4
7
- data.tar.gz: 5c214bbf6cbbb836ecfe647603e19c92090d6c7646c98db31ff84a8076d9531adba6d9c483e78351aefda9abecef100acf2e5d430e90cb21eda33bdd0c9a81ec
6
+ metadata.gz: 9f14db2c9cd8100d4161e42ee83bc3cee6e60c33b8f43ba5cb6d4534d9b64e6a57f0895bb5da9a0b693c57b532f236049039540c335ff6318d2f306ea216c627
7
+ data.tar.gz: 94f8f05469f849d810d815d597202f764dd5253ac50ebc5d5609720b07c21baa977e8eeb267d86f57576bd3b8258e1605e4a5a2ed38b5fdc8a39ff9137a341b2
data/.idea/ext_logger.iml CHANGED
@@ -7,7 +7,6 @@
7
7
  <content url="file://$MODULE_DIR$" />
8
8
  <orderEntry type="jdk" jdkName="RVM: ruby-2.3.1 [gem_ext_logger]" jdkType="RUBY_SDK" />
9
9
  <orderEntry type="sourceFolder" forTests="false" />
10
- <orderEntry type="library" scope="PROVIDED" name="bundler (v1.17.1, RVM: ruby-2.3.1 [gem_ext_logger]) [gem]" level="application" />
11
10
  <orderEntry type="library" scope="PROVIDED" name="rake (v10.4.2, RVM: ruby-2.3.1 [gem_ext_logger]) [gem]" level="application" />
12
11
  </component>
13
12
  </module>
data/.idea/workspace.xml CHANGED
@@ -2,8 +2,10 @@
2
2
  <project version="4">
3
3
  <component name="ChangeListManager">
4
4
  <list default="true" id="09d7e2e9-1cd6-481d-b2bb-16f8f2694524" name="Default" comment="">
5
+ <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/lib/ext_logger/common.rb" />
5
6
  <change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/ext_logger.iml" afterPath="$PROJECT_DIR$/.idea/ext_logger.iml" />
6
7
  <change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
8
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/README.md" afterPath="$PROJECT_DIR$/README.md" />
7
9
  <change type="MODIFICATION" beforePath="$PROJECT_DIR$/lib/ext_logger/main.rb" afterPath="$PROJECT_DIR$/lib/ext_logger/main.rb" />
8
10
  </list>
9
11
  <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@@ -18,74 +20,27 @@
18
20
  <file leaf-file-name="main.rb" pinned="false" current-in-tab="true">
19
21
  <entry file="file://$PROJECT_DIR$/lib/ext_logger/main.rb">
20
22
  <provider selected="true" editor-type-id="text-editor">
21
- <state relative-caret-position="326">
22
- <caret line="241" column="25" lean-forward="true" selection-start-line="241" selection-start-column="25" selection-end-line="241" selection-end-column="25" />
23
+ <state relative-caret-position="116">
24
+ <caret line="59" column="18" lean-forward="false" selection-start-line="59" selection-start-column="18" selection-end-line="59" selection-end-column="18" />
23
25
  <folding />
24
26
  </state>
25
27
  </provider>
26
28
  </entry>
27
29
  </file>
28
- <file leaf-file-name="version.rb" pinned="false" current-in-tab="false">
29
- <entry file="file://$PROJECT_DIR$/lib/ext_logger/version.rb">
30
+ <file leaf-file-name="common.rb" pinned="false" current-in-tab="false">
31
+ <entry file="file://$PROJECT_DIR$/lib/ext_logger/common.rb">
30
32
  <provider selected="true" editor-type-id="text-editor">
31
- <state relative-caret-position="45">
32
- <caret line="3" column="0" lean-forward="false" selection-start-line="3" selection-start-column="0" selection-end-line="3" selection-end-column="0" />
33
+ <state relative-caret-position="210">
34
+ <caret line="14" column="6" lean-forward="false" selection-start-line="14" selection-start-column="6" selection-end-line="14" selection-end-column="6" />
33
35
  <folding />
34
36
  </state>
35
37
  </provider>
36
38
  </entry>
37
39
  </file>
38
- <file leaf-file-name="ext_logger.rb" pinned="false" current-in-tab="false">
39
- <entry file="file://$PROJECT_DIR$/lib/ext_logger.rb">
40
- <provider selected="true" editor-type-id="text-editor">
41
- <state relative-caret-position="30">
42
- <caret line="2" column="6" lean-forward="false" selection-start-line="2" selection-start-column="6" selection-end-line="5" selection-end-column="5" />
43
- <folding />
44
- </state>
45
- </provider>
46
- </entry>
47
- </file>
48
- <file leaf-file-name="ext_logger.gemspec" pinned="false" current-in-tab="false">
49
- <entry file="file://$PROJECT_DIR$/ext_logger.gemspec">
50
- <provider selected="true" editor-type-id="text-editor">
51
- <state relative-caret-position="45">
52
- <caret line="3" column="28" lean-forward="false" selection-start-line="3" selection-start-column="28" selection-end-line="3" selection-end-column="28" />
53
- <folding />
54
- </state>
55
- </provider>
56
- </entry>
57
- </file>
58
- <file leaf-file-name="README.md" pinned="false" current-in-tab="false">
59
- <entry file="file://$PROJECT_DIR$/README.md">
60
- <provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
61
- <state split_layout="SPLIT">
62
- <first_editor relative-caret-position="90">
63
- <caret line="6" column="16" lean-forward="false" selection-start-line="6" selection-start-column="16" selection-end-line="6" selection-end-column="16" />
64
- <folding />
65
- </first_editor>
66
- <second_editor />
67
- </state>
68
- </provider>
69
- </entry>
70
- </file>
71
40
  </leaf>
72
41
  </component>
73
42
  <component name="FindInProjectRecents">
74
43
  <findStrings>
75
- <find>root_path</find>
76
- <find>ExtLogger.split_file</find>
77
- <find>self.is_blank?</find>
78
- <find>self.</find>
79
- <find>split_postfix</find>
80
- <find>@log_postfix_format</find>
81
- <find>_postfix</find>
82
- <find>puts</find>
83
- <find>@output_flag</find>
84
- <find>output?</find>
85
- <find>DATE_FORMAT_MEMBER_LIST</find>
86
- <find>postfix</find>
87
- <find>dput</find>
88
- <find>split_format</find>
89
44
  <find>_ext</find>
90
45
  <find>@log_path</find>
91
46
  <find>File.</find>
@@ -100,8 +55,22 @@
100
55
  <find>set_split_format</find>
101
56
  <find>get_split_format</find>
102
57
  <find>log_path</find>
103
- <find>get_path</find>
104
58
  <find>File.open</find>
59
+ <find>get_path</find>
60
+ <find>_flag</find>
61
+ <find>output</find>
62
+ <find>@debug</find>
63
+ <find>log_max_count</find>
64
+ <find>self.class.to_s</find>
65
+ <find>ENV</find>
66
+ <find>ENV_HASH</find>
67
+ <find>output_debug</find>
68
+ <find>DATE_FORMAT_MEMBER_LIST</find>
69
+ <find>LOG_NAME</find>
70
+ <find>Dir</find>
71
+ <find>Dir.exist?</find>
72
+ <find>rails_flag</find>
73
+ <find>set_dev</find>
105
74
  </findStrings>
106
75
  <replaceStrings>
107
76
  <replace>now_time</replace>
@@ -120,9 +89,11 @@
120
89
  <replace>split_format</replace>
121
90
  <replace>output_debug</replace>
122
91
  <replace>self.class.to_s</replace>
92
+ <replace>get_instance_name</replace>
123
93
  </replaceStrings>
124
94
  <dirStrings>
125
95
  <dir>$PROJECT_DIR$</dir>
96
+ <dir>$PROJECT_DIR$/lib/ext_logger</dir>
126
97
  </dirStrings>
127
98
  </component>
128
99
  <component name="Git.Settings">
@@ -136,8 +107,10 @@
136
107
  <option value="$PROJECT_DIR$/lib/ext_logger/ext_logger.rb" />
137
108
  <option value="$PROJECT_DIR$/lib/ext_logger/version.rb" />
138
109
  <option value="$PROJECT_DIR$/lib/ext_logger.rb" />
139
- <option value="$PROJECT_DIR$/README.md" />
140
110
  <option value="$PROJECT_DIR$/ext_logger.gemspec" />
111
+ <option value="$PROJECT_DIR$/README.md" />
112
+ <option value="$PROJECT_DIR$/lib/ext_logger/debug.rb" />
113
+ <option value="$PROJECT_DIR$/lib/ext_logger/common.rb" />
141
114
  <option value="$PROJECT_DIR$/lib/ext_logger/main.rb" />
142
115
  </list>
143
116
  </option>
@@ -148,9 +121,11 @@
148
121
  <detection-done>true</detection-done>
149
122
  <sorting>DEFINITION_ORDER</sorting>
150
123
  </component>
151
- <component name="ProjectFrameBounds" fullScreen="true">
124
+ <component name="ProjectFrameBounds">
125
+ <option name="x" value="231" />
126
+ <option name="y" value="97" />
152
127
  <option name="width" value="1280" />
153
- <option name="height" value="800" />
128
+ <option name="height" value="727" />
154
129
  </component>
155
130
  <component name="ProjectView">
156
131
  <navigator currentView="ProjectPane" proportions="" version="1">
@@ -208,14 +183,14 @@
208
183
  <property name="WebServerToolWindowFactoryState" value="false" />
209
184
  </component>
210
185
  <component name="RecentsManager">
211
- <key name="CopyFile.RECENT_KEYS">
212
- <recent name="$PROJECT_DIR$/lib/ext_logger" />
213
- <recent name="$PROJECT_DIR$" />
214
- </key>
215
186
  <key name="MoveFile.RECENT_KEYS">
216
187
  <recent name="$PROJECT_DIR$" />
217
188
  <recent name="$PROJECT_DIR$/pkg" />
218
189
  </key>
190
+ <key name="CopyFile.RECENT_KEYS">
191
+ <recent name="$PROJECT_DIR$/lib/ext_logger" />
192
+ <recent name="$PROJECT_DIR$" />
193
+ </key>
219
194
  </component>
220
195
  <component name="RunDashboard">
221
196
  <option name="ruleStates">
@@ -256,25 +231,24 @@
256
231
  <workItem from="1547566862204" duration="231000" />
257
232
  <workItem from="1547644478267" duration="804000" />
258
233
  <workItem from="1547892125756" duration="3024000" />
259
- <workItem from="1547895733301" duration="5600000" />
234
+ <workItem from="1547895733301" duration="22708000" />
260
235
  </task>
261
236
  <servers />
262
237
  </component>
263
238
  <component name="TimeTrackingManager">
264
- <option name="totallyTimeSpent" value="50295000" />
239
+ <option name="totallyTimeSpent" value="67403000" />
265
240
  </component>
266
241
  <component name="ToolWindowManager">
267
- <frame x="0" y="0" width="1280" height="800" extended-state="0" />
268
- <editor active="true" />
242
+ <frame x="231" y="97" width="1280" height="727" extended-state="0" />
269
243
  <layout>
270
- <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.21683876" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
244
+ <window_info id="Project" active="true" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.21683876" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
271
245
  <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" />
272
246
  <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" />
273
247
  <window_info id="Find" 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="1" side_tool="false" content_ui="tabs" />
274
248
  <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" />
275
249
  <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" />
276
250
  <window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.2494043" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
277
- <window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.2777778" sideWeight="0.5" order="8" side_tool="false" content_ui="tabs" />
251
+ <window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.2777778" sideWeight="0.5" order="8" side_tool="false" content_ui="tabs" />
278
252
  <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" />
279
253
  <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" />
280
254
  <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" />
@@ -298,22 +272,6 @@
298
272
  <watches-manager />
299
273
  </component>
300
274
  <component name="editorHistoryManager">
301
- <entry file="file://$PROJECT_DIR$/lib/ext_logger/main.rb">
302
- <provider selected="true" editor-type-id="text-editor">
303
- <state relative-caret-position="3105">
304
- <caret line="207" column="18" lean-forward="false" selection-start-line="207" selection-start-column="18" selection-end-line="207" selection-end-column="18" />
305
- <folding />
306
- </state>
307
- </provider>
308
- </entry>
309
- <entry file="file://$PROJECT_DIR$/ext_logger.gemspec">
310
- <provider selected="true" editor-type-id="text-editor">
311
- <state relative-caret-position="195">
312
- <caret line="13" column="217" lean-forward="false" selection-start-line="13" selection-start-column="217" selection-end-line="13" selection-end-column="217" />
313
- <folding />
314
- </state>
315
- </provider>
316
- </entry>
317
275
  <entry file="file://$PROJECT_DIR$/lib/ext_logger.rb">
318
276
  <provider selected="true" editor-type-id="text-editor">
319
277
  <state relative-caret-position="90">
@@ -595,59 +553,76 @@
595
553
  </state>
596
554
  </provider>
597
555
  </entry>
556
+ <entry file="file://$USER_HOME$/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/logger.rb">
557
+ <provider selected="true" editor-type-id="text-editor">
558
+ <state relative-caret-position="2850">
559
+ <caret line="345" column="50" lean-forward="false" selection-start-line="345" selection-start-column="40" selection-end-line="345" selection-end-column="50" />
560
+ </state>
561
+ </provider>
562
+ </entry>
598
563
  <entry file="file://$PROJECT_DIR$/Gemfile">
599
564
  <provider selected="true" editor-type-id="text-editor">
600
565
  <state relative-caret-position="0">
601
566
  <caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
567
+ <folding />
602
568
  </state>
603
569
  </provider>
604
570
  </entry>
605
- <entry file="file://$USER_HOME$/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/logger.rb">
571
+ <entry file="file://$PROJECT_DIR$/lib/ext_logger.rb">
606
572
  <provider selected="true" editor-type-id="text-editor">
607
- <state relative-caret-position="2850">
608
- <caret line="345" column="50" lean-forward="false" selection-start-line="345" selection-start-column="40" selection-end-line="345" selection-end-column="50" />
573
+ <state relative-caret-position="90">
574
+ <caret line="6" column="0" lean-forward="false" selection-start-line="6" selection-start-column="0" selection-end-line="6" selection-end-column="0" />
575
+ <folding />
576
+ </state>
577
+ </provider>
578
+ </entry>
579
+ <entry file="file://$PROJECT_DIR$/ext_logger.gemspec">
580
+ <provider selected="true" editor-type-id="text-editor">
581
+ <state relative-caret-position="75">
582
+ <caret line="5" column="16" lean-forward="false" selection-start-line="5" selection-start-column="16" selection-end-line="5" selection-end-column="16" />
583
+ <folding />
609
584
  </state>
610
585
  </provider>
611
586
  </entry>
612
587
  <entry file="file://$PROJECT_DIR$/README.md">
613
588
  <provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
614
589
  <state split_layout="SPLIT">
615
- <first_editor relative-caret-position="90">
616
- <caret line="6" column="16" lean-forward="false" selection-start-line="6" selection-start-column="16" selection-end-line="6" selection-end-column="16" />
590
+ <first_editor relative-caret-position="-448">
591
+ <caret line="7" column="19" lean-forward="false" selection-start-line="7" selection-start-column="19" selection-end-line="7" selection-end-column="19" />
617
592
  <folding />
618
593
  </first_editor>
619
594
  <second_editor />
620
595
  </state>
621
596
  </provider>
622
597
  </entry>
623
- <entry file="file://$PROJECT_DIR$/ext_logger.gemspec">
598
+ <entry file="file://$PROJECT_DIR$/lib/ext_logger/version.rb">
624
599
  <provider selected="true" editor-type-id="text-editor">
625
600
  <state relative-caret-position="45">
626
- <caret line="3" column="28" lean-forward="false" selection-start-line="3" selection-start-column="28" selection-end-line="3" selection-end-column="28" />
601
+ <caret line="3" column="0" lean-forward="false" selection-start-line="3" selection-start-column="0" selection-end-line="3" selection-end-column="0" />
627
602
  <folding />
628
603
  </state>
629
604
  </provider>
630
605
  </entry>
631
- <entry file="file://$PROJECT_DIR$/lib/ext_logger.rb">
606
+ <entry file="file://$PROJECT_DIR$/lib/ext_logger/debug.rb">
632
607
  <provider selected="true" editor-type-id="text-editor">
633
- <state relative-caret-position="30">
634
- <caret line="2" column="6" lean-forward="false" selection-start-line="2" selection-start-column="6" selection-end-line="5" selection-end-column="5" />
608
+ <state relative-caret-position="45">
609
+ <caret line="3" column="64" lean-forward="false" selection-start-line="3" selection-start-column="64" selection-end-line="3" selection-end-column="64" />
635
610
  <folding />
636
611
  </state>
637
612
  </provider>
638
613
  </entry>
639
- <entry file="file://$PROJECT_DIR$/lib/ext_logger/version.rb">
614
+ <entry file="file://$PROJECT_DIR$/lib/ext_logger/common.rb">
640
615
  <provider selected="true" editor-type-id="text-editor">
641
- <state relative-caret-position="45">
642
- <caret line="3" column="0" lean-forward="false" selection-start-line="3" selection-start-column="0" selection-end-line="3" selection-end-column="0" />
616
+ <state relative-caret-position="210">
617
+ <caret line="14" column="6" lean-forward="false" selection-start-line="14" selection-start-column="6" selection-end-line="14" selection-end-column="6" />
643
618
  <folding />
644
619
  </state>
645
620
  </provider>
646
621
  </entry>
647
622
  <entry file="file://$PROJECT_DIR$/lib/ext_logger/main.rb">
648
623
  <provider selected="true" editor-type-id="text-editor">
649
- <state relative-caret-position="326">
650
- <caret line="241" column="25" lean-forward="true" selection-start-line="241" selection-start-column="25" selection-end-line="241" selection-end-column="25" />
624
+ <state relative-caret-position="116">
625
+ <caret line="59" column="18" lean-forward="false" selection-start-line="59" selection-start-column="18" selection-end-line="59" selection-end-column="18" />
651
626
  <folding />
652
627
  </state>
653
628
  </provider>
data/README.md CHANGED
@@ -3,11 +3,14 @@
3
3
  Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ext_logger`. To experiment with that code, run `bin/console` for an interactive prompt.
4
4
 
5
5
  ```explain
6
- Extended Logger class, log output to console in non-production environment.
6
+ Extended Logger class, log output to console in non-production environment.
7
+ Other extensions see version updates.
8
+ 2019-01-21(0.2.4):
9
+ Fix some bugs.
10
+ Common methods are extracted into separate modules for later use by other classes.
11
+
7
12
  2019-01-20(0.2.3):
8
- The internal structure changes greatly.
9
- Adding hash parameters:
10
- :log_max_num (keep the latest number of log files according to the parameter values, and delete the redundancy),
13
+ Fix some bugs.
11
14
 
12
15
  2018-12-25(0.2.2):
13
16
  The internal structure changes greatly.
@@ -0,0 +1,133 @@
1
+ class ExtLogger
2
+
3
+ module Common
4
+
5
+ # Get class name
6
+ def get_class_name
7
+ self.class.to_s
8
+ end
9
+
10
+ # Get instance name
11
+ def get_instance_name
12
+ self.class.to_s.downcase
13
+ end
14
+
15
+ # Set debug
16
+ def set_debug(_bool=true)
17
+ @debug = _bool # Controller debug content output to console
18
+ end
19
+
20
+ def get_debug
21
+ return @debug || false
22
+ end
23
+
24
+ # Put content to console by debug=true
25
+ def output_debug(str)
26
+ puts str if @debug
27
+ end
28
+
29
+ # Validation the Rails object
30
+ def valid_rails
31
+ defined?(::Rails)
32
+ end
33
+
34
+ # Get the path of folder or rails project
35
+ def rails_root
36
+ valid_rails && ::Rails.root ? ::Rails.root.to_s : ::Dir.pwd
37
+ end
38
+
39
+ ENV_HASH = {
40
+ dev: 'development',
41
+ stg: 'staging',
42
+ pro: 'production',
43
+ }
44
+ # Get the env
45
+ def rails_env
46
+ valid_rails && ::Rails.env ? ::Rails.env : ENV_HASH[:dev]
47
+ end
48
+
49
+ # File operate
50
+ # Check the folder and create it when it is not exist.
51
+ def mkdir_more(file_path)
52
+ begin
53
+ require 'FileUtils' if !defined? FileUtils
54
+ FileUtils.mkdir_p(File.dirname(file_path))
55
+ rescue Exception => e
56
+ puts e.message + "\n" + e.backtrace.join("\n")
57
+ end
58
+
59
+ # rails_flag = true if path.include?(rails_root)
60
+ # if !::Dir.exist?(_path)
61
+ # _path_array = _path.split('/').select{|item| !item.nil? && item != ''}
62
+ # _path = rails_flag ? rails_root : ''
63
+ #
64
+ # _path_array.each_with_index do |item, idx|
65
+ # break if idx >= _path_array.length - 1
66
+ # _path += '/' + item
67
+ # ::Dir.mkdir(_path) if !::Dir.exist?(_path)
68
+ # end
69
+ # end
70
+ end
71
+
72
+ # String
73
+ # Empty judgement for object
74
+ def is_blank?(obj)
75
+ func_name = "[#{get_instance_name}.is_blank?]"
76
+ output_debug "#{func_name} obj.class: #{obj.class}"
77
+ return true if obj.nil?
78
+ return (obj.is_a?(String) || obj.is_a?(Array) || obj.is_a?(Hash)) && obj.empty?
79
+ end
80
+
81
+ # date & time
82
+ TIME_MS_DAY = 24 * 60 * 60 * 1000 # Day with millisecond
83
+ TIME_MS_HOUR = 60 * 60 * 1000 # Hour with millisecond
84
+ TIME_MS_MIDDLE = 60 * 1000 # Middle with millisecond
85
+ TIME_MS_SECOND = 1000 # Second with millisecond
86
+
87
+ TIME_UNIT_DAY = 'day '
88
+ TIME_UNIT_HOUR = ':'
89
+ TIME_UNIT_MIDDLE = ':'
90
+ TIME_UNIT_SECOND = ' '
91
+ TIME_UNIT_MILLISECOND = 'ms'
92
+
93
+ # Formatting time difference
94
+ def format_sub_time(start_time, end_time)
95
+ use_time = (end_time - start_time).to_i
96
+ time_list = []
97
+
98
+ if use_time > TIME_MS_DAY
99
+ remainder_time = use_time % TIME_MS_DAY
100
+ num = (use_time - remainder_time) / TIME_MS_DAY
101
+ time_list << "#{num}#{TIME_UNIT_DAY}"
102
+ use_time = remainder_time
103
+ end
104
+
105
+ if use_time > TIME_MS_HOUR
106
+ remainder_time = use_time % TIME_MS_HOUR
107
+ num = (use_time - remainder_time) / TIME_MS_HOUR
108
+ time_list << "#{num}#{TIME_UNIT_HOUR}"
109
+ use_time = remainder_time
110
+ end
111
+
112
+ if use_time > TIME_MS_MIDDLE
113
+ remainder_time = use_time % TIME_MS_MIDDLE
114
+ num = (use_time - remainder_time) / TIME_MS_MIDDLE
115
+ time_list << "#{num}#{TIME_UNIT_MIDDLE}"
116
+ use_time = remainder_time
117
+ end
118
+
119
+ if use_time > TIME_MS_SECOND
120
+ remainder_time = use_time % TIME_MS_SECOND
121
+ num = (use_time - remainder_time) / TIME_MS_SECOND
122
+ time_list << "#{num}#{TIME_UNIT_SECOND}"
123
+ use_time = remainder_time
124
+ end
125
+
126
+ if use_time > 0
127
+ time_list << "#{use_time}#{TIME_UNIT_MILLISECOND}"
128
+ end
129
+
130
+ return time_list.join('')
131
+ end
132
+ end
133
+ end
@@ -1,24 +1,12 @@
1
1
  require 'logger'
2
+ require 'ext_logger/common'
2
3
  # require 'rails'
3
4
 
4
5
  class ExtLogger
6
+ include Common
5
7
 
6
8
  DATE_FORMAT_MEMBER_LIST = %w(%Y %y %m %d %wday %H %M %S)
7
9
  LOG_NAME = '{log_name}' # Log name pseudo-code
8
- ENV_HASH = {
9
- dev: 'development',
10
- stg: 'staging',
11
- pro: 'production',
12
- }
13
-
14
- @debug = false # Controller debug content output to console
15
- @logger = nil # Initialize logger object
16
- @log_path = '' # Log path
17
- @log_folder = '' # Log folder
18
- @log_file_name = '' # Log file name
19
- @log_split_format = '' # Split format character in log, default blank.
20
- @log_max_num = 0 # Retain the latest number of log files.
21
- @output_flag = true # Controller normal content output to console
22
10
 
23
11
  # Initialize, next is parameters:
24
12
  # 1rst: log path (Default parameter)
@@ -31,6 +19,17 @@ class ExtLogger
31
19
  def initialize(*args)
32
20
  func_name = "[#{self.class.to_s}.initialize]"
33
21
  output_debug "#{func_name} args.size: #{args.size}"
22
+
23
+ # Instance variables
24
+ # @debug = false # Controller debug content output to console
25
+ @logger = nil # Initialize logger object
26
+ @log_path = '' # Log path
27
+ @log_folder = '' # Log folder
28
+ @log_file_name = '' # Log file name
29
+ @log_split_format = '' # Split format character in log, default blank.
30
+ @log_max_num = 0 # Retain the latest number of log files.
31
+ @output_flag = true # Controller normal content output to console
32
+
34
33
  init(args[0]) if args.size == 1
35
34
 
36
35
  if args.size == 2
@@ -49,14 +48,10 @@ class ExtLogger
49
48
  end
50
49
  end
51
50
 
51
+ # ExtTest.new()
52
52
  @logger = Logger.new(*args)
53
53
  end
54
54
 
55
- # Set debug
56
- def set_debug(_bool=true)
57
- @debug = _bool
58
- end
59
-
60
55
  # Set output flag
61
56
  def set_output_flag(type=true)
62
57
  @output_flag = type
@@ -104,15 +99,11 @@ class ExtLogger
104
99
 
105
100
  # Output exception
106
101
  def exception(*args)
107
- func_name = "[@logger.EXCEPTION]"
102
+ func_name = "[#{get_instance_name}.exception]"
108
103
 
109
104
  if args.size == 1
110
- output_debug "#{func_name} args[0].class: #{args[0].class}"
111
- if !args[0].class.to_s.include?('Error')
112
- @logger.error("The object 'e:#{args[0].to_s}' is not exception. e.class: #{args[0].class}")
113
- return
114
- end
115
- str = args[0].message + args[0].backtrace.join("\n")
105
+ str = analysis_exception(args[0])
106
+ return if is_blank?(str)
116
107
  args = [str]
117
108
  end
118
109
  output_normal('EXCEPTION', *args)
@@ -140,6 +131,18 @@ class ExtLogger
140
131
  end
141
132
  end
142
133
 
134
+ # Analysis exception object
135
+ def analysis_exception(e)
136
+ func_name = "[#{get_instance_name}.analysis_exception]"
137
+ output_debug "#{func_name} e.class: #{e.class}"
138
+ if !e.class.to_s.include?('Error')
139
+ @logger.error("The object 'e:#{e.to_s}' is not exception. e.class: #{e.class}")
140
+ return nil
141
+ end
142
+ str = e.message + "\n" + e.backtrace.join("\n")
143
+ return str
144
+ end
145
+
143
146
  # Output the memory usage
144
147
  # Example: record_memory()
145
148
  # Example: record_memory('end')
@@ -188,39 +191,29 @@ class ExtLogger
188
191
  end
189
192
  end
190
193
 
191
- private
194
+ # private
192
195
  # Private function for initialize
193
196
  def init(path, opt={})
194
- func_name = "[#{self.class.to_s}.init]"
195
- @debug = true if opt[:debug]
197
+ func_name = "[#{get_class_name}:private init]"
198
+ set_debug(true) if opt[:debug]
196
199
 
197
200
  output_debug "#{func_name} path: #{path}, opt: #{opt}"
198
- _path = ''
201
+ puts "#{func_name} path: #{path}, opt: #{opt}"
202
+ _path = path
199
203
  if path.is_a?(String)
200
- rails_flag = false
201
- if path.include?(rails_root)
202
- _path = path.gsub(rails_root, '')
203
- _path = '/log/' + _path if !_path.include?('log/')
204
- _path = _path.gsub('//', '/')
205
- rails_flag = true
206
- else
207
- _path = path
208
- end
209
- _path = _path.gsub('./', ::Dir.pwd + '/')
204
+ # if path.include?(rails_root)
205
+ # _path = path.gsub(rails_root, '')
206
+ # _path = '/log/' + _path if !_path.include?('log/')
207
+ # _path = _path.gsub('//', '/')
208
+ # else
209
+ # _path = path
210
+ # end
211
+ # _path = _path.gsub('./', ::Dir.pwd + '/')
210
212
  set_path(_path) # Save original log path
211
213
  end
212
214
 
213
- # Check the directory is exist.
214
- if !::Dir.exist?(_path)
215
- _path_array = _path.split('/').select{|item| !item.nil? && item != ''}
216
- _path = rails_flag ? rails_root : ''
217
-
218
- _path_array.each_with_index do |item, idx|
219
- break if idx >= _path_array.length - 1
220
- _path += '/' + item
221
- ::Dir.mkdir(_path) if !::Dir.exist?(_path)
222
- end
223
- end
215
+ # Check the folder and create it.
216
+ mkdir_more(_path)
224
217
 
225
218
  # Process parameters
226
219
  if !is_blank?(opt[:split_format])
@@ -239,15 +232,16 @@ class ExtLogger
239
232
 
240
233
  # Check: Does the log file exist? If not, create it immediately
241
234
  def check_log_file
235
+ func_name = "[#{get_class_name}:private check_log_file]"
242
236
  _file_path = get_path
237
+ puts "#{func_name} _file_path ### #{_file_path}"
243
238
  # File.new(_file_path, 'w+') if !File.exist?(_file_path)
244
239
  @logger = Logger.new(_file_path) if !File.exist?(_file_path)
245
240
  end
246
241
 
247
-
248
242
  # Check split_format contain the format member
249
243
  def has_date_format_member
250
- func_name = "[#{self.class.to_s}.has_date_format_member]"
244
+ func_name = "[#{get_class_name}:private has_date_format_member]"
251
245
 
252
246
  _has_flag = false
253
247
  return _has_flag if is_blank?(@log_split_format) || !@log_split_format.include?('%')
@@ -265,7 +259,7 @@ class ExtLogger
265
259
 
266
260
  # Split log file, doesn't consider file extensions
267
261
  def split_file
268
- func_name = "[#{self.class.to_s}.split_file]"
262
+ func_name = "[#{get_class_name}:private split_file]"
269
263
  if has_date_format_member
270
264
  _file_path = get_path
271
265
  # _file_ext = ''
@@ -282,7 +276,7 @@ class ExtLogger
282
276
 
283
277
  _now_time = Time.now
284
278
  _split_format = get_split_format
285
- _split_format = _split_format.gsub('%S', '').gsub('%s', '') if !@debug # Non-debug state, does not support seconds splitting files.
279
+ _split_format = _split_format.gsub('%S', '').gsub('%s', '') if !get_debug # Non-debug state, does not support seconds splitting files.
286
280
  output_debug "#{func_name} split_format: #{_split_format}"
287
281
  output_debug "#{func_name} _now_time: #{_now_time.strftime(_split_format)}"
288
282
  if _file_date.strftime(_split_format) != _now_time.strftime(_split_format)
@@ -304,7 +298,7 @@ class ExtLogger
304
298
 
305
299
  # Delete redundant old log file
306
300
  def delete_redundant_file
307
- func_name = "[#{self.class.to_s}.delete_redundant_file]"
301
+ func_name = "[#{get_class_name}:private delete_redundant_file]"
308
302
  output_debug "#{func_name} get_log_max_num: #{get_log_max_num}"
309
303
  return if get_log_max_num == 0
310
304
 
@@ -329,11 +323,11 @@ class ExtLogger
329
323
 
330
324
  # Check output flag & env
331
325
  def output_normal(*args)
326
+ func_name = "[#{get_class_name}:private output_normal]"
332
327
  _flag = false
333
328
  _flag = rails_env != ENV_HASH[:pro] if @output_flag
334
329
 
335
330
  if args.size > 1
336
- func_name = "[@logger.#{args[0]}]"
337
331
  output_debug "#{func_name} *args: #{args}"
338
332
 
339
333
  puts "#{args[0]}: #{args[1]}" if args[1].is_a?(String)
@@ -386,33 +380,5 @@ class ExtLogger
386
380
  return @log_max_num || 0
387
381
  end
388
382
 
389
- # Validation the Rails object
390
- def valid_rails
391
- defined?(::Rails)
392
- end
393
-
394
- # Get the path of folder or rails project
395
- def rails_root
396
- valid_rails && ::Rails.root ? ::Rails.root.to_s : ::Dir.pwd
397
- end
398
-
399
- # Get the env
400
- def rails_env
401
- valid_rails && ::Rails.env ? ::Rails.env : ENV_HASH[:dev]
402
- end
403
-
404
- # Empty judgement for object
405
- def is_blank?(obj)
406
- func_name = "[#{self.class.to_s}.is_blank?]"
407
- output_debug "#{func_name} obj.class: #{obj.class}"
408
- return true if obj.nil?
409
- return (obj.is_a?(String) || obj.is_a?(Array) || obj.is_a?(Hash)) && obj.empty?
410
- end
411
-
412
- # Put content to console by debug=true
413
- def output_debug(str)
414
- puts str if @debug
415
- end
416
-
417
383
  end
418
384
 
@@ -1,3 +1,3 @@
1
1
  module ExtLogger
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  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.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruby
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-19 00:00:00.000000000 Z
11
+ date: 2019-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -65,6 +65,7 @@ files:
65
65
  - bin/setup
66
66
  - ext_logger.gemspec
67
67
  - lib/ext_logger.rb
68
+ - lib/ext_logger/common.rb
68
69
  - lib/ext_logger/main.rb
69
70
  - lib/ext_logger/version.rb
70
71
  homepage: ''