rbatch 1.6.3 → 1.6.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. data/Rakefile +2 -5
  2. data/doc/rdoc/CHANGELOG.html +182 -0
  3. data/doc/rdoc/LICENSE.html +98 -0
  4. data/doc/rdoc/RBatch/Cmd.html +333 -0
  5. data/doc/rdoc/RBatch/CmdException.html +158 -0
  6. data/doc/rdoc/RBatch/CmdResult.html +496 -0
  7. data/doc/rdoc/RBatch/Config/Exception.html +158 -0
  8. data/doc/rdoc/RBatch/Config.html +355 -0
  9. data/doc/rdoc/RBatch/Log.html +743 -0
  10. data/doc/rdoc/RBatch.html +457 -0
  11. data/doc/rdoc/created.rid +8 -0
  12. data/doc/rdoc/images/brick.png +0 -0
  13. data/doc/rdoc/images/brick_link.png +0 -0
  14. data/doc/rdoc/images/bug.png +0 -0
  15. data/doc/rdoc/images/bullet_black.png +0 -0
  16. data/doc/rdoc/images/bullet_toggle_minus.png +0 -0
  17. data/doc/rdoc/images/bullet_toggle_plus.png +0 -0
  18. data/doc/rdoc/images/date.png +0 -0
  19. data/doc/rdoc/images/find.png +0 -0
  20. data/doc/rdoc/images/loadingAnimation.gif +0 -0
  21. data/doc/rdoc/images/macFFBgHack.png +0 -0
  22. data/doc/rdoc/images/package.png +0 -0
  23. data/doc/rdoc/images/page_green.png +0 -0
  24. data/doc/rdoc/images/page_white_text.png +0 -0
  25. data/doc/rdoc/images/page_white_width.png +0 -0
  26. data/doc/rdoc/images/plugin.png +0 -0
  27. data/doc/rdoc/images/ruby.png +0 -0
  28. data/doc/rdoc/images/tag_green.png +0 -0
  29. data/doc/rdoc/images/wrench.png +0 -0
  30. data/doc/rdoc/images/wrench_orange.png +0 -0
  31. data/doc/rdoc/images/zoom.png +0 -0
  32. data/doc/rdoc/index.html +136 -0
  33. data/doc/rdoc/js/darkfish.js +116 -0
  34. data/doc/rdoc/js/jquery.js +32 -0
  35. data/doc/rdoc/js/quicksearch.js +114 -0
  36. data/doc/rdoc/js/thickbox-compressed.js +10 -0
  37. data/doc/rdoc/lib/rbatch/cmd_rb.html +56 -0
  38. data/doc/rdoc/lib/rbatch/config_rb.html +56 -0
  39. data/doc/rdoc/lib/rbatch/log_rb.html +58 -0
  40. data/doc/rdoc/lib/rbatch_rb.html +58 -0
  41. data/doc/rdoc/rdoc.css +706 -0
  42. data/sample/bin/apache_log_insert.rb +108 -0
  43. data/sample/bin/file_batch_copy.rb +13 -0
  44. data/sample/bin/mysql_data_backup.rb +42 -0
  45. data/sample/bin/openam_log_insert.rb +105 -0
  46. data/sample/bin/openldap_backup.rb +7 -0
  47. data/sample/bin/webagent_log_insert.rb +108 -0
  48. data/sample/conf/apache_log_insert.yaml +8 -0
  49. data/sample/conf/file_batch_copy.yaml +5 -0
  50. data/sample/conf/mysql_data_backup.yaml +5 -0
  51. data/sample/conf/openam_log_insert.yaml +35 -0
  52. data/sample/conf/openldap_backup.yaml +2 -0
  53. data/sample/conf/rbatch.yaml +68 -0
  54. data/sample/conf/test.yaml +5 -0
  55. data/sample/conf/webagent_log_insert.yaml +16 -0
  56. data/sample/data/access_log.1 +50 -0
  57. data/sample/data/access_log.2012-07-10 +50 -0
  58. data/sample/data/amAgent_localhost_80.log.1 +39 -0
  59. data/sample/data/amAgent_localhost_80.log.2012-07-10 +40 -0
  60. data/sample/data/amAuthentication.access.1 +30 -0
  61. data/sample/data/amAuthentication.access.2012-07-10 +30 -0
  62. data/sample/data/amAuthentication.error.1 +10 -0
  63. data/sample/data/amAuthentication.error.2012-07-10 +6 -0
  64. data/sample/log/20130120_apache_log_insert.log +171 -0
  65. data/sample/log/20130120_openam_log_insert.log +143 -0
  66. data/sample/log/20130121_apache_log_insert.log +103 -0
  67. data/sample/log/20130121_file_batch_copy.log +15 -0
  68. data/sample/log/20130121_openam_log_insert.log +39 -0
  69. data/sample/log/20130121_webagent_log_insert.log +432 -0
  70. data/sample/log/empty +0 -0
  71. data/sample/moto/README +16 -0
  72. data/sample/moto/auditlog.src.zip +0 -0
  73. data/sample/moto/build.gradle +106 -0
  74. data/sample/moto/gradle/wrapper/gradle-wrapper.jar +0 -0
  75. data/sample/moto/gradle/wrapper/gradle-wrapper.properties +7 -0
  76. data/sample/moto/gradle.properties +12 -0
  77. data/sample/moto/gradlew +164 -0
  78. data/sample/moto/gradlew.bat +90 -0
  79. data/sample/moto/settings.gradle +1 -0
  80. data/sample/moto/src/main/bin/delete_auditlog.sh +176 -0
  81. data/sample/moto/src/main/bin/delete_workflowinstances.sh +315 -0
  82. data/sample/moto/src/main/bin/import_auth_log.sh +23 -0
  83. data/sample/moto/src/main/etc/delete_auditlog.param +39 -0
  84. data/sample/moto/src/main/etc/delete_workflowinstances.param +30 -0
  85. data/sample/moto/src/main/etc/log4j.xml +28 -0
  86. data/sample/moto/src/main/etc/status.properties +27 -0
  87. data/sample/moto/src/main/etc/sysparam.properties +54 -0
  88. data/sample/moto/src/main/java/jp/ossc/imortAuditlog/DateUtil.java +48 -0
  89. data/sample/moto/src/main/java/jp/ossc/imortAuditlog/ImportAuthLogMain.java +36 -0
  90. data/sample/moto/src/main/java/jp/ossc/imortAuditlog/LogReader.java +521 -0
  91. data/sample/moto/src/main/java/jp/ossc/imortAuditlog/MysqlController.java +315 -0
  92. data/sample/moto/src/main/logrotate/delete_auditlog +6 -0
  93. data/sample/moto/src/main/logrotate/delete_workflowinstanceslog +6 -0
  94. data/sample/moto/src/main/sql/tables.sql +36 -0
  95. data/test/cases/test_cmd.rb +120 -0
  96. data/test/cases/test_config.rb +41 -0
  97. data/test/cases/test_log.rb +599 -0
  98. data/test/conf/rbatch.yaml +0 -0
  99. data/test/mocks/PrintArgs.exe +0 -0
  100. data/test/mocks/win_cmd.exe +0 -0
  101. metadata +100 -1
@@ -0,0 +1,599 @@
1
+ require 'test/unit'
2
+ require 'fileutils'
3
+ require 'rbatch'
4
+ class LoggerTest < Test::Unit::TestCase
5
+ def setup
6
+ @dir = File.join(File.dirname(RBatch.program_name), "..", "log")
7
+ @dir2 = File.join(File.dirname(RBatch.program_name), "..", "log2")
8
+ @dir3 = File.join(File.dirname(RBatch.program_name), "..", "log3")
9
+ @config_dir = File.join(File.dirname(RBatch.program_name), "..", "conf")
10
+ Dir::mkdir(@dir)if ! Dir.exists? @dir
11
+ Dir::mkdir(@dir2)if ! Dir.exists? @dir2
12
+ Dir::mkdir(@config_dir) if ! Dir.exists? @config_dir
13
+ # RBatch::Log.verbose = true
14
+ # set STDOUT Logger stop
15
+ confstr = "log_quiet: true\n"
16
+ open( RBatch.common_config_path , "w" ){|f| f.write(confstr)}
17
+
18
+ end
19
+
20
+ def teardown
21
+ File::delete(RBatch.common_config_path) if File.exists?(RBatch.common_config_path)
22
+ if Dir.exists? @dir
23
+ Dir::foreach(@dir) do |f|
24
+ File::delete(File.join(@dir , f)) if ! (/\.+$/ =~ f)
25
+ end
26
+ Dir::rmdir(@dir)
27
+ end
28
+ if Dir.exists? @dir2
29
+ Dir::foreach(@dir2) do |f|
30
+ File::delete(File.join(@dir2 , f)) if ! (/\.+$/ =~ f)
31
+ end
32
+ Dir::rmdir(@dir2)
33
+ end
34
+ end
35
+
36
+ def testlog
37
+ RBatch::Log.new do | log |
38
+ log.info("test_log")
39
+ end
40
+ Dir::foreach(@dir) do |f|
41
+ if ! (/\.+$/ =~ f)
42
+ File::open(File.join(@dir , f)) {|f|
43
+ assert_match /test_log/, f.read
44
+ }
45
+ end
46
+ end
47
+ end
48
+
49
+ def test_log_dir_doesnot_exist
50
+ Dir::rmdir(@dir)
51
+ assert_raise(Errno::ENOENT){
52
+ RBatch::Log.new {|log|}
53
+ }
54
+ Dir::mkdir(@dir)
55
+ end
56
+
57
+ def test_change_name_by_opt
58
+ RBatch::Log.new({:name => "name1.log" }) do | log |
59
+ log.info("test_change_name_by_opt")
60
+ end
61
+ File::open(File.join(@dir , "name1.log")) {|f|
62
+ assert_match /test_change_name_by_opt/, f.read
63
+ }
64
+ end
65
+
66
+ def test_change_name_by_opt2
67
+ RBatch::Log.new({:name => "<prog><date>name.log" }) do | log |
68
+ log.info("test_change_name_by_opt2")
69
+ end
70
+ File::open(File.join(@dir , "test_log" + Time.now.strftime("%Y%m%d") + "name.log")) {|f|
71
+ assert_match /test_change_name_by_opt2/, f.read
72
+ }
73
+ end
74
+
75
+ def test_change_name_by_opt3
76
+ RBatch::Log.new({:name => "<prog>-<date>-name.log" }) do | log |
77
+ log.info("test_change_name_by_opt2")
78
+ end
79
+ File::open(File.join(@dir , "test_log-" + Time.now.strftime("%Y%m%d") + "-name.log")) {|f|
80
+ assert_match /test_change_name_by_opt2/, f.read
81
+ }
82
+ end
83
+
84
+
85
+ def test_change_name_by_config
86
+ confstr = "log_name: name1"
87
+ open( RBatch.common_config_path , "a" ){|f| f.write(confstr)}
88
+ RBatch::Log.new({:name => "name1.log" }) do | log |
89
+ log.info("test_change_name_by_config")
90
+ end
91
+ File::open(File.join(@dir , "name1.log")) {|f|
92
+ assert_match /test_change_name_by_config/, f.read
93
+ }
94
+ end
95
+
96
+
97
+ def test_change_log_dir_by_opt
98
+ RBatch::Log.new({:output_dir=> @dir2 }) do | log |
99
+ log.info("test_change_log_dir_by_opt")
100
+ end
101
+ Dir::foreach(@dir2) do |f|
102
+ if ! (/\.+$/ =~ f)
103
+ File::open(File.join(@dir2 , f)) {|f|
104
+ assert_match /test_change_log_dir_by_opt/, f.read
105
+ }
106
+ end
107
+ end
108
+ end
109
+
110
+ def test_change_log_dir_by_config
111
+ confstr = "log_dir: " + @dir2
112
+ open( RBatch.common_config_path , "a" ){|f| f.write(confstr)}
113
+ RBatch::Log.new({:output_dir=> @dir2 }) do | log |
114
+ log.info("test_change_log_dir_by_config")
115
+ end
116
+ Dir::foreach(@dir2) do |f|
117
+ if ! (/\.+$/ =~ f)
118
+ File::open(File.join(@dir2 , f)) {|f|
119
+ assert_match /test_change_log_dir_by_config/, f.read
120
+ }
121
+ end
122
+ end
123
+ end
124
+
125
+ def test_change_formatte
126
+ RBatch::Log.new({:name => "file" , :formatter => proc { |severity, datetime, progname, msg| "test_change_formatte#{msg}\n" }}) do | log |
127
+ log.info("bar")
128
+ end
129
+ File::open(File.join(@dir,"file")) {|f| assert_match /test_change_formatte/, f.read }
130
+ end
131
+
132
+ def test_nest_block
133
+ RBatch::Log.new({:name => "name1" }) do | log |
134
+ log.info("name1")
135
+ RBatch::Log.new({:name => "name2" }) do | log |
136
+ log.info("name2")
137
+ end
138
+ end
139
+ File::open(File.join(@dir,"name1")) {|f| assert_match /name1/, f.read }
140
+ File::open(File.join(@dir,"name2")) {|f| assert_match /name2/, f.read }
141
+ end
142
+
143
+ def test_opt_overwite_config
144
+ confstr = "log_name: " + "name1"
145
+ open( RBatch.common_config_path , "a" ){|f| f.write(confstr)}
146
+ RBatch::Log.new({:name => "name2" }) do | log |
147
+ log.info("test_opt_overwite_config")
148
+ end
149
+ File::open(File.join(@dir , "name2")) {|f|
150
+ assert_match /test_opt_overwite_config/, f.read
151
+ }
152
+ end
153
+
154
+ def test_append_by_opt
155
+ RBatch::Log.new({:append => true, :name => "test_append" }) do | log |
156
+ log.info("test_append1")
157
+ end
158
+ RBatch::Log.new({:append => true, :name => "test_append" }) do | log |
159
+ log.info("test_append2")
160
+ end
161
+ File::open(File.join(@dir , "test_append")) {|f|
162
+ str = f.read
163
+ assert_match /test_append1/, str
164
+ assert_match /test_append2/, str
165
+ }
166
+ end
167
+
168
+ def test_no_append_by_opt
169
+ RBatch::Log.new({:append => false, :name => "test_append" }) do | log |
170
+ log.info("test_append1")
171
+ end
172
+ RBatch::Log.new({:append => false, :name => "test_append" }) do | log |
173
+ log.info("test_append2")
174
+ end
175
+ File::open(File.join(@dir , "test_append")) {|f|
176
+ str = f.read
177
+ assert_no_match /test_append1/, str
178
+ assert_match /test_append2/, str
179
+ }
180
+ end
181
+
182
+
183
+ def test_append_by_conf
184
+ confstr = "log_append: true"
185
+ open( RBatch.common_config_path , "a" ){|f| f.write(confstr)}
186
+
187
+ RBatch::Log.new({:name => "test_append" }) do | log |
188
+ log.info("test_append1")
189
+ end
190
+ RBatch::Log.new({:name => "test_append" }) do | log |
191
+ log.info("test_append2")
192
+ end
193
+ File::open(File.join(@dir , "test_append")) {|f|
194
+ str = f.read
195
+ assert_match /test_append1/, str
196
+ assert_match /test_append2/, str
197
+ }
198
+ end
199
+
200
+ def test_no_append_by_conf
201
+ confstr = "log_append: false"
202
+ open( RBatch.common_config_path , "a" ){|f| f.write(confstr)}
203
+
204
+ RBatch::Log.new({ :name => "test_append" }) do | log |
205
+ log.info("test_append1")
206
+ end
207
+ RBatch::Log.new({ :name => "test_append" }) do | log |
208
+ log.info("test_append2")
209
+ end
210
+ File::open(File.join(@dir , "test_append")) {|f|
211
+ str = f.read
212
+ assert_no_match /test_append1/, str
213
+ assert_match /test_append2/, str
214
+ }
215
+ end
216
+
217
+ def test_log_level_default
218
+ RBatch::Log.new({ :name => "test_level" }) do | log |
219
+ log.debug("test_debug")
220
+ log.info("test_info")
221
+ log.warn("test_warn")
222
+ log.error("test_error")
223
+ log.fatal("test_fatal")
224
+ end
225
+ File::open(File.join(@dir , "test_level")) {|f|
226
+ str = f.read
227
+ assert_no_match /test_debug/, str
228
+ assert_match /test_info/, str
229
+ assert_match /test_warn/, str
230
+ assert_match /test_error/, str
231
+ assert_match /test_fatal/, str
232
+ }
233
+ end
234
+
235
+ def test_log_level_debug_by_opt
236
+ RBatch::Log.new({ :level => "debug",:name => "test_level" }) do | log |
237
+ log.debug("test_debug")
238
+ log.info("test_info")
239
+ log.warn("test_warn")
240
+ log.error("test_error")
241
+ log.fatal("test_fatal")
242
+ end
243
+ File::open(File.join(@dir , "test_level")) {|f|
244
+ str = f.read
245
+ assert_match /test_debug/, str
246
+ assert_match /test_info/, str
247
+ assert_match /test_warn/, str
248
+ assert_match /test_error/, str
249
+ assert_match /test_fatal/, str
250
+ }
251
+ end
252
+
253
+ def test_log_level_info_by_opt
254
+ RBatch::Log.new({ :level => "info",:name => "test_level" }) do | log |
255
+ log.debug("test_debug")
256
+ log.info("test_info")
257
+ log.warn("test_warn")
258
+ log.error("test_error")
259
+ log.fatal("test_fatal")
260
+ end
261
+ File::open(File.join(@dir , "test_level")) {|f|
262
+ str = f.read
263
+ assert_no_match /test_debug/, str
264
+ assert_match /test_info/, str
265
+ assert_match /test_warn/, str
266
+ assert_match /test_error/, str
267
+ assert_match /test_fatal/, str
268
+ }
269
+ end
270
+
271
+ def test_log_level_warn_by_opt
272
+ RBatch::Log.new({ :level => "warn",:name => "test_level" }) do | log |
273
+ log.debug("test_debug")
274
+ log.info("test_info")
275
+ log.warn("test_warn")
276
+ log.error("test_error")
277
+ log.fatal("test_fatal")
278
+ end
279
+ File::open(File.join(@dir , "test_level")) {|f|
280
+ str = f.read
281
+ assert_no_match /test_debug/, str
282
+ assert_no_match /test_info/, str
283
+ assert_match /test_warn/, str
284
+ assert_match /test_error/, str
285
+ assert_match /test_fatal/, str
286
+ }
287
+ end
288
+
289
+ def test_log_level_error_by_opt
290
+ RBatch::Log.new({ :level => "error",:name => "test_level" }) do | log |
291
+ log.debug("test_debug")
292
+ log.info("test_info")
293
+ log.warn("test_warn")
294
+ log.error("test_error")
295
+ log.fatal("test_fatal")
296
+ end
297
+ File::open(File.join(@dir , "test_level")) {|f|
298
+ str = f.read
299
+ assert_no_match /test_debug/, str
300
+ assert_no_match /test_info/, str
301
+ assert_no_match /test_warn/, str
302
+ assert_match /test_error/, str
303
+ assert_match /test_fatal/, str
304
+ }
305
+ end
306
+
307
+ def test_log_level_fatal_by_opt
308
+ RBatch::Log.new({ :level => "fatal",:name => "test_level" }) do | log |
309
+ log.debug("test_debug")
310
+ log.info("test_info")
311
+ log.warn("test_warn")
312
+ log.error("test_error")
313
+ log.fatal("test_fatal")
314
+ end
315
+ File::open(File.join(@dir , "test_level")) {|f|
316
+ str = f.read
317
+ assert_no_match /test_debug/, str
318
+ assert_no_match /test_info/, str
319
+ assert_no_match /test_warn/, str
320
+ assert_no_match /test_error/, str
321
+ assert_match /test_fatal/, str
322
+ }
323
+ end
324
+
325
+
326
+ def test_log_level_debug_by_conf
327
+ confstr = "log_level: debug"
328
+ open( RBatch.common_config_path , "a" ){|f| f.write(confstr)}
329
+
330
+ RBatch::Log.new({ :name => "test_level" }) do | log |
331
+ log.debug("test_debug")
332
+ log.info("test_info")
333
+ log.warn("test_warn")
334
+ log.error("test_error")
335
+ log.fatal("test_fatal")
336
+ end
337
+ File::open(File.join(@dir , "test_level")) {|f|
338
+ str = f.read
339
+ assert_match /test_debug/, str
340
+ assert_match /test_info/, str
341
+ assert_match /test_warn/, str
342
+ assert_match /test_error/, str
343
+ assert_match /test_fatal/, str
344
+ }
345
+ end
346
+
347
+ def test_log_level_info_by_conf
348
+ confstr = "log_level: info"
349
+ open( RBatch.common_config_path , "a" ){|f| f.write(confstr)}
350
+ RBatch::Log.new({ :name => "test_level" }) do | log |
351
+ log.debug("test_debug")
352
+ log.info("test_info")
353
+ log.warn("test_warn")
354
+ log.error("test_error")
355
+ log.fatal("test_fatal")
356
+ end
357
+ File::open(File.join(@dir , "test_level")) {|f|
358
+ str = f.read
359
+ assert_no_match /test_debug/, str
360
+ assert_match /test_info/, str
361
+ assert_match /test_warn/, str
362
+ assert_match /test_error/, str
363
+ assert_match /test_fatal/, str
364
+ }
365
+ end
366
+
367
+ def test_log_level_warn_by_conf
368
+ confstr = "log_level: warn"
369
+ open( RBatch.common_config_path , "a" ){|f| f.write(confstr)}
370
+ RBatch::Log.new({ :name => "test_level" }) do | log |
371
+ log.debug("test_debug")
372
+ log.info("test_info")
373
+ log.warn("test_warn")
374
+ log.error("test_error")
375
+ log.fatal("test_fatal")
376
+ end
377
+ File::open(File.join(@dir , "test_level")) {|f|
378
+ str = f.read
379
+ assert_no_match /test_debug/, str
380
+ assert_no_match /test_info/, str
381
+ assert_match /test_warn/, str
382
+ assert_match /test_error/, str
383
+ assert_match /test_fatal/, str
384
+ }
385
+ end
386
+
387
+ def test_log_level_error_by_conf
388
+ confstr = "log_level: error"
389
+ open( RBatch.common_config_path , "a" ){|f| f.write(confstr)}
390
+ RBatch::Log.new({ :name => "test_level" }) do | log |
391
+ log.debug("test_debug")
392
+ log.info("test_info")
393
+ log.warn("test_warn")
394
+ log.error("test_error")
395
+ log.fatal("test_fatal")
396
+ end
397
+ File::open(File.join(@dir , "test_level")) {|f|
398
+ str = f.read
399
+ assert_no_match /test_debug/, str
400
+ assert_no_match /test_info/, str
401
+ assert_no_match /test_warn/, str
402
+ assert_match /test_error/, str
403
+ assert_match /test_fatal/, str
404
+ }
405
+ end
406
+
407
+ def test_log_level_fatal_by_conf
408
+ confstr = "log_level: fatal"
409
+ open( RBatch.common_config_path , "a" ){|f| f.write(confstr)}
410
+ RBatch::Log.new({ :name => "test_level" }) do | log |
411
+ log.debug("test_debug")
412
+ log.info("test_info")
413
+ log.warn("test_warn")
414
+ log.error("test_error")
415
+ log.fatal("test_fatal")
416
+ end
417
+ File::open(File.join(@dir , "test_level")) {|f|
418
+ str = f.read
419
+ assert_no_match /test_debug/, str
420
+ assert_no_match /test_info/, str
421
+ assert_no_match /test_warn/, str
422
+ assert_no_match /test_error/, str
423
+ assert_match /test_fatal/, str
424
+ }
425
+ end
426
+
427
+
428
+ def test_i_log
429
+ log = RBatch::Log.new
430
+ assert_not_nil log
431
+ log.info("test_log")
432
+ log.close
433
+ Dir::foreach(@dir) do |f|
434
+ if ! (/\.+$/ =~ f)
435
+ File::open(File.join(@dir , f)) {|f|
436
+ assert_match /test_log/, f.read
437
+ }
438
+ end
439
+ end
440
+ end
441
+
442
+ def test_i_log_dir_doesnot_exist
443
+ Dir::rmdir(@dir)
444
+ assert_raise(Errno::ENOENT){
445
+ log = RBatch::Log.new
446
+ log.close
447
+ }
448
+ Dir::mkdir(@dir)
449
+ end
450
+
451
+ def test_i_change_name_by_opt
452
+ log = RBatch::Log.new({:name => "name1.log" })
453
+ log.info("test_change_name_by_opt")
454
+ log.close
455
+ File::open(File.join(@dir , "name1.log")) {|f|
456
+ assert_match /test_change_name_by_opt/, f.read
457
+ }
458
+ end
459
+
460
+ def test_i_change_name_by_opt2
461
+ log = RBatch::Log.new({:name => "<prog><date>name.log" })
462
+ log.info("test_change_name_by_opt2")
463
+ log.close
464
+ File::open(File.join(@dir , "test_log" + Time.now.strftime("%Y%m%d") + "name.log")) {|f|
465
+ assert_match /test_change_name_by_opt2/, f.read
466
+ }
467
+ end
468
+
469
+
470
+ def test_i_log_level_default
471
+ log = RBatch::Log.new({ :name => "test_level" })
472
+ log.debug("test_debug")
473
+ log.info("test_info")
474
+ log.warn("test_warn")
475
+ log.error("test_error")
476
+ log.fatal("test_fatal")
477
+ log.close
478
+
479
+ File::open(File.join(@dir , "test_level")) {|f|
480
+ str = f.read
481
+ assert_no_match /test_debug/, str
482
+ assert_match /test_info/, str
483
+ assert_match /test_warn/, str
484
+ assert_match /test_error/, str
485
+ assert_match /test_fatal/, str
486
+ }
487
+ end
488
+
489
+ def test_i_log_level_debug_by_opt
490
+ log = RBatch::Log.new({ :level => "debug",:name => "test_level" })
491
+ log.debug("test_debug")
492
+ log.info("test_info")
493
+ log.warn("test_warn")
494
+ log.error("test_error")
495
+ log.fatal("test_fatal")
496
+ log.close
497
+ File::open(File.join(@dir , "test_level")) {|f|
498
+ str = f.read
499
+ assert_match /test_debug/, str
500
+ assert_match /test_info/, str
501
+ assert_match /test_warn/, str
502
+ assert_match /test_error/, str
503
+ assert_match /test_fatal/, str
504
+ }
505
+ end
506
+
507
+
508
+ def test_i_log_level_debug_by_conf
509
+ confstr = "log_level: debug"
510
+ open( RBatch.common_config_path , "a" ){|f| f.write(confstr)}
511
+
512
+ log = RBatch::Log.new({ :name => "test_level" })
513
+ log.debug("test_debug")
514
+ log.info("test_info")
515
+ log.warn("test_warn")
516
+ log.error("test_error")
517
+ log.fatal("test_fatal")
518
+ log.close
519
+ File::open(File.join(@dir , "test_level")) {|f|
520
+ str = f.read
521
+ assert_match /test_debug/, str
522
+ assert_match /test_info/, str
523
+ assert_match /test_warn/, str
524
+ assert_match /test_error/, str
525
+ assert_match /test_fatal/, str
526
+ }
527
+ end
528
+
529
+ def test_delete_old_log_by_opt
530
+ loglist = [*0..20].map do |day|
531
+ File.join(@dir , (Date.today - day).strftime("%Y%m%d") + "_test_delete.log")
532
+ end
533
+ FileUtils.touch(loglist)
534
+ log = RBatch::Log.new({ :name => "<date>_test_delete.log",:delete_old_log => true})
535
+ log.close
536
+ loglist[1..6].each do |filename|
537
+ assert File.exists?(filename), "log file \"#{filename}\" should be exist"
538
+ end
539
+ loglist[7..20].each do |filename|
540
+ assert ! File.exists?(filename), "log file \"#{filename}\" should NOT be exist"
541
+ end
542
+ end
543
+ def test_delete_old_log_by_config
544
+ confstr = "log_delete_old_log: true"
545
+ open( RBatch.common_config_path , "a" ){|f| f.write(confstr)}
546
+
547
+ loglist = [*0..20].map do |day|
548
+ File.join(@dir , (Date.today - day).strftime("%Y%m%d") + "_test_delete.log")
549
+ end
550
+ FileUtils.touch(loglist)
551
+ log = RBatch::Log.new({ :name => "<date>_test_delete.log"})
552
+ log.close
553
+ loglist[1..6].each do |filename|
554
+ assert File.exists?(filename), "log file \"#{filename}\" should be exist"
555
+ end
556
+ loglist[7..20].each do |filename|
557
+ assert ! File.exists?(filename), "log file \"#{filename}\" should NOT be exist"
558
+ end
559
+ end
560
+
561
+ def test_delete_old_log_file_format_change_with_time
562
+ loglist = [*0..20].map do |day|
563
+ File.join(@dir , "235959-" + (Date.today - day).strftime("%Y%m%d") + "_test_delete.log")
564
+ end
565
+ FileUtils.touch(loglist)
566
+ log = RBatch::Log.new({ :name => "<time>-<date>_test_delete.log",:delete_old_log => true})
567
+ log.close
568
+ loglist[1..6].each do |filename|
569
+ assert File.exists?(filename), "log file \"#{filename}\" should be exist"
570
+ end
571
+ loglist[7..20].each do |filename|
572
+ assert ! File.exists?(filename), "log file \"#{filename}\" should NOT be exist"
573
+ end
574
+ end
575
+
576
+ def test_delete_old_log_file_format_change_no_date
577
+ log = RBatch::Log.new({ :name => "test_delete.log",:delete_old_log => true})
578
+ log.close
579
+ assert File.exists?(File.join(@dir,"test_delete.log")), "log file \"test_delete.log\" should be exist"
580
+ end
581
+
582
+ def test_delete_old_log_date
583
+ loglist = [*0..20].map do |day|
584
+ File.join(@dir , (Date.today - day).strftime("%Y%m%d") + "_test_delete.log")
585
+ end
586
+ FileUtils.touch(loglist)
587
+ log = RBatch::Log.new({ :name => "<date>_test_delete.log",:delete_old_log => true,:delete_old_log_date => 5})
588
+ log.close
589
+ loglist[1..4].each do |filename|
590
+ assert File.exists?(filename), "log file \"#{filename}\" should be exist"
591
+ end
592
+ loglist[5..20].each do |filename|
593
+ assert ! File.exists?(filename), "log file \"#{filename}\" should NOT be exist"
594
+ end
595
+ end
596
+
597
+
598
+ end
599
+
File without changes
Binary file
Binary file