rUtilAnts 0.3.0.20110825 → 1.0.0.20120223
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +7 -1
- data/ChangeLog +16 -0
- data/LICENSE +1 -1
- data/README +2 -5
- data/ReleaseInfo +8 -8
- data/lib/rUtilAnts/Archive.rb +26 -26
- data/lib/rUtilAnts/ForeignProcess.rb +20 -21
- data/lib/rUtilAnts/GUI.rb +38 -38
- data/lib/rUtilAnts/GUI/BugReportDialog.rb +5 -5
- data/lib/rUtilAnts/Logging.rb +124 -254
- data/lib/rUtilAnts/Misc.rb +70 -37
- data/lib/rUtilAnts/MySQLPool.rb +31 -31
- data/lib/rUtilAnts/Platform.rb +33 -16
- data/lib/rUtilAnts/Platforms/i386-cygwin/PlatformInfo.rb +46 -15
- data/lib/rUtilAnts/Platforms/i386-linux/PlatformInfo.rb +46 -15
- data/lib/rUtilAnts/Platforms/i386-mingw32/PlatformInfo.rb +58 -17
- data/lib/rUtilAnts/Platforms/i386-mswin32/PlatformInfo.rb +58 -17
- data/lib/rUtilAnts/Platforms/x86_64-linux/PlatformInfo.rb +46 -15
- data/lib/rUtilAnts/Plugins.rb +54 -139
- data/lib/rUtilAnts/SingletonProxy.rb +33 -0
- data/lib/rUtilAnts/URLAccess.rb +44 -66
- data/lib/rUtilAnts/URLCache.rb +39 -56
- data/lib/rUtilAnts/URLHandlers/DataImage.rb +20 -20
- data/lib/rUtilAnts/URLHandlers/FTP.rb +24 -24
- data/lib/rUtilAnts/URLHandlers/HTTP.rb +21 -21
- data/lib/rUtilAnts/URLHandlers/LocalFile.rb +19 -19
- metadata +10 -10
@@ -1,5 +1,5 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2009 -
|
2
|
+
# Copyright (c) 2009 - 2012 Muriel Salvan (muriel@x-aeon.com)
|
3
3
|
# Licensed under the terms specified in LICENSE file. No warranty is provided.
|
4
4
|
#++
|
5
5
|
|
@@ -12,10 +12,10 @@ module RUtilAnts
|
|
12
12
|
|
13
13
|
# Constructor
|
14
14
|
#
|
15
|
-
# Parameters
|
15
|
+
# Parameters::
|
16
16
|
# * *iParent* (<em>Wx::Window</em>): The parent
|
17
17
|
# * *iMsg* (_String_): The bug message
|
18
|
-
# * *iBugTrackerURL* (_String_): The Bug tracker URL
|
18
|
+
# * *iBugTrackerURL* (_String_): The Bug tracker URL (can be nil)
|
19
19
|
def initialize(iParent, iMsg, iBugTrackerURL)
|
20
20
|
super(iParent,
|
21
21
|
:title => 'Bug',
|
@@ -46,7 +46,7 @@ Thanks.",
|
|
46
46
|
lBSend = Wx::Button.new(self, Wx::ID_ANY, 'Send Bug report')
|
47
47
|
lHCTrackerURL = Wx::HyperlinkCtrl.new(self, Wx::ID_ANY, 'Bug tracker', iBugTrackerURL,
|
48
48
|
:style => Wx::NO_BORDER|Wx::HL_ALIGN_CENTRE|Wx::HL_CONTEXTMENU
|
49
|
-
)
|
49
|
+
) if (iBugTrackerURL != nil)
|
50
50
|
|
51
51
|
# Put everything in sizers
|
52
52
|
lMainSizer = Wx::BoxSizer.new(Wx::VERTICAL)
|
@@ -65,7 +65,7 @@ Thanks.",
|
|
65
65
|
lTopSizer.add_item(lTopRightSizer, :flag => Wx::GROW, :proportion => 1)
|
66
66
|
|
67
67
|
lBottomSizer = Wx::BoxSizer.new(Wx::HORIZONTAL)
|
68
|
-
lBottomSizer.add_item(lHCTrackerURL, :flag => Wx::ALIGN_CENTRE, :proportion => 0)
|
68
|
+
lBottomSizer.add_item(lHCTrackerURL, :flag => Wx::ALIGN_CENTRE, :proportion => 0) if (iBugTrackerURL != nil)
|
69
69
|
lBottomSizer.add_item([8,0], :proportion => 1)
|
70
70
|
lBottomSizer.add_item(lBSend, :flag => Wx::ALIGN_CENTRE, :proportion => 0)
|
71
71
|
lBottomSizer.add_item(lBClose, :flag => Wx::ALIGN_CENTRE, :proportion => 0)
|
data/lib/rUtilAnts/Logging.rb
CHANGED
@@ -1,36 +1,43 @@
|
|
1
1
|
#--
|
2
|
-
# Copyright (c) 2009 -
|
2
|
+
# Copyright (c) 2009 - 2012 Muriel Salvan (muriel@x-aeon.com)
|
3
3
|
# Licensed under the terms specified in LICENSE file. No warranty is provided.
|
4
4
|
#++
|
5
5
|
|
6
|
-
# This file declares modules that might be shared across several projects.
|
7
|
-
|
8
6
|
module RUtilAnts
|
9
7
|
|
10
8
|
module Logging
|
11
9
|
|
12
|
-
#
|
13
|
-
|
10
|
+
# Constants used for GUI dialogs selection
|
11
|
+
GUI_WX = 0
|
14
12
|
|
15
|
-
|
16
|
-
|
13
|
+
# The logger interface, can be used to decorate any class willing to have de
|
14
|
+
module LoggerInterface
|
17
15
|
|
18
|
-
#
|
16
|
+
# Initializer of the logger variables
|
19
17
|
#
|
20
|
-
# Parameters
|
21
|
-
# * *
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
@
|
18
|
+
# Parameters::
|
19
|
+
# * *iOptions* (<em>map<Symbol,Object></em>): Options [optional = {}]
|
20
|
+
# * *:lib_root_dir* (_String_): The library root directory that will not appear in the logged stack messages [optional = nil]
|
21
|
+
# * *:bug_tracker_url* (_String_): The application's bug tracker URL, used to report bugs [optional = nil]
|
22
|
+
# * *:mute_stdout* (_Boolean_): Do we silent normal output (nothing sent to $stdout) ? [optional = false]
|
23
|
+
# * *:mute_stderr* (_Boolean_): Do we silent error output (nothing sent to $stderr) ? [optional = false]
|
24
|
+
# * *:no_dialogs* (_Boolean_): Do we forbid dialogs usage ? [optional = false]
|
25
|
+
# * *:debug_mode* (_Boolean_): Do we activate debug mode ? [optional = false]
|
26
|
+
# * *:log_file* (_String_): Specify a log file [optional = nil]
|
27
|
+
# * *:errors_stack* (<em>list<String></em>): Specify an errors stack [optional = nil]
|
28
|
+
# * *:messages_stack* (<em>list<String></em>): Specify a messages stack [optional = nil]
|
29
|
+
# * *:gui_for_dialogs* (_Integer_): Specify a GUI constant for dialogs [optional = nil]
|
30
|
+
def init_logger(iOptions = {})
|
31
|
+
@LibRootDir = iOptions[:lib_root_dir]
|
32
|
+
@BugTrackerURL = iOptions[:bug_tracker_url]
|
33
|
+
@DebugMode = (iOptions[:debug_mode] == nil) ? false : iOptions[:debug_mode]
|
34
|
+
@LogFile = iOptions[:log_file]
|
35
|
+
@ErrorsStack = iOptions[:errors_stack]
|
36
|
+
@MessagesStack = iOptions[:messages_stack]
|
37
|
+
@DialogsGUI = iOptions[:gui_for_dialogs]
|
38
|
+
@ScreenOutput = (iOptions[:mute_stdout] == nil) ? true : (!iOptions[:mute_stdout])
|
39
|
+
@ScreenOutputErr = (iOptions[:mute_stderr] == nil) ? true : (!iOptions[:mute_stderr])
|
40
|
+
@NoDialogs = (iOptions[:no_dialogs] == nil) ? false : iOptions[:no_dialogs]
|
34
41
|
if (!@ScreenOutput)
|
35
42
|
# Test if we can write to stdout
|
36
43
|
begin
|
@@ -67,80 +74,80 @@ module RUtilAnts
|
|
67
74
|
|
68
75
|
# Mute or unmute standard output
|
69
76
|
#
|
70
|
-
# Parameters
|
77
|
+
# Parameters::
|
71
78
|
# * *iMute* (_Boolean_): Do we mute standard output ? [optional = true]
|
72
|
-
def
|
79
|
+
def mute_stdout(iMute = true)
|
73
80
|
@ScreenOutput = (!iMute)
|
74
81
|
end
|
75
82
|
|
76
83
|
# Mute or unmute error output
|
77
84
|
#
|
78
|
-
# Parameters
|
85
|
+
# Parameters::
|
79
86
|
# * *iMute* (_Boolean_): Do we mute error output ? [optional = true]
|
80
|
-
def
|
87
|
+
def mute_stderr(iMute = true)
|
81
88
|
@ScreenOutputErr = (!iMute)
|
82
89
|
end
|
83
90
|
|
84
91
|
# Set the log file to use (can be nil to stop logging into a file)
|
85
92
|
#
|
86
|
-
# Parameters
|
93
|
+
# Parameters::
|
87
94
|
# * *iFileName* (_String_): Log file name (can be nil)
|
88
|
-
def
|
95
|
+
def set_log_file(iFileName)
|
89
96
|
@LogFile = iFileName
|
90
97
|
end
|
91
98
|
|
92
99
|
# Get the log file used (can be nil)
|
93
100
|
#
|
94
|
-
# Return
|
101
|
+
# Return::
|
95
102
|
# * _String_: Log file name (can be nil)
|
96
|
-
def
|
103
|
+
def get_log_file
|
97
104
|
return @LogFile
|
98
105
|
end
|
99
106
|
|
100
107
|
# Get the library root dir
|
101
108
|
#
|
102
|
-
# Return
|
109
|
+
# Return::
|
103
110
|
# * _String_: The library root dir, as defined when initialized
|
104
|
-
def
|
111
|
+
def get_lib_root_dir
|
105
112
|
return @LibRootDir
|
106
113
|
end
|
107
114
|
|
108
115
|
# Get the bug tracker URL
|
109
116
|
#
|
110
|
-
# Return
|
117
|
+
# Return::
|
111
118
|
# * _String_: The bug tracker URL, as defined when initialized
|
112
|
-
def
|
119
|
+
def get_bug_tracker_url
|
113
120
|
return @BugTrackerURL
|
114
121
|
end
|
115
122
|
|
116
123
|
# Indicate which GUI to be used to display dialogs.
|
117
124
|
#
|
118
|
-
# Parameters
|
125
|
+
# Parameters::
|
119
126
|
# * *iGUIToUse* (_Integer_): The GUI constant, or nil if no GUI is provided
|
120
|
-
def
|
127
|
+
def set_gui_for_dialogs(iGUIToUse)
|
121
128
|
@DialogsGUI = iGUIToUse
|
122
129
|
end
|
123
130
|
|
124
131
|
# Set the debug mode
|
125
132
|
#
|
126
|
-
# Parameters
|
133
|
+
# Parameters::
|
127
134
|
# * *iDebugMode* (_Boolean_): Are we in debug mode ?
|
128
|
-
def
|
135
|
+
def activate_log_debug(iDebugMode)
|
129
136
|
if (@DebugMode != iDebugMode)
|
130
137
|
@DebugMode = iDebugMode
|
131
138
|
if (iDebugMode)
|
132
|
-
|
139
|
+
log_info 'Activated log debug'
|
133
140
|
else
|
134
|
-
|
141
|
+
log_info 'Deactivated log debug'
|
135
142
|
end
|
136
143
|
end
|
137
144
|
end
|
138
145
|
|
139
146
|
# Is debug mode activated ?
|
140
147
|
#
|
141
|
-
# Return
|
148
|
+
# Return::
|
142
149
|
# * _Boolean_: Are we in debug mode ?
|
143
|
-
def
|
150
|
+
def debug_activated?
|
144
151
|
return @DebugMode
|
145
152
|
end
|
146
153
|
|
@@ -148,9 +155,9 @@ module RUtilAnts
|
|
148
155
|
# If set to nil, errors will be displayed as they appear.
|
149
156
|
# If set to a stack, errors will silently be added to the list.
|
150
157
|
#
|
151
|
-
# Parameters
|
158
|
+
# Parameters::
|
152
159
|
# * *iErrorsStack* (<em>list<String></em>): The stack of errors, or nil to unset it
|
153
|
-
def
|
160
|
+
def set_log_errors_stack(iErrorsStack)
|
154
161
|
@ErrorsStack = iErrorsStack
|
155
162
|
end
|
156
163
|
|
@@ -158,44 +165,44 @@ module RUtilAnts
|
|
158
165
|
# If set to nil, messages will be displayed as they appear.
|
159
166
|
# If set to a stack, messages will silently be added to the list.
|
160
167
|
#
|
161
|
-
# Parameters
|
168
|
+
# Parameters::
|
162
169
|
# * *iMessagesStack* (<em>list<String></em>): The stack of messages, or nil to unset it
|
163
|
-
def
|
170
|
+
def set_log_messages_stack(iMessagesStack)
|
164
171
|
@MessagesStack = iMessagesStack
|
165
172
|
end
|
166
173
|
|
167
174
|
# Log an exception
|
168
175
|
# This is called when there is a bug due to an exception in the program. It has been set in many places to detect bugs.
|
169
176
|
#
|
170
|
-
# Parameters
|
177
|
+
# Parameters::
|
171
178
|
# * *iException* (_Exception_): Exception
|
172
179
|
# * *iMsg* (_String_): Message to log
|
173
|
-
def
|
174
|
-
|
180
|
+
def log_exc(iException, iMsg)
|
181
|
+
log_bug("#{iMsg}
|
175
182
|
Exception: #{iException}
|
176
183
|
Exception stack:
|
177
|
-
#{
|
184
|
+
#{get_simple_caller(iException.backtrace, caller).join("\n")}
|
178
185
|
...")
|
179
186
|
end
|
180
187
|
|
181
188
|
# Log a bug
|
182
189
|
# This is called when there is a bug in the program. It has been set in many places to detect bugs.
|
183
190
|
#
|
184
|
-
# Parameters
|
191
|
+
# Parameters::
|
185
192
|
# * *iMsg* (_String_): Message to log
|
186
|
-
def
|
193
|
+
def log_bug(iMsg)
|
187
194
|
lCompleteMsg = "Bug: #{iMsg}
|
188
195
|
Stack:
|
189
|
-
#{
|
196
|
+
#{get_simple_caller(caller[0..-2]).join("\n")}"
|
190
197
|
# Log into stderr
|
191
198
|
if (@ScreenOutputErr)
|
192
199
|
$stderr << "!!! BUG !!! #{lCompleteMsg}\n"
|
193
200
|
end
|
194
201
|
if (@LogFile != nil)
|
195
|
-
|
202
|
+
log_file(lCompleteMsg)
|
196
203
|
end
|
197
204
|
# Display Bug dialog
|
198
|
-
if (
|
205
|
+
if (show_modal_wx_available?)
|
199
206
|
# We require the file here, as we hope it will not be required often
|
200
207
|
require 'rUtilAnts/GUI/BugReportDialog'
|
201
208
|
showModal(GUI::BugReportDialog, nil, lCompleteMsg, @BugTrackerURL) do |iModalResult, iDialog|
|
@@ -203,8 +210,9 @@ Stack:
|
|
203
210
|
end
|
204
211
|
else
|
205
212
|
# Use normal platform dependent message, if the platform has been initialized (otherwise, stick to $stderr)
|
206
|
-
if (defined?(
|
207
|
-
|
213
|
+
if ((defined?(sendMsg) != nil) and
|
214
|
+
(!@NoDialogs))
|
215
|
+
sendMsg("A bug has just occurred.
|
208
216
|
Normally you should never see this message, but this application is not bug-less.
|
209
217
|
We are sorry for the inconvenience caused.
|
210
218
|
If you want to help improving this application, please inform us of this bug:
|
@@ -222,20 +230,20 @@ Details:
|
|
222
230
|
# Log an error.
|
223
231
|
# Those errors can be normal, as they mainly depend on external factors (lost connection, invalid user file...)
|
224
232
|
#
|
225
|
-
# Parameters
|
233
|
+
# Parameters::
|
226
234
|
# * *iMsg* (_String_): Message to log
|
227
|
-
def
|
235
|
+
def log_err(iMsg)
|
228
236
|
lMsg = "!!! ERR !!! #{iMsg}"
|
229
237
|
# Log into stderr
|
230
238
|
if (@ScreenOutputErr)
|
231
239
|
$stderr << "#{lMsg}\n"
|
232
240
|
end
|
233
241
|
if (@LogFile != nil)
|
234
|
-
|
242
|
+
log_file(lMsg)
|
235
243
|
end
|
236
244
|
# Display dialog only if we are not redirecting messages to a stack
|
237
245
|
if (@ErrorsStack == nil)
|
238
|
-
if (
|
246
|
+
if (show_modal_wx_available?)
|
239
247
|
showModal(Wx::MessageDialog, nil,
|
240
248
|
iMsg,
|
241
249
|
:caption => 'Error',
|
@@ -243,9 +251,10 @@ Details:
|
|
243
251
|
) do |iModalResult, iDialog|
|
244
252
|
# Nothing to do
|
245
253
|
end
|
246
|
-
elsif (defined?(
|
254
|
+
elsif ((defined?(sendMsg) != nil) and
|
255
|
+
(!@NoDialogs))
|
247
256
|
# Use normal platform dependent message, if the platform has been initialized (otherwise, stick to $stderr)
|
248
|
-
|
257
|
+
sendMsg(iMsg)
|
249
258
|
end
|
250
259
|
else
|
251
260
|
@ErrorsStack << iMsg
|
@@ -255,20 +264,20 @@ Details:
|
|
255
264
|
# Log a normal message to the user
|
256
265
|
# This is used to display a simple message to the user
|
257
266
|
#
|
258
|
-
# Parameters
|
267
|
+
# Parameters::
|
259
268
|
# * *iMsg* (_String_): Message to log
|
260
|
-
def
|
269
|
+
def log_msg(iMsg)
|
261
270
|
# Log into stderr
|
262
271
|
if (@ScreenOutput)
|
263
272
|
$stdout << "#{iMsg}\n"
|
264
273
|
end
|
265
274
|
if (@LogFile != nil)
|
266
|
-
|
275
|
+
log_file(iMsg)
|
267
276
|
end
|
268
277
|
# Display dialog only if we are not redirecting messages to a stack
|
269
278
|
if (@MessagesStack == nil)
|
270
279
|
# Display dialog only if showModal exists and that we are currently running the application
|
271
|
-
if (
|
280
|
+
if (show_modal_wx_available?)
|
272
281
|
showModal(Wx::MessageDialog, nil,
|
273
282
|
iMsg,
|
274
283
|
:caption => 'Notification',
|
@@ -276,9 +285,10 @@ Details:
|
|
276
285
|
) do |iModalResult, iDialog|
|
277
286
|
# Nothing to do
|
278
287
|
end
|
279
|
-
elsif (defined?(
|
288
|
+
elsif ((defined?(sendMsg) != nil) and
|
289
|
+
(!@NoDialogs))
|
280
290
|
# Use normal platform dependent message, if the platform has been initialized (otherwise, stick to $stderr)
|
281
|
-
|
291
|
+
sendMsg(iMsg)
|
282
292
|
end
|
283
293
|
else
|
284
294
|
@MessagesStack << iMsg
|
@@ -288,47 +298,47 @@ Details:
|
|
288
298
|
# Log an info.
|
289
299
|
# This is just common journal.
|
290
300
|
#
|
291
|
-
# Parameters
|
301
|
+
# Parameters::
|
292
302
|
# * *iMsg* (_String_): Message to log
|
293
|
-
def
|
303
|
+
def log_info(iMsg)
|
294
304
|
# Log into stdout
|
295
305
|
if (@ScreenOutput)
|
296
306
|
$stdout << "#{iMsg}\n"
|
297
307
|
end
|
298
308
|
if (@LogFile != nil)
|
299
|
-
|
309
|
+
log_file(iMsg)
|
300
310
|
end
|
301
311
|
end
|
302
312
|
|
303
313
|
# Log a warning.
|
304
314
|
# Warnings are not errors but still should be highlighted.
|
305
315
|
#
|
306
|
-
# Parameters
|
316
|
+
# Parameters::
|
307
317
|
# * *iMsg* (_String_): Message to log
|
308
|
-
def
|
318
|
+
def log_warn(iMsg)
|
309
319
|
# Log into stdout
|
310
320
|
lMsg = "!!! WARNING !!! - #{iMsg}"
|
311
321
|
if (@ScreenOutput)
|
312
322
|
$stdout << "#{lMsg}\n"
|
313
323
|
end
|
314
324
|
if (@LogFile != nil)
|
315
|
-
|
325
|
+
log_file(lMsg)
|
316
326
|
end
|
317
327
|
end
|
318
328
|
|
319
329
|
# Log a debugging info.
|
320
330
|
# This is used when debug is activated
|
321
331
|
#
|
322
|
-
# Parameters
|
332
|
+
# Parameters::
|
323
333
|
# * *iMsg* (_String_): Message to log
|
324
|
-
def
|
334
|
+
def log_debug(iMsg)
|
325
335
|
# Log into stdout
|
326
336
|
if (@DebugMode)
|
327
337
|
if (@ScreenOutput)
|
328
338
|
$stdout << "#{iMsg}\n"
|
329
339
|
end
|
330
340
|
if (@LogFile != nil)
|
331
|
-
|
341
|
+
log_file(iMsg)
|
332
342
|
end
|
333
343
|
end
|
334
344
|
end
|
@@ -337,9 +347,9 @@ Details:
|
|
337
347
|
|
338
348
|
# Check if Wx dialogs environment is set up
|
339
349
|
#
|
340
|
-
# Return
|
350
|
+
# Return::
|
341
351
|
# * _Boolean_: Can we use showModal ?
|
342
|
-
def
|
352
|
+
def show_modal_wx_available?
|
343
353
|
return (
|
344
354
|
(defined?(showModal) != nil) and
|
345
355
|
(@DialogsGUI == GUI_WX)
|
@@ -348,9 +358,9 @@ Details:
|
|
348
358
|
|
349
359
|
# Log a message in the log file
|
350
360
|
#
|
351
|
-
# Parameters
|
361
|
+
# Parameters::
|
352
362
|
# * *iMsg* (_String_): The message to log
|
353
|
-
def
|
363
|
+
def log_file(iMsg)
|
354
364
|
File.open(@LogFile, 'a+') do |oFile|
|
355
365
|
oFile << "#{Time.now.gmtime.strftime('%Y/%m/%d %H:%M:%S')} - #{iMsg}\n"
|
356
366
|
end
|
@@ -359,12 +369,12 @@ Details:
|
|
359
369
|
# Get a stack trace in a simple format:
|
360
370
|
# Remove @LibRootDir paths from it.
|
361
371
|
#
|
362
|
-
# Parameters
|
372
|
+
# Parameters::
|
363
373
|
# * *iCaller* (<em>list<String></em>): The caller, or nil if no caller
|
364
374
|
# * *iReferenceCaller* (<em>list<String></em>): The reference caller: we will not display lines from iCaller that also belong to iReferenceCaller [optional = nil]
|
365
|
-
# Return
|
375
|
+
# Return::
|
366
376
|
# * <em>list<String></em>): The simple stack
|
367
|
-
def
|
377
|
+
def get_simple_caller(iCaller, iReferenceCaller = nil)
|
368
378
|
rSimpleCaller = []
|
369
379
|
|
370
380
|
if (iCaller != nil)
|
@@ -384,13 +394,18 @@ Details:
|
|
384
394
|
# Here we have either one of the indexes that is -1, or the indexes point to different lines between the caller and its reference.
|
385
395
|
lCaller = iCaller[0..lIdxCaller+1]
|
386
396
|
end
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
397
|
+
if (@LibRootDir == nil)
|
398
|
+
rSimpleCaller = lCaller
|
399
|
+
else
|
400
|
+
# Remove @LibRootDir from each entry
|
401
|
+
lCaller.each do |iCallerLine|
|
402
|
+
lMatch = iCallerLine.match(/^(.*):([[:digit:]]*):in (.*)$/)
|
403
|
+
if (lMatch == nil)
|
404
|
+
# Did not get which format. Just add it blindly.
|
405
|
+
rSimpleCaller << iCallerLine
|
406
|
+
else
|
407
|
+
rSimpleCaller << "#{File.expand_path(lMatch[1]).gsub(@LibRootDir, '')}:#{lMatch[2]}:in #{lMatch[3]}"
|
408
|
+
end
|
394
409
|
end
|
395
410
|
end
|
396
411
|
end
|
@@ -400,174 +415,29 @@ Details:
|
|
400
415
|
|
401
416
|
end
|
402
417
|
|
403
|
-
#
|
404
|
-
|
405
|
-
# Initialize the logging features
|
406
|
-
#
|
407
|
-
# Parameters:
|
408
|
-
# * *iLibRootDir* (_String_): The library root directory that will not appear in the logged stack messages
|
409
|
-
# * *iBugTrackerURL* (_String_): The application's bug tracker URL, used to report bugs
|
410
|
-
# * *iSilentOutputs* (_Boolean_): Do we silent outputs (nothing sent to $stdout or $stderr) ? [optional = false]
|
411
|
-
def self.initializeLogging(iLibRootDir, iBugTrackerURL, iSilentOutputs = false)
|
412
|
-
$rUtilAnts_Logging_Logger = RUtilAnts::Logging::Logger.new(iLibRootDir, iBugTrackerURL, iSilentOutputs)
|
413
|
-
# Add the module accessible from the Object namespace
|
414
|
-
Object.module_eval('include RUtilAnts::Logging')
|
415
|
-
end
|
416
|
-
|
417
|
-
# Mute or unmute standard output
|
418
|
-
#
|
419
|
-
# Parameters:
|
420
|
-
# * *iMute* (_Boolean_): Do we mute standard output ? [optional = true]
|
421
|
-
def muteStdOut(iMute = true)
|
422
|
-
$rUtilAnts_Logging_Logger.muteStdOut(iMute)
|
423
|
-
end
|
424
|
-
|
425
|
-
# Mute or unmute error output
|
426
|
-
#
|
427
|
-
# Parameters:
|
428
|
-
# * *iMute* (_Boolean_): Do we mute error output ? [optional = true]
|
429
|
-
def muteStdErr(iMute = true)
|
430
|
-
$rUtilAnts_Logging_Logger.muteStdErr(iMute)
|
431
|
-
end
|
432
|
-
|
433
|
-
# Set the log file to use (can be nil to stop logging into a file)
|
434
|
-
#
|
435
|
-
# Parameters:
|
436
|
-
# * *iFileName* (_String_): Log file name (can be nil)
|
437
|
-
def setLogFile(iFileName)
|
438
|
-
$rUtilAnts_Logging_Logger.setLogFile(iFileName)
|
439
|
-
end
|
440
|
-
|
441
|
-
# Get the log file used (can be nil)
|
442
|
-
#
|
443
|
-
# Return:
|
444
|
-
# * _String_: Log file name (can be nil)
|
445
|
-
def getLogFile
|
446
|
-
return $rUtilAnts_Logging_Logger.getLogFile
|
447
|
-
end
|
448
|
-
|
449
|
-
# Get the library root dir
|
450
|
-
#
|
451
|
-
# Return:
|
452
|
-
# * _String_: The library root dir, as defined when initialized
|
453
|
-
def getLibRootDir
|
454
|
-
return $rUtilAnts_Logging_Logger.getLibRootDir
|
455
|
-
end
|
456
|
-
|
457
|
-
# Get the bug tracker URL
|
458
|
-
#
|
459
|
-
# Return:
|
460
|
-
# * _String_: The bug tracker URL, as defined when initialized
|
461
|
-
def getBugTrackerURL
|
462
|
-
return $rUtilAnts_Logging_Logger.getBugTrackerURL
|
463
|
-
end
|
464
|
-
|
465
|
-
# Indicate which GUI to be used to display dialogs.
|
466
|
-
#
|
467
|
-
# Parameters:
|
468
|
-
# * *iGUIToUse* (_Integer_): The GUI constant, or nil if no GUI is provided
|
469
|
-
def setGUIForDialogs(iGUIToUse)
|
470
|
-
$rUtilAnts_Logging_Logger.setGUIForDialogs(iGUIToUse)
|
471
|
-
end
|
472
|
-
|
473
|
-
# Set the debug mode
|
474
|
-
#
|
475
|
-
# Parameters:
|
476
|
-
# * *iDebugMode* (_Boolean_): Are we in debug mode ?
|
477
|
-
def activateLogDebug(iDebugMode)
|
478
|
-
$rUtilAnts_Logging_Logger.activateLogDebug(iDebugMode)
|
479
|
-
end
|
480
|
-
|
481
|
-
# Is debug mode activated ?
|
482
|
-
#
|
483
|
-
# Return:
|
484
|
-
# * _Boolean_: Are we in debug mode ?
|
485
|
-
def debugActivated?
|
486
|
-
return $rUtilAnts_Logging_Logger.debugActivated?
|
487
|
-
end
|
488
|
-
|
489
|
-
# Set the stack of the errors to fill.
|
490
|
-
# If set to nil, errors will be displayed as they appear.
|
491
|
-
# If set to a stack, errors will silently be added to the list.
|
492
|
-
#
|
493
|
-
# Parameters:
|
494
|
-
# * *iErrorsStack* (<em>list<String></em>): The stack of errors, or nil to unset it
|
495
|
-
def setLogErrorsStack(iErrorsStack)
|
496
|
-
$rUtilAnts_Logging_Logger.setLogErrorsStack(iErrorsStack)
|
497
|
-
end
|
498
|
-
|
499
|
-
# Set the stack of the messages to fill.
|
500
|
-
# If set to nil, messages will be displayed as they appear.
|
501
|
-
# If set to a stack, messages will silently be added to the list.
|
502
|
-
#
|
503
|
-
# Parameters:
|
504
|
-
# * *iMessagesStack* (<em>list<String></em>): The stack of messages, or nil to unset it
|
505
|
-
def setLogMessagesStack(iMessagesStack)
|
506
|
-
$rUtilAnts_Logging_Logger.setLogMessagesStack(iMessagesStack)
|
507
|
-
end
|
508
|
-
|
509
|
-
# Log an exception
|
510
|
-
# This is called when there is a bug due to an exception in the program. It has been set in many places to detect bugs.
|
511
|
-
#
|
512
|
-
# Parameters:
|
513
|
-
# * *iException* (_Exception_): Exception
|
514
|
-
# * *iMsg* (_String_): Message to log
|
515
|
-
def logExc(iException, iMsg)
|
516
|
-
$rUtilAnts_Logging_Logger.logExc(iException, iMsg)
|
517
|
-
end
|
518
|
-
|
519
|
-
# Log a bug
|
520
|
-
# This is called when there is a bug in the program. It has been set in many places to detect bugs.
|
521
|
-
#
|
522
|
-
# Parameters:
|
523
|
-
# * *iMsg* (_String_): Message to log
|
524
|
-
def logBug(iMsg)
|
525
|
-
$rUtilAnts_Logging_Logger.logBug(iMsg)
|
526
|
-
end
|
527
|
-
|
528
|
-
# Log an error.
|
529
|
-
# Those errors can be normal, as they mainly depend on external factors (lost connection, invalid user file...)
|
530
|
-
#
|
531
|
-
# Parameters:
|
532
|
-
# * *iMsg* (_String_): Message to log
|
533
|
-
def logErr(iMsg)
|
534
|
-
$rUtilAnts_Logging_Logger.logErr(iMsg)
|
535
|
-
end
|
418
|
+
# A stand-alone logger
|
419
|
+
class Logger
|
536
420
|
|
537
|
-
|
538
|
-
# This is used to display a simple message to the user
|
539
|
-
#
|
540
|
-
# Parameters:
|
541
|
-
# * *iMsg* (_String_): Message to log
|
542
|
-
def logMsg(iMsg)
|
543
|
-
$rUtilAnts_Logging_Logger.logMsg(iMsg)
|
544
|
-
end
|
421
|
+
include RUtilAnts::Logging::LoggerInterface
|
545
422
|
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
end
|
423
|
+
# Constructor
|
424
|
+
#
|
425
|
+
# Parameters::
|
426
|
+
# * *iOptions* (<em>map<Symbol,Object></em>): Options (see LoggerInterface for details) [optional = {}]
|
427
|
+
def initialize(iOptions = {})
|
428
|
+
init_logger(iOptions)
|
429
|
+
end
|
554
430
|
|
555
|
-
# Log a warning.
|
556
|
-
# Warnings are not errors but still should be highlighted.
|
557
|
-
#
|
558
|
-
# Parameters:
|
559
|
-
# * *iMsg* (_String_): Message to log
|
560
|
-
def logWarn(iMsg)
|
561
|
-
$rUtilAnts_Logging_Logger.logWarn(iMsg)
|
562
431
|
end
|
563
432
|
|
564
|
-
#
|
565
|
-
# This is used when debug is activated
|
433
|
+
# Set Object as a logger.
|
566
434
|
#
|
567
|
-
# Parameters
|
568
|
-
# * *
|
569
|
-
def
|
570
|
-
|
435
|
+
# Parameters::
|
436
|
+
# * *iOptions* (<em>map<Symbol,Object></em>): Options (see RUtilAnts::Logging::Logger::initialize documentation for options) [optional = {}]
|
437
|
+
def self.install_logger_on_object(iOptions = {})
|
438
|
+
require 'rUtilAnts/SingletonProxy'
|
439
|
+
RUtilAnts::make_singleton_proxy(RUtilAnts::Logging::LoggerInterface, Object)
|
440
|
+
init_logger(iOptions)
|
571
441
|
end
|
572
442
|
|
573
443
|
end
|