woolen_common 0.0.13 → 0.0.14
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 +4 -4
- data/lib/woolen_common/logger.rb +381 -364
- data/lib/woolen_common/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb4291b40661c8a8196d7d9e95cdbb827b47e066
|
4
|
+
data.tar.gz: 1da17a64b0702845f81a0dea0a9908007a989c19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bcf2004f65457f047ef94f3a5a73f2d8377aeeb617438856afeb7d9bfce7846d22b0c3bd279d6fea4236342dfc5d9795a69f692b54a810475442ff1dd27dd5f9
|
7
|
+
data.tar.gz: 8befdddc13c6dccdcace8b0a092dd6739796049873ef918ff6f3f6f49676daf0907ae0d3389db4cf33ad787efa0f981122b90d2c6a3f1eb799b0e38064c8cda1
|
data/lib/woolen_common/logger.rb
CHANGED
@@ -6,422 +6,439 @@ require 'pathname'
|
|
6
6
|
require "#{File.join(File.dirname(__FILE__), 'system_helper')}"
|
7
7
|
require "#{File.join(File.dirname(__FILE__), 'config_manager')}"
|
8
8
|
module WoolenCommon
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
9
|
+
class MyLogger # :nodoc: all
|
10
|
+
include SystemHelper
|
11
|
+
LEVELS = ['TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL']
|
12
|
+
COLORS = { 'TRACE' => 'white', 'DEBUG' => 'silver', 'INFO' => 'green', 'WARN' => 'yellow', 'ERROR' => 'purple', 'FATAL' => 'red' }
|
13
|
+
FOREGROUND_BLUE = 1
|
14
|
+
FOREGROUND_GREEN = 2
|
15
|
+
FOREGROUND_RED = 4
|
16
|
+
FOREGROUND_INTENSITY = 8
|
17
|
+
BACKGROUND_BLUE = 16
|
18
|
+
BACKGROUND_GREEN = 32
|
19
|
+
BACKGROUND_RED = 64
|
20
|
+
BACKGROUND_INTENSITY = 128
|
21
|
+
WIN32COLORS = [
|
22
|
+
"default", "black", "navy", "green",
|
23
|
+
"teal", "maroon", "purple", "olive",
|
24
|
+
"silver", "gray", "blue", "lime",
|
25
|
+
"aqua", "red", "fuchsia", "yellow",
|
26
|
+
"white"
|
27
|
+
]
|
28
|
+
WIN32_FOREGROUND_COLOR_MOD = [
|
29
|
+
-1, 0,
|
30
|
+
FOREGROUND_BLUE, FOREGROUND_GREEN, FOREGROUND_BLUE | FOREGROUND_GREEN,
|
31
|
+
FOREGROUND_RED, FOREGROUND_BLUE | FOREGROUND_RED, FOREGROUND_RED | FOREGROUND_GREEN,
|
32
|
+
FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED
|
33
|
+
]
|
34
|
+
WIN32_BACKGROUND_COLOR_MOD = [
|
35
|
+
-1, 0,
|
36
|
+
BACKGROUND_BLUE, BACKGROUND_GREEN, BACKGROUND_BLUE | BACKGROUND_GREEN,
|
37
|
+
BACKGROUND_RED, BACKGROUND_BLUE | BACKGROUND_RED, BACKGROUND_RED | BACKGROUND_GREEN,
|
38
|
+
BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED
|
39
|
+
]
|
40
|
+
CONSOLE_LOCK = Mutex.new
|
41
|
+
# WIN_PRINTER = Pathname.new(File.join(__FILE__, '..', '..', '..', 'bin', 'puts_color.exe')).realpath.to_s
|
42
|
+
attr_reader :file, :stdout, :name
|
43
|
+
attr_accessor :level, :log_cache, :cache_msg, :cache_count
|
44
|
+
|
45
|
+
LOGGERS = []
|
46
|
+
|
47
|
+
def linux_puts_color(message, color = nil)
|
48
|
+
case color
|
49
|
+
when 'red'
|
50
|
+
color = '31;1'
|
51
|
+
when 'green'
|
52
|
+
color = '32;1'
|
53
|
+
when 'yellow'
|
54
|
+
color = '33;1'
|
55
|
+
when 'blue'
|
56
|
+
color = '34;1'
|
57
|
+
when 'purple'
|
58
|
+
color = '35;1'
|
59
|
+
when 'silver'
|
60
|
+
color = '36;1'
|
61
|
+
when 'white'
|
62
|
+
color = '37;1'
|
63
|
+
else
|
64
|
+
color = ''
|
65
|
+
end
|
66
|
+
if color == ''
|
67
|
+
print "#{message}\n"
|
68
|
+
else
|
69
|
+
print "\e[#{color}m#{message}\e[0m\n"
|
70
|
+
end
|
71
|
+
end
|
71
72
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
73
|
+
def win32_puts_color(message, color)
|
74
|
+
require "#{File.join(File.dirname(__FILE__), 'ffi', 'win32_kernel32')}"
|
75
|
+
the_out_handle = Win32Kernel32.getStdHandle Win32Kernel32::STD_OUTPUT_HANDLE
|
76
|
+
if WIN32COLORS.include? color
|
77
|
+
if WIN32COLORS.index(color) >= WIN32_FOREGROUND_COLOR_MOD.length
|
78
|
+
the_color_mod = WIN32_FOREGROUND_COLOR_MOD[WIN32COLORS.index(color) % WIN32_FOREGROUND_COLOR_MOD.length] | FOREGROUND_INTENSITY
|
79
|
+
else
|
80
|
+
the_color_mod = WIN32_FOREGROUND_COLOR_MOD[WIN32COLORS.index(color)]
|
81
|
+
end
|
82
|
+
CONSOLE_LOCK.synchronize do
|
83
|
+
Win32Kernel32.setConsoleTextAttribute the_out_handle, 0x00ff & the_color_mod
|
84
|
+
print "#{message}\n"
|
85
|
+
Win32Kernel32.setConsoleTextAttribute the_out_handle, 0x00ff & (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED)
|
86
|
+
end
|
87
|
+
else
|
88
|
+
print "#{message}\n"
|
89
|
+
end
|
90
|
+
end
|
88
91
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
92
|
+
def my_puts(message, color = nil)
|
93
|
+
if windows?
|
94
|
+
win32_puts_color message, color
|
95
|
+
else
|
96
|
+
linux_puts_color message, color
|
97
|
+
end
|
98
|
+
end
|
96
99
|
|
97
100
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
101
|
+
def initialize(attrs = {})
|
102
|
+
#puts "=> init logger with: #{attrs.inspect}"
|
103
|
+
@stdout = (attrs[:stdout] == 1)
|
104
|
+
@name = attrs[:name]
|
105
|
+
@filename = attrs[:file].gsub(/\.log/, ".#{Process.pid}.log")
|
106
|
+
FileUtils.mkdir_p(File.dirname(@filename))
|
107
|
+
@roll_type = attrs[:roll_type]
|
108
|
+
@roll_param = attrs[:roll_param]
|
109
|
+
@log_cache = attrs[:log_cache].blank? ? 1 : attrs[:log_cache].to_i
|
110
|
+
@max_log_cnt = attrs[:max_log_cnt].blank? ? 10 : attrs[:max_log_cnt].to_i
|
111
|
+
@cache_msg = {}
|
112
|
+
LEVELS.each do |one_lev|
|
113
|
+
@cache_msg[one_lev] = Queue.new
|
114
|
+
end
|
115
|
+
@cache_msg_lock = Mutex.new
|
116
|
+
@cache_count = 0
|
117
|
+
@caller = attrs[:caller] || 1
|
118
|
+
if @roll_type == "file_size" && @roll_param && (@roll_param = @roll_param.to_s)
|
119
|
+
size = nil
|
120
|
+
if @roll_param.index("K")
|
121
|
+
size = @roll_param.to_i * 1024
|
122
|
+
elsif @roll_param.index("M")
|
123
|
+
size = @roll_param.to_i * 1024 * 1024
|
124
|
+
end
|
125
|
+
@roll_param = size
|
126
|
+
end
|
127
|
+
@level = LEVELS.index(attrs[:level].upcase) || 1
|
128
|
+
@last_log_time = nil
|
129
|
+
clean_log @filename
|
130
|
+
@file = File.open(@filename, "a+")
|
131
|
+
@log_file_lock = Mutex.new
|
132
|
+
# clean_log
|
133
|
+
end
|
126
134
|
|
127
135
|
|
128
|
-
|
129
|
-
|
130
|
-
|
136
|
+
def self.loggers
|
137
|
+
return LOGGERS
|
138
|
+
end
|
131
139
|
|
132
|
-
|
133
|
-
|
134
|
-
|
140
|
+
def self.add_log(logger)
|
141
|
+
LOGGERS << logger
|
142
|
+
end
|
135
143
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
end
|
141
|
-
end
|
144
|
+
def self.get(name)
|
145
|
+
LOGGERS.each do |__log__|
|
146
|
+
if __log__.name == name
|
147
|
+
return __log__
|
142
148
|
end
|
149
|
+
end
|
150
|
+
end
|
143
151
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
152
|
+
attr_writer :caller
|
153
|
+
|
154
|
+
def rename_and_create_new(newfilename)
|
155
|
+
# fix Error::EACCESS exception throw when file is opened before rename by lyf
|
156
|
+
begin
|
157
|
+
@log_file_lock.synchronize do
|
158
|
+
@file.flush rescue nil
|
159
|
+
@file.close rescue nil
|
160
|
+
FileUtils.cp(@file.path, newfilename)
|
161
|
+
clean_log @file.path rescue nil
|
162
|
+
@file.reopen(@file.path, "w")
|
163
|
+
end
|
164
|
+
rescue Exception => e
|
165
|
+
puts "error when try to rename_and_create_new #{newfilename},#{e.message}"
|
166
|
+
end
|
167
|
+
#unless (FileUtils.cp(@file.path, newfilename) and FileUtils.rm_f(@file.path) and @file.reopen(@file.path, "w"))
|
168
|
+
# #puts "==> error rename #{@filename} => #{newfilename}"
|
169
|
+
#end
|
170
|
+
end
|
161
171
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
172
|
+
def clean_log(the_path)
|
173
|
+
log_patten = File.join(File.dirname(the_path), '*.log')
|
174
|
+
# puts "need clean #{the_path}"
|
175
|
+
FileUtils.rm_f(the_path)
|
176
|
+
sort_time_files = Dir[log_patten].sort_by {|file|
|
177
|
+
test(?M, file) if File.exists?(file)
|
178
|
+
}
|
179
|
+
# puts "sort_time_files #{sort_time_files}"
|
180
|
+
if @max_log_cnt && @max_log_cnt > 0 && sort_time_files.length > @max_log_cnt
|
181
|
+
(sort_time_files.length - @max_log_cnt).times do |cnt|
|
182
|
+
puts "need to del #{sort_time_files[cnt]} cnt #{cnt}"
|
183
|
+
FileUtils.rm_f sort_time_files[cnt] if File.exists?(sort_time_files[cnt])
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
177
187
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
end
|
200
|
-
rename_and_create_new(new_name)
|
201
|
-
end
|
202
|
-
end
|
203
|
-
rescue Exception => e
|
204
|
-
puts "\n============= log error msg:#{e.message}!!! =============\n"
|
188
|
+
def check_split_file(force = false)
|
189
|
+
begin
|
190
|
+
if @roll_type == 'daily'
|
191
|
+
if force or (@last_log_time && @last_log_time.day != Time.now.day)
|
192
|
+
p = @file.path
|
193
|
+
new_name = nil
|
194
|
+
if p.rindex(".") > p.rindex("/")
|
195
|
+
new_name = "#{p[0, p.rindex(".")]}.#{@last_log_time.strftime("%Y-%m-%d")}#{p[p.rindex("."), p.length]}"
|
196
|
+
else
|
197
|
+
new_name = "#{p}.#{@last_log_time.strftime("%Y-%m-%d")}"
|
198
|
+
end
|
199
|
+
rename_and_create_new(new_name)
|
200
|
+
end
|
201
|
+
elsif @roll_type == 'file_size'
|
202
|
+
if force or (File.size(@file) >= @roll_param)
|
203
|
+
p = @file.path
|
204
|
+
new_name = nil
|
205
|
+
if p.rindex(".") > p.rindex("/")
|
206
|
+
new_name = "#{p[0, p.rindex(".")]}.#{Time.now.strftime("%Y%m%d%H%M")}#{p[p.rindex("."), p.length]}"
|
207
|
+
else
|
208
|
+
new_name = "#{p}.#{Time.now.strftime("%Y%m%d%H%M")}"
|
205
209
|
end
|
210
|
+
rename_and_create_new(new_name)
|
211
|
+
end
|
206
212
|
end
|
213
|
+
rescue Exception => e
|
214
|
+
puts "\n============= log error msg:#{e.message}!!! =============\n"
|
215
|
+
end
|
216
|
+
end
|
207
217
|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
218
|
+
def truncate
|
219
|
+
@file.truncate(0)
|
220
|
+
@file.flush
|
221
|
+
end
|
212
222
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
if @file
|
249
|
-
@file.print file_need_to_pus_cache
|
250
|
-
@file.flush
|
251
|
-
end
|
252
|
-
rescue Exception => es
|
253
|
-
check_split_file true
|
254
|
-
end
|
223
|
+
def log(_level, msg, err = nil)
|
224
|
+
begin
|
225
|
+
check_split_file if @file and not @file.closed?
|
226
|
+
err_msg = nil
|
227
|
+
line = ''
|
228
|
+
if caller[@caller].respond_to? :include?
|
229
|
+
#my_puts "proj root ::#{ConfigManager.project_root}"
|
230
|
+
line = find_the_project_caller_line(@caller)
|
231
|
+
else
|
232
|
+
line = caller[1].gsub(ConfigManager.project_root, '')
|
233
|
+
end
|
234
|
+
_msg = "#{_level},Thread::#{Thread.current},#{Time.now.strftime("%y-%m-%d %H:%M:%S")}\n#{line}: #{msg}"
|
235
|
+
_msg += "\n" if msg[-1] != "\n"
|
236
|
+
if $stdouttype == "GBK"
|
237
|
+
_msg = _msg.to_gbk
|
238
|
+
end
|
239
|
+
err_msg = "#{err.message}\n#{err.backtrace.join("\n\t")}" if err
|
240
|
+
the_key = _level.strip
|
241
|
+
@cache_msg[the_key] << _msg
|
242
|
+
@cache_msg[the_key] << err_msg if err_msg
|
243
|
+
if @cache_count < @log_cache.to_i
|
244
|
+
@cache_count += 1
|
245
|
+
else
|
246
|
+
file_need_to_pus_cache = ''
|
247
|
+
@cache_count = 0
|
248
|
+
@cache_msg_lock.synchronize do
|
249
|
+
@cache_msg.each do |key, value|
|
250
|
+
value.length.times do
|
251
|
+
begin
|
252
|
+
the_msg_data = value.pop(true)
|
253
|
+
my_puts the_msg_data, COLORS[key] if @stdout
|
254
|
+
#puts "need to log with #{@file} [#{value}]"
|
255
|
+
file_need_to_pus_cache << the_msg_data
|
256
|
+
rescue Exception
|
257
|
+
break
|
255
258
|
end
|
256
|
-
|
257
|
-
rescue Exception => e
|
258
|
-
puts "\n==========log error !!! err msg is [#{e.message}][stack::#{e.backtrace.join("\n")}] you need to log is \n#{_msg}\n"
|
259
|
+
end
|
259
260
|
end
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
#my_puts "caller::#{the_caller}====#{caller[the_caller]}"
|
268
|
-
if caller[the_caller].include? ConfigManager.project_root and not caller[the_caller].include? __FILE__
|
269
|
-
#my_puts "===get the caller ::#{the_caller} #{caller[the_caller]} "
|
270
|
-
line = caller[the_caller].gsub(ConfigManager.project_root, '')
|
271
|
-
break
|
272
|
-
end
|
273
|
-
the_caller += 1
|
274
|
-
else
|
275
|
-
line = caller[3].gsub(ConfigManager.project_root, '')
|
276
|
-
break
|
277
|
-
end
|
261
|
+
end
|
262
|
+
begin
|
263
|
+
if @file
|
264
|
+
@log_file_lock.synchronize do
|
265
|
+
@file.print file_need_to_pus_cache
|
266
|
+
@file.flush
|
267
|
+
end
|
278
268
|
end
|
279
|
-
|
280
|
-
|
269
|
+
rescue Exception => es
|
270
|
+
check_split_file true
|
271
|
+
end
|
272
|
+
end
|
273
|
+
@last_log_time = Time.now
|
274
|
+
rescue Exception => e
|
275
|
+
puts "\n==========log error !!! err msg is [#{e.message}][stack::#{e.backtrace.join("\n")}] you need to log is \n#{_msg}\n"
|
276
|
+
end
|
277
|
+
end
|
281
278
|
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
279
|
+
def find_the_project_caller_line(the_caller)
|
280
|
+
line = ''
|
281
|
+
the_caller += 1
|
282
|
+
loop do
|
283
|
+
if caller[the_caller].respond_to? :include?
|
284
|
+
#my_puts "caller::#{the_caller}====#{caller[the_caller]}"
|
285
|
+
if caller[the_caller].include? ConfigManager.project_root and not caller[the_caller].include? __FILE__
|
286
|
+
#my_puts "===get the caller ::#{the_caller} #{caller[the_caller]} "
|
287
|
+
line = caller[the_caller].gsub(ConfigManager.project_root, '')
|
288
|
+
break
|
289
|
+
end
|
290
|
+
the_caller += 1
|
291
|
+
else
|
292
|
+
line = caller[3].gsub(ConfigManager.project_root, '')
|
293
|
+
break
|
294
|
+
end
|
295
|
+
end
|
296
|
+
line
|
297
|
+
end
|
286
298
|
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
299
|
+
def soft(*msg)
|
300
|
+
log('SOFT ', msg.join(','), nil) if true
|
301
|
+
nil
|
302
|
+
end
|
291
303
|
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
304
|
+
def trace(msg, err = nil)
|
305
|
+
log('TRACE ', msg, err) if @level == 0
|
306
|
+
nil
|
307
|
+
end
|
296
308
|
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
309
|
+
def debug(msg, err = nil)
|
310
|
+
log('DEBUG ', msg, err) if @level <= 1
|
311
|
+
nil
|
312
|
+
end
|
301
313
|
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
314
|
+
def info(msg, err = nil)
|
315
|
+
log('INFO ', msg, err) if @level <= 2
|
316
|
+
nil
|
317
|
+
end
|
306
318
|
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
319
|
+
def warn(msg, err = nil)
|
320
|
+
log('WARN ', msg, err) if @level <= 3
|
321
|
+
nil
|
322
|
+
end
|
311
323
|
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
324
|
+
def error(msg, err = nil)
|
325
|
+
log('ERROR ', msg, err) if @level <= 4
|
326
|
+
nil
|
327
|
+
end
|
316
328
|
|
317
|
-
|
318
|
-
|
319
|
-
|
329
|
+
def fatal(msg, err = nil)
|
330
|
+
log('FATAL ', msg, err)
|
331
|
+
nil
|
332
|
+
end
|
320
333
|
|
321
|
-
|
322
|
-
|
323
|
-
|
334
|
+
def debug?
|
335
|
+
@level == 1
|
336
|
+
end
|
324
337
|
|
325
|
-
|
326
|
-
|
338
|
+
def info?
|
339
|
+
@level >= 2
|
327
340
|
end
|
328
341
|
|
342
|
+
def add(*)
|
343
|
+
end
|
344
|
+
end
|
329
345
|
|
330
|
-
class SingleLogger
|
331
|
-
class << self
|
332
|
-
attr_accessor :logger_config, :my_logger
|
333
|
-
end
|
334
346
|
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
SingleLogger.logger_config = YAML.load_file(the_cfg_file)
|
340
|
-
end
|
341
|
-
end
|
342
|
-
return SingleLogger.logger_config if SingleLogger.logger_config
|
343
|
-
{}
|
344
|
-
end
|
347
|
+
class SingleLogger
|
348
|
+
class << self
|
349
|
+
attr_accessor :logger_config, :my_logger
|
350
|
+
end
|
345
351
|
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
:roll_param => log_cfg['roll_param'] || '5M',
|
352
|
-
:max_log_cnt => log_cfg['max_log_cnt'] || 10,
|
353
|
-
:level => log_cfg['level'] || 'debug',
|
354
|
-
:log_cache => log_cfg['log_cache'] || 0,
|
355
|
-
:caller => 2 })
|
356
|
-
|
357
|
-
def self.new(*args)
|
358
|
-
SingleLogger.my_logger || super(*args)
|
352
|
+
def self.get_conf
|
353
|
+
the_cfg_file = File.expand_path(File.join(ConfigManager.project_root, 'config', 'logger.yml'))
|
354
|
+
if SingleLogger.logger_config.blank?
|
355
|
+
if File.exist?(the_cfg_file)
|
356
|
+
SingleLogger.logger_config = YAML.load_file(the_cfg_file)
|
359
357
|
end
|
358
|
+
end
|
359
|
+
return SingleLogger.logger_config if SingleLogger.logger_config
|
360
|
+
{}
|
361
|
+
end
|
360
362
|
|
361
|
-
|
362
|
-
|
363
|
-
|
363
|
+
key = get_conf['default'] || 'dev'
|
364
|
+
log_cfg = get_conf[key] || {}
|
365
|
+
SingleLogger.my_logger ||= MyLogger.new({ :stdout => log_cfg['stdout'] || 1, :name => key,
|
366
|
+
:file => File.join(ConfigManager.project_root, log_cfg['file'] || './log/dev.log'),
|
367
|
+
:roll_type => log_cfg['roll_type'] || 'file_size',
|
368
|
+
:roll_param => log_cfg['roll_param'] || '5M',
|
369
|
+
:max_log_cnt => log_cfg['max_log_cnt'] || 10,
|
370
|
+
:level => log_cfg['level'] || 'debug',
|
371
|
+
:log_cache => log_cfg['log_cache'] || 0,
|
372
|
+
:caller => 2 })
|
373
|
+
|
374
|
+
def self.new(*args)
|
375
|
+
SingleLogger.my_logger || super(*args)
|
376
|
+
end
|
364
377
|
|
365
|
-
|
366
|
-
|
367
|
-
|
378
|
+
def self.get_logger
|
379
|
+
SingleLogger.my_logger || self.new()
|
380
|
+
end
|
381
|
+
|
382
|
+
def initialize(*args)
|
383
|
+
SingleLogger.my_logger || super(*args)
|
384
|
+
end
|
368
385
|
|
369
386
|
|
370
|
-
|
371
|
-
|
372
|
-
|
387
|
+
def self.method_missing(*arg)
|
388
|
+
SingleLogger.my_logger.send(*arg)
|
389
|
+
end
|
390
|
+
end
|
391
|
+
module ToolLogger
|
392
|
+
def log(*arg)
|
393
|
+
SingleLogger.get_logger.log(*arg)
|
373
394
|
end
|
374
|
-
module ToolLogger
|
375
|
-
def log(*arg)
|
376
|
-
SingleLogger.get_logger.log(*arg)
|
377
|
-
end
|
378
395
|
|
379
|
-
|
380
|
-
|
381
|
-
|
396
|
+
def trace(*arg)
|
397
|
+
SingleLogger.get_logger.trace(*arg)
|
398
|
+
end
|
382
399
|
|
383
|
-
|
384
|
-
|
385
|
-
|
400
|
+
def debug(*arg)
|
401
|
+
SingleLogger.get_logger.debug(*arg)
|
402
|
+
end
|
386
403
|
|
387
|
-
|
388
|
-
|
389
|
-
|
404
|
+
def info(*arg)
|
405
|
+
SingleLogger.get_logger.info(*arg)
|
406
|
+
end
|
390
407
|
|
391
|
-
|
392
|
-
|
393
|
-
|
408
|
+
def warn(*arg)
|
409
|
+
SingleLogger.get_logger.warn(*arg)
|
410
|
+
end
|
394
411
|
|
395
|
-
|
396
|
-
|
397
|
-
|
412
|
+
def error(*arg)
|
413
|
+
SingleLogger.get_logger.error(*arg)
|
414
|
+
end
|
398
415
|
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
416
|
+
def fatal(*arg)
|
417
|
+
SingleLogger.get_logger.fatal(*arg)
|
418
|
+
raise arg[1]
|
419
|
+
end
|
403
420
|
|
404
|
-
|
405
|
-
|
406
|
-
|
421
|
+
def debug?
|
422
|
+
SingleLogger.get_logger.debug?
|
423
|
+
end
|
407
424
|
|
408
|
-
|
409
|
-
|
410
|
-
|
425
|
+
def info?
|
426
|
+
SingleLogger.get_logger.info?
|
427
|
+
end
|
411
428
|
|
412
|
-
|
429
|
+
module_function :log, :trace, :debug, :info, :warn, :error, :fatal, :debug?, :info?
|
413
430
|
|
414
|
-
|
415
|
-
|
416
|
-
|
431
|
+
def self.included(base)
|
432
|
+
base.extend self
|
433
|
+
end
|
417
434
|
|
418
|
-
|
419
|
-
|
420
|
-
|
435
|
+
#def method_missing(*arg)
|
436
|
+
# SingleLogger.get_logger.send(*arg)
|
437
|
+
#end
|
421
438
|
|
422
|
-
|
423
|
-
|
424
|
-
end
|
439
|
+
def self.method_missing(*arg)
|
440
|
+
SingleLogger.get_logger.send(*arg)
|
425
441
|
end
|
442
|
+
end
|
426
443
|
end
|
427
444
|
#TestTool::ToolLogger.error("123")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: woolen_common
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- just_woolen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -180,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
180
180
|
version: '0'
|
181
181
|
requirements: []
|
182
182
|
rubyforge_project:
|
183
|
-
rubygems_version: 2.
|
183
|
+
rubygems_version: 2.5.1
|
184
184
|
signing_key:
|
185
185
|
specification_version: 4
|
186
186
|
summary: woolen_common
|