ext_logger 0.2.4 → 0.2.5

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: d139d7caebd5dfb7ce8369a0c6e0eb71f0acf7fc
4
- data.tar.gz: 589e394683491926ffb694d9c028595a674cf8e5
3
+ metadata.gz: bb68b59f8af66ac2bd1faf3121e7c5c4f91819d1
4
+ data.tar.gz: 066ce5f3c4fcae29670416f606a682c6ad83462f
5
5
  SHA512:
6
- metadata.gz: 9f14db2c9cd8100d4161e42ee83bc3cee6e60c33b8f43ba5cb6d4534d9b64e6a57f0895bb5da9a0b693c57b532f236049039540c335ff6318d2f306ea216c627
7
- data.tar.gz: 94f8f05469f849d810d815d597202f764dd5253ac50ebc5d5609720b07c21baa977e8eeb267d86f57576bd3b8258e1605e4a5a2ed38b5fdc8a39ff9137a341b2
6
+ metadata.gz: 9455adc45467fba0090acaf880cb3ae285d042054c10696fdc848dbe2df2b35380e49e77a157b420598454ced680acefcbf43ac88cdb4eb2f648604f419b7c1f
7
+ data.tar.gz: 46adef22447a8ff1b0cf336545f0b91037e75eaf37c97f507482dcd48a204ee8ff2309f613122b97298056e5fa18791e0cf4036795d9eee384b67cef6cf83f3e
data/README.md CHANGED
@@ -5,6 +5,10 @@ Welcome to your new gem! In this directory, you'll find the files you need to be
5
5
  ```explain
6
6
  Extended Logger class, log output to console in non-production environment.
7
7
  Other extensions see version updates.
8
+ 2019-01-22(0.2.5):
9
+ Fix some bugs.
10
+ Add method: analysis_exception to Common module.
11
+
8
12
  2019-01-21(0.2.4):
9
13
  Fix some bugs.
10
14
  Common methods are extracted into separate modules for later use by other classes.
@@ -55,43 +59,43 @@ Or install it yourself as:
55
59
  logger = ExtLogger.new(log_path, {age: 7/'weekly', size: 1024000, split_format: '%Y%m%d%H%M', log_max_num: 5})
56
60
  ```
57
61
 
58
- 2. Output of normal log (Extended logger.info):
62
+ 2. Output normal log (Extended logger.info):
59
63
 
60
64
  ```ruby
61
65
  logger.info("log content")
62
66
  ```
63
67
 
64
- 3. Output of debug log (Extended logger.info):
68
+ 3. Output debug log (Extended logger.info):
65
69
 
66
70
  ```ruby
67
71
  logger.debug("log content")
68
72
  ```
69
73
 
70
- 4. Output of error log (Extended logger.error):
74
+ 4. Output error log (Extended logger.error):
71
75
 
72
76
  ```ruby
73
77
  logger.error("log content")
74
78
  ```
75
79
 
76
- 5. Output of warning log (Extended logger.warn):
80
+ 5. Output warning log (Extended logger.warn):
77
81
 
78
82
  ```ruby
79
83
  logger.warn("log content")
80
84
  ```
81
85
 
82
- 6. Output of fatal log (Extended logger.fatal):
86
+ 6. Output fatal log (Extended logger.fatal):
83
87
 
84
88
  ```ruby
85
89
  logger.fatal("log content")
86
90
  ```
87
91
 
88
- 7. Output of exception log (Extended logger.error):
92
+ 7. Output exception log (Extended logger.error):
89
93
 
90
94
  ```ruby
91
95
  logger.exception(e) # when rescure Exception => e
92
96
  ```
93
97
 
94
- 8. Output of memory usage (Extended logger.warn):
98
+ 8. Output memory usage (Extended logger.warn):
95
99
 
96
100
  ```ruby
97
101
  logger.record_memory # at the begin of programme
@@ -23,7 +23,7 @@ class ExtLogger
23
23
 
24
24
  # Put content to console by debug=true
25
25
  def output_debug(str)
26
- puts str if @debug
26
+ puts "DEBUG_P: #{str}" if @debug
27
27
  end
28
28
 
29
29
  # Validation the Rails object
@@ -46,6 +46,18 @@ class ExtLogger
46
46
  valid_rails && ::Rails.env ? ::Rails.env : ENV_HASH[:dev]
47
47
  end
48
48
 
49
+ # Analysis exception object
50
+ def analysis_exception(e)
51
+ func_name = "[common.#{__method__.to_s}]"
52
+ output_debug "#{func_name} e.class: #{e.class}"
53
+ if !e.class.to_s.include?('Error')
54
+ @logger.error("The object 'e:#{e.to_s}' is not exception. e.class: #{e.class}")
55
+ return ''
56
+ end
57
+ str = e.message + "\n" + e.backtrace.join("\n")
58
+ return str
59
+ end
60
+
49
61
  # File operate
50
62
  # Check the folder and create it when it is not exist.
51
63
  def mkdir_more(file_path)
@@ -72,8 +84,8 @@ class ExtLogger
72
84
  # String
73
85
  # Empty judgement for object
74
86
  def is_blank?(obj)
75
- func_name = "[#{get_instance_name}.is_blank?]"
76
- output_debug "#{func_name} obj.class: #{obj.class}"
87
+ func_name = "[common.#{__method__.to_s}]"
88
+ # output_debug "#{func_name} obj.class: #{obj.class}"
77
89
  return true if obj.nil?
78
90
  return (obj.is_a?(String) || obj.is_a?(Array) || obj.is_a?(Hash)) && obj.empty?
79
91
  end
@@ -131,18 +131,6 @@ class ExtLogger
131
131
  end
132
132
  end
133
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
-
146
134
  # Output the memory usage
147
135
  # Example: record_memory()
148
136
  # Example: record_memory('end')
@@ -191,26 +179,26 @@ class ExtLogger
191
179
  end
192
180
  end
193
181
 
194
- # private
182
+ private
195
183
  # Private function for initialize
196
184
  def init(path, opt={})
197
- func_name = "[#{get_class_name}:private init]"
185
+ func_name = "[#{get_class_name}:private #{__method__}]"
198
186
  set_debug(true) if opt[:debug]
199
187
 
200
188
  output_debug "#{func_name} path: #{path}, opt: #{opt}"
201
- puts "#{func_name} path: #{path}, opt: #{opt}"
202
189
  _path = path
203
- if path.is_a?(String)
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 + '/')
212
- set_path(_path) # Save original log path
213
- end
190
+ set_path(_path)
191
+ # if path.is_a?(String)
192
+ # if path.include?(rails_root)
193
+ # _path = path.gsub(rails_root, '')
194
+ # _path = '/log/' + _path if !_path.include?('log/')
195
+ # _path = _path.gsub('//', '/')
196
+ # else
197
+ # _path = path
198
+ # end
199
+ # _path = _path.gsub('./', ::Dir.pwd + '/')
200
+ # set_path(_path) # Save original log path
201
+ # end
214
202
 
215
203
  # Check the folder and create it.
216
204
  mkdir_more(_path)
@@ -219,12 +207,11 @@ class ExtLogger
219
207
  if !is_blank?(opt[:split_format])
220
208
  set_split_format(opt[:split_format])
221
209
  end
222
- output_debug "#{func_name} split_format: #{get_split_format}"
223
210
 
224
211
  if !is_blank?(opt[:log_max_num])
225
212
  set_log_max_num(opt[:log_max_num])
226
213
  end
227
- output_debug "#{func_name} log_max_num: #{get_log_max_num}"
214
+ output_debug "#{func_name} split_format: #{get_split_format}, log_max_num: #{get_log_max_num}"
228
215
 
229
216
  # Delete redundant old log file
230
217
  delete_redundant_file
@@ -1,3 +1,3 @@
1
1
  module ExtLogger
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5"
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.4
4
+ version: 0.2.5
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-21 00:00:00.000000000 Z
11
+ date: 2019-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler