rbatch 2.3.1 → 2.4.0
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.
- data/CHANGELOG +67 -60
- data/README.ja.md +12 -0
- data/README.md +98 -53
- data/bin/rbatch-init +9 -0
- data/lib/rbatch/log.rb +12 -8
- data/lib/rbatch/run_conf.rb +1 -0
- data/lib/rbatch/version.rb +1 -1
- data/sample/.rbatchrc +9 -0
- data/spec/rbatch/log_spec.rb +293 -245
- metadata +2 -2
data/CHANGELOG
CHANGED
|
@@ -2,99 +2,106 @@ CHANGE LOG
|
|
|
2
2
|
|
|
3
3
|
This document includes functions which is added or changed.
|
|
4
4
|
This document does NOT include bugfix.
|
|
5
|
+
|
|
5
6
|
If you want to know about bug fix, please see commit logs of https://github.com/fetaro/rbatch .
|
|
6
7
|
|
|
7
8
|
===================
|
|
8
|
-
version
|
|
9
|
+
version 2
|
|
9
10
|
===================
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
*
|
|
12
|
+
2.4.0 (2015/06/08)
|
|
13
|
+
----
|
|
14
|
+
* [add] new option : "log_output_exit_status"
|
|
15
|
+
* [change] log massage has been changed when you use "exit" in RBatch Log block.
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* [add]
|
|
18
|
-
* [change]
|
|
17
|
+
2.3.0 (2014/10/28)
|
|
18
|
+
----
|
|
19
|
+
* [add] new option : "log_bufferd"
|
|
20
|
+
* [change] before log output is bufferd, now not.
|
|
21
|
+
* [bugfix] fix that it raises error if .rbatchrc is empty.
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
* [
|
|
23
|
-
* [add] new option : "log_append"
|
|
23
|
+
2.2.0 (2014/4/15)
|
|
24
|
+
----
|
|
25
|
+
* [add] now "log_mail_to" option accepts multiple recipients, before it accepts only one recipient.
|
|
24
26
|
|
|
25
|
-
1.
|
|
26
|
-
|
|
27
|
-
* [add] add
|
|
28
|
-
* [add]
|
|
27
|
+
2.1.0 (2013/1/10)
|
|
28
|
+
----
|
|
29
|
+
* [add] add an error handling when user mistake key class as Symbol for String in config file.
|
|
30
|
+
* [add] add function of auto library file reading
|
|
31
|
+
* [add] new option : "mix_rbatch_msg_to_log"
|
|
32
|
+
* [change] config reading timing. before ondemand, now initial.
|
|
29
33
|
|
|
30
|
-
|
|
34
|
+
2.0.0 (2013/12/28)
|
|
31
35
|
----
|
|
32
|
-
* [
|
|
33
|
-
* [add] add
|
|
36
|
+
* [change] Change Run-Conf path from "${RB_HOME}/conf/rbatch.yaml" to "${RB_HOME}/.rbatchrc"
|
|
37
|
+
* [add] add function of checking existence of Run-Conf's keys.
|
|
38
|
+
* [add] new options : "conf_dir", "common_conf_name", "cmd_timeout".
|
|
39
|
+
* [add] when cmd_timeout occured, RBatch kill child process now.
|
|
40
|
+
* [change] Change test code from Test::Unit to RSpec.
|
|
34
41
|
|
|
35
|
-
|
|
42
|
+
|
|
43
|
+
===================
|
|
44
|
+
version 1
|
|
45
|
+
===================
|
|
46
|
+
|
|
47
|
+
1.13 (2013/12/19)
|
|
36
48
|
----
|
|
37
|
-
* [
|
|
49
|
+
* [add] add customize point that can change RBatch home directory by using the environment variables, ${RB_HOME}.
|
|
38
50
|
|
|
39
|
-
1.
|
|
51
|
+
1.12 (2013/11/19)
|
|
40
52
|
----
|
|
41
|
-
* [add] add
|
|
53
|
+
* [add] add Common Config Function
|
|
42
54
|
|
|
43
|
-
1.
|
|
55
|
+
1.11 (2013/02/24)
|
|
44
56
|
----
|
|
45
|
-
* [
|
|
46
|
-
* [delete] change log format option
|
|
57
|
+
* [add] support for MAC-OSX environment (change handling of the environment variable about hostname and temporary directory)
|
|
47
58
|
|
|
48
|
-
1.
|
|
59
|
+
1.10 (2013/02/12)
|
|
49
60
|
----
|
|
50
|
-
* [add]
|
|
61
|
+
* [add] add rbatch-init command
|
|
51
62
|
|
|
52
63
|
1.9 (2013/02/11)
|
|
53
64
|
----
|
|
54
65
|
* [add] add "<host>" keyword to log_name option
|
|
55
66
|
* [change] Environmental variables ($TMPDIR and $HOSTNAME) are checked strictly
|
|
56
67
|
|
|
57
|
-
1.
|
|
68
|
+
1.8 (2013/02/10)
|
|
58
69
|
----
|
|
59
|
-
* [add]
|
|
70
|
+
* [add] new option : "log_send_mail", "cmd_timeout"
|
|
60
71
|
|
|
61
|
-
1.
|
|
72
|
+
1.7 (2013/01/30)
|
|
62
73
|
----
|
|
63
|
-
* [
|
|
74
|
+
* [change] log format
|
|
75
|
+
* [delete] change log format option
|
|
64
76
|
|
|
65
|
-
1.
|
|
77
|
+
1.6 (2013/1/14)
|
|
66
78
|
----
|
|
67
|
-
* [add] add
|
|
79
|
+
* [add] add function of cheking config keys
|
|
68
80
|
|
|
69
|
-
1.
|
|
81
|
+
1.5 (2013/1/11)
|
|
70
82
|
----
|
|
71
|
-
* [
|
|
72
|
-
|
|
73
|
-
===================
|
|
74
|
-
version 2
|
|
75
|
-
===================
|
|
83
|
+
* [change] change default config dir from "../config" to "../conf"
|
|
76
84
|
|
|
77
|
-
|
|
85
|
+
1.4 (2013/1/5)
|
|
78
86
|
----
|
|
79
|
-
* [
|
|
80
|
-
* [add] add
|
|
81
|
-
* [add] new options : "conf_dir", "common_conf_name", "cmd_timeout".
|
|
82
|
-
* [add] when cmd_timeout occured, RBatch kill child process now.
|
|
83
|
-
* [change] Change test code from Test::Unit to RSpec.
|
|
87
|
+
* [add] new options : "log_stdout", "cmd_raise", "log_delete_old_log"
|
|
88
|
+
* [add] add sample code
|
|
84
89
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
* [add] add
|
|
88
|
-
* [add]
|
|
89
|
-
* [add] new option : "mix_rbatch_msg_to_log"
|
|
90
|
-
* [change] config reading timing. before ondemand, now initial.
|
|
90
|
+
1.3 (2012/12/30)
|
|
91
|
+
-----
|
|
92
|
+
* [add] add customize point to RBatch::Log's constructor
|
|
93
|
+
* [add] new option : "double_run_check"
|
|
91
94
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
* [
|
|
95
|
+
1.2 (2012/11/13)
|
|
96
|
+
-----
|
|
97
|
+
* [change] log level option format
|
|
98
|
+
* [add] new option : "log_append"
|
|
95
99
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
* [add]
|
|
99
|
-
* [change]
|
|
100
|
-
|
|
100
|
+
1.1 (2012/11/9)
|
|
101
|
+
-----
|
|
102
|
+
* [add] common config file
|
|
103
|
+
* [change] new option : "log"
|
|
104
|
+
|
|
105
|
+
1.0
|
|
106
|
+
-----
|
|
107
|
+
* initial
|
data/README.ja.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
[English](https://github.com/fetaro/rbatch/blob/master/README.md "english") | [Japanese ](https://github.com/fetaro/rbatch/blob/master/README.ja.md "japanese") | [Document (YardDoc)](http://fetaro.github.io/rbatch/index.html)
|
|
2
2
|
|
|
3
|
+
[](http://badge.fury.io/rb/rbatch)
|
|
4
|
+
[](https://travis-ci.org/fetaro/rbatch)
|
|
3
5
|
RBatch: バッチスクリプト フレームワーク
|
|
4
6
|
=============
|
|
5
7
|
|
|
@@ -412,6 +414,15 @@ Run-Conf(`${RB_HOME}/.rbatchrc`)のサンプルは以下の通り
|
|
|
412
414
|
#log_bufferd : true
|
|
413
415
|
#log_bufferd : false
|
|
414
416
|
|
|
417
|
+
# exitステータスをログに出すかどうか
|
|
418
|
+
#
|
|
419
|
+
# デフォルトはtrue。
|
|
420
|
+
# ログブロック内で "exist" メソッドを使った時に、
|
|
421
|
+
# exitステータスをログファイルに出力する。
|
|
422
|
+
#
|
|
423
|
+
#log_output_exit_status : true
|
|
424
|
+
#log_output_exit_status : false
|
|
425
|
+
|
|
415
426
|
# メール送信するかどうか
|
|
416
427
|
#
|
|
417
428
|
# デフォルト値は false。
|
|
@@ -470,6 +481,7 @@ opt = {
|
|
|
470
481
|
:delete_old_log => false,
|
|
471
482
|
:delete_old_log_date => 7,
|
|
472
483
|
:bufferd => false,
|
|
484
|
+
:log_output_exit_status => true,
|
|
473
485
|
:send_mail => false,
|
|
474
486
|
:mail_to => nil,
|
|
475
487
|
:mail_from => "rbatch.localhost",
|
data/README.md
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
|
-
[English](https://github.com/fetaro/rbatch/blob/master/README.md "english") | [Japanese ](https://github.com/fetaro/rbatch/blob/master/README.ja.md "japanese") | [Document (YardDoc)](http://fetaro.github.io/rbatch/index.html)
|
|
2
1
|
|
|
2
|
+
|
|
3
|
+
[English](https://github.com/fetaro/rbatch/blob/master/README.md
|
|
4
|
+
"english") | [Japanese
|
|
5
|
+
](https://github.com/fetaro/rbatch/blob/master/README.ja.md
|
|
6
|
+
"japanese") | [Document
|
|
7
|
+
(YardDoc)](http://fetaro.github.io/rbatch/index.html)
|
|
8
|
+
|
|
9
|
+
[](http://badge.fury.io/rb/rbatch)
|
|
10
|
+
[](https://travis-ci.org/fetaro/rbatch)
|
|
3
11
|
RBatch: Batch Script Framework
|
|
4
12
|
=============
|
|
5
13
|
|
|
6
14
|
About RBatch
|
|
7
15
|
--------------
|
|
8
16
|
|
|
9
|
-
RBatch is a ruby-based framework for batch scripts. RBatch help to
|
|
17
|
+
RBatch is a ruby-based framework for batch scripts. RBatch help to
|
|
18
|
+
make batch scripts such as "data backup" or "proccess controll ".
|
|
10
19
|
|
|
11
|
-
There are following functions
|
|
20
|
+
There are following functions:
|
|
12
21
|
|
|
13
22
|
* Auto Logging
|
|
14
23
|
* Auto Library Loading
|
|
@@ -17,7 +26,7 @@ There are following functions.
|
|
|
17
26
|
* External Command Wrapper
|
|
18
27
|
* Double Run Check
|
|
19
28
|
|
|
20
|
-
Note: RBatch works on Ruby 1.9.
|
|
29
|
+
Note: RBatch works on Ruby 1.9 above.
|
|
21
30
|
|
|
22
31
|
Note: This software is released under the MIT License, see LICENSE.txt.
|
|
23
32
|
|
|
@@ -34,26 +43,26 @@ Overview
|
|
|
34
43
|
|
|
35
44
|
### RBatch home directory
|
|
36
45
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
46
|
+
If you set the `${RB_HOME}` as environment variable, RBatch home
|
|
47
|
+
directory is fixed at `${RB_HOME}`.
|
|
48
|
+
Otherwise, `${RB_HOME}` is the parent directory of the directory where
|
|
49
|
+
the script is located. In other words, default of `${RB_HOME}` is
|
|
50
|
+
`(script path)/../` .
|
|
40
51
|
|
|
41
52
|
### Directory Structure and File Naming Convention
|
|
42
53
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
If you follow these rules, you will gain plenty development
|
|
46
|
-
|
|
47
|
-
The rules are
|
|
54
|
+
RBatch is made based on the rule of "convention over configuration".
|
|
55
|
+
So there are conventions of file naming and directory structure.
|
|
56
|
+
If you follow these rules, you will gain plenty development
|
|
57
|
+
environment without any configurations.
|
|
48
58
|
|
|
49
|
-
|
|
50
|
-
* individual config file should be `${RB_HOME}/conf/hoge.yaml`
|
|
51
|
-
* common(shared) config file should be `${RB_HOME}/conf/common.yaml`
|
|
52
|
-
* libraries should be `${RB_HOME}/lib/*.rb`
|
|
59
|
+
The rules are below:
|
|
53
60
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
*
|
|
61
|
+
* Script should be `${RB_HOME}/bin/hoge.rb`
|
|
62
|
+
* Config file should be `${RB_HOME}/conf/hoge.yaml`
|
|
63
|
+
* Common config file should be `${RB_HOME}/conf/common.yaml`
|
|
64
|
+
* Libraries should be `${RB_HOME}/lib/*.rb`
|
|
65
|
+
* Log files should be `${RB_HOME}/log/YYYYMMDD_HHMMSS_hoge.log`
|
|
57
66
|
|
|
58
67
|
For example
|
|
59
68
|
|
|
@@ -80,13 +89,16 @@ For example
|
|
|
80
89
|
|
|
81
90
|
### Auto Logging
|
|
82
91
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
92
|
+
By using the auto logging block ,`RBatch::Log`, RBatch automatically
|
|
93
|
+
output logfiles.
|
|
94
|
+
The default location of log files are
|
|
95
|
+
`${RB_HOME}/log/YYYYMMDD_HHMMSS_(script base).log`.
|
|
96
|
+
If exceptions are raised in auto logging block, RBatch will rescue it
|
|
97
|
+
and output its stack trace to the logfile.
|
|
86
98
|
|
|
87
|
-
|
|
99
|
+
Sample
|
|
88
100
|
|
|
89
|
-
|
|
101
|
+
Make script `${RB_HOME}/bin/sample1.rb`
|
|
90
102
|
|
|
91
103
|
```ruby
|
|
92
104
|
require 'rbatch'
|
|
@@ -105,25 +117,30 @@ Run script. Log file is `${RB_HOME}/log/20121020_005953_sample1.log`
|
|
|
105
117
|
[2012-10-20 00:59:53 +900] [FATAL] Caught exception; existing 1
|
|
106
118
|
[2012-10-20 00:59:53 +900] [FATAL] exception (RuntimeError)
|
|
107
119
|
[backtrace] test.rb:6:in `block in <main>'
|
|
108
|
-
[backtrace]
|
|
120
|
+
[backtrace]
|
|
121
|
+
/usr/local/lib/ruby192/lib/ruby/gems/1.9.1/gems/rbatch-1.0.0/lib/rbatch/auto_logger.rb:37:in
|
|
122
|
+
`initialize'
|
|
109
123
|
[backtrace] test.rb:3:in `new'
|
|
110
124
|
[backtrace] test.rb:3:in `<main>'
|
|
111
125
|
|
|
112
126
|
### Auto Library Loading
|
|
113
127
|
|
|
114
|
-
If you make
|
|
128
|
+
If you make libraries at `${RB_HOME}/lib/*.rb`, these are
|
|
129
|
+
loaded(required) before scripts run.
|
|
115
130
|
|
|
116
131
|
### Auto Mail Sending
|
|
117
132
|
|
|
118
|
-
By using `log_send_mail` option,
|
|
133
|
+
By using `log_send_mail` option, RBatch sends error messages by e-mail
|
|
134
|
+
when ERROR or FATAL level logs are raised.
|
|
119
135
|
|
|
120
136
|
### Auto Config Reading
|
|
121
137
|
|
|
122
|
-
|
|
138
|
+
By putting the configuration file as `${RB_HOME}/conf/"(script
|
|
139
|
+
base).yaml"`, the file is read and parsed automatically.
|
|
123
140
|
|
|
124
|
-
|
|
141
|
+
Sample
|
|
125
142
|
|
|
126
|
-
|
|
143
|
+
Make the config file `${RB_HOME}/conf/sample2.yaml`.
|
|
127
144
|
|
|
128
145
|
key: value
|
|
129
146
|
array:
|
|
@@ -137,7 +154,7 @@ In script named `${RB_HOME}/bin/sample2.rb`, this config values can be used.
|
|
|
137
154
|
require 'rbatch'
|
|
138
155
|
|
|
139
156
|
# You can read config value without loading file.
|
|
140
|
-
p RBatch.config["key"] # => "value"
|
|
157
|
+
p RBatch.config["key"] # => "value"
|
|
141
158
|
p RBatch.config["array"] # => ["item1", "item2", "item3"]
|
|
142
159
|
|
|
143
160
|
# If key does not exist, raise exception
|
|
@@ -146,16 +163,20 @@ p RBatch.config["not_exist"] # => Raise RBatch::ConfigException
|
|
|
146
163
|
|
|
147
164
|
#### Common Config
|
|
148
165
|
|
|
149
|
-
|
|
150
|
-
|
|
166
|
+
By putting shard config file at `${RB_HOME}/conf/common.yaml`, the
|
|
167
|
+
values in the file are shared by all scripts.
|
|
168
|
+
If you want to change the name of the config file, you cau use the
|
|
169
|
+
`common_conf_name` option.
|
|
151
170
|
|
|
152
171
|
### External Command Wrapper
|
|
153
172
|
|
|
154
|
-
|
|
173
|
+
RBatch have useful functions of external command execution.
|
|
174
|
+
`RBatch.cmd` is wrapper of `Kernel.#Spawn`.
|
|
155
175
|
|
|
156
|
-
This function return a result object which contains command's
|
|
176
|
+
This function return a result object which contains command's string,
|
|
177
|
+
STDOUT, STDERR and exit status.
|
|
157
178
|
|
|
158
|
-
|
|
179
|
+
Sample
|
|
159
180
|
|
|
160
181
|
```ruby
|
|
161
182
|
require 'rbatch'
|
|
@@ -166,14 +187,17 @@ p r.stderr # => ""
|
|
|
166
187
|
p r.status # => 0
|
|
167
188
|
```
|
|
168
189
|
|
|
169
|
-
If you want to set a timeout of external command, you can use
|
|
190
|
+
If you want to set a timeout of external command, you can use
|
|
191
|
+
`cmd_timeout` option.
|
|
170
192
|
|
|
171
|
-
By using `cmd_raise` option, if exit status
|
|
193
|
+
By using `cmd_raise` option, if exit status is not 0,
|
|
194
|
+
RBatch raise an Exception.
|
|
172
195
|
This function help to handle the errors of external command.
|
|
173
196
|
|
|
174
197
|
### Double Run Check
|
|
175
198
|
|
|
176
|
-
By using `forbid_double_run` option, two scripts both has same name
|
|
199
|
+
By using `forbid_double_run` option, two scripts both has same name
|
|
200
|
+
cannot run at the same time.
|
|
177
201
|
|
|
178
202
|
Manual
|
|
179
203
|
--------------
|
|
@@ -204,21 +228,25 @@ require 'rbatch' # <= require rbatch
|
|
|
204
228
|
require 'aws-sdk'
|
|
205
229
|
require 'net/http'
|
|
206
230
|
|
|
207
|
-
RBatch::Log.new do |log| # <= Start Log block. And write main logic in
|
|
231
|
+
RBatch::Log.new do |log| # <= Start Log block. And write main logic in
|
|
232
|
+
this block.
|
|
208
233
|
# get ec2 region
|
|
209
234
|
@ec2_region = "ec2." +
|
|
210
|
-
Net::HTTP.get("169.254.169.254",
|
|
235
|
+
Net::HTTP.get("169.254.169.254",
|
|
236
|
+
"/latest/meta-data/placement/availability-zone").chop +
|
|
211
237
|
".amazonaws.com"
|
|
212
238
|
log.info("ec2 region : #{@ec2_region}") # <= Output Log
|
|
213
239
|
|
|
214
240
|
#create ec2 instance
|
|
215
|
-
@ec2 = AWS::EC2.new(:access_key_id =>
|
|
241
|
+
@ec2 = AWS::EC2.new(:access_key_id =>
|
|
242
|
+
RBatch.config["access_key"], # <= Read Config
|
|
216
243
|
:secret_access_key => RBatch.config["secret_key"],
|
|
217
244
|
:ec2_endpoint => @ec2_region)
|
|
218
245
|
|
|
219
246
|
|
|
220
247
|
# create instance
|
|
221
|
-
@instance_id = Net::HTTP.get("169.254.169.254",
|
|
248
|
+
@instance_id = Net::HTTP.get("169.254.169.254",
|
|
249
|
+
"/latest/meta-data/instance-id")
|
|
222
250
|
@instance = @ec2.instances[@instance_id]
|
|
223
251
|
log.info("instance_id : #{@instance_id}")
|
|
224
252
|
|
|
@@ -234,7 +262,7 @@ end
|
|
|
234
262
|
|
|
235
263
|
```
|
|
236
264
|
|
|
237
|
-
Finally you run the script, then following logfile is output.
|
|
265
|
+
Finally, you run the script, then following logfile is output.
|
|
238
266
|
|
|
239
267
|
Log file : `${RB_HOME}/log/20140121_123124_ec2_create_snapshot.log`
|
|
240
268
|
|
|
@@ -242,16 +270,22 @@ Log file : `${RB_HOME}/log/20140121_123124_ec2_create_snapshot.log`
|
|
|
242
270
|
[2014-01-21 12:31:24 -0500] [INFO ] === START RBatch === (PID=10095)
|
|
243
271
|
[2014-01-21 12:31:24 -0500] [INFO ] RB_HOME : "/opt/MyProject"
|
|
244
272
|
[2014-01-21 12:31:24 -0500] [INFO ] Load Run-Conf: "/opt/MyProject/.rbatchrc"
|
|
245
|
-
[2014-01-21 12:31:24 -0500] [INFO ] Load Config :
|
|
246
|
-
|
|
247
|
-
[2014-01-21 12:31:24 -0500] [INFO ]
|
|
248
|
-
|
|
273
|
+
[2014-01-21 12:31:24 -0500] [INFO ] Load Config :
|
|
274
|
+
"/opt/MyProject/conf/ec2_create_snapshot.yaml"
|
|
275
|
+
[2014-01-21 12:31:24 -0500] [INFO ] Start Script :
|
|
276
|
+
"/opt/MyProject/bin/ec2_create_snapshot.rb"
|
|
277
|
+
[2014-01-21 12:31:24 -0500] [INFO ] Logging Start:
|
|
278
|
+
"/opt/MyProject/log/20140121_123124_ec2_create_snapshot.log"
|
|
279
|
+
[2014-01-21 12:31:24 -0500] [INFO ] ec2 region :
|
|
280
|
+
ec2.ap-northeast-1.amazonaws.com
|
|
249
281
|
[2014-01-21 12:31:25 -0500] [INFO ] instance_id : i-cc25f1c9
|
|
250
|
-
[2014-01-21 12:31:25 -0500] [INFO ] create snapshot : i-cc25f1c9
|
|
282
|
+
[2014-01-21 12:31:25 -0500] [INFO ] create snapshot : i-cc25f1c9
|
|
283
|
+
/dev/sda1 vol-82483ea7 2014/01/21 12:31
|
|
251
284
|
[2014-01-21 12:31:25 -0500] [INFO ] sucess
|
|
252
285
|
```
|
|
253
286
|
|
|
254
|
-
Only you write a short code, this batch script has logging and
|
|
287
|
+
Only you write a short code, this batch script has logging and
|
|
288
|
+
reading config function.
|
|
255
289
|
|
|
256
290
|
Customize
|
|
257
291
|
--------------
|
|
@@ -316,7 +350,7 @@ Sample of RBatch Run-Conf `${RB_HOME}/.rbatchrc`.
|
|
|
316
350
|
# RBatch Journal Level
|
|
317
351
|
#
|
|
318
352
|
# Default is 1
|
|
319
|
-
# RBatch Journal is message of RBatch and is output to STDOUT.
|
|
353
|
+
# RBatch Journal is message of RBatch and is output to STDOUT.
|
|
320
354
|
# If 2, put much more information.
|
|
321
355
|
# If 0, put nothing.
|
|
322
356
|
#
|
|
@@ -407,6 +441,15 @@ Sample of RBatch Run-Conf `${RB_HOME}/.rbatchrc`.
|
|
|
407
441
|
#log_bufferd : true
|
|
408
442
|
#log_bufferd : false
|
|
409
443
|
|
|
444
|
+
# Output Exit Status
|
|
445
|
+
#
|
|
446
|
+
# Default is true.
|
|
447
|
+
# When you use the "exist" method in a log block,
|
|
448
|
+
# output exit status into the log file.
|
|
449
|
+
#
|
|
450
|
+
#log_output_exit_status : true
|
|
451
|
+
#log_output_exit_status : false
|
|
452
|
+
|
|
410
453
|
# Send Mail
|
|
411
454
|
#
|
|
412
455
|
# Default is false.
|
|
@@ -451,7 +494,8 @@ Sample of RBatch Run-Conf `${RB_HOME}/.rbatchrc`.
|
|
|
451
494
|
|
|
452
495
|
### Customize by passing option object to constructor
|
|
453
496
|
|
|
454
|
-
If you want to change options in a script, you pass an options object
|
|
497
|
+
If you want to change options in a script, you pass an options object
|
|
498
|
+
to the constructor of RBatch::Log or RBatch::Cmd.
|
|
455
499
|
|
|
456
500
|
#### option of RBatch::Log
|
|
457
501
|
|
|
@@ -492,4 +536,5 @@ Migration from version 1 to version 2
|
|
|
492
536
|
--------------
|
|
493
537
|
|
|
494
538
|
Move `${RB_HOME}/conf/rbatch.yaml` to `${RB_HOME}/.rbatchrc` .
|
|
495
|
-
|
|
539
|
+
|
|
540
|
+
|
data/bin/rbatch-init
CHANGED
|
@@ -142,6 +142,15 @@ contents[".rbatchrc"] = <<EOF
|
|
|
142
142
|
#log_bufferd : true
|
|
143
143
|
#log_bufferd : false
|
|
144
144
|
|
|
145
|
+
# Output Exit Status
|
|
146
|
+
#
|
|
147
|
+
# Default is true.
|
|
148
|
+
# When you use the "exist" method in a log block,
|
|
149
|
+
# output exit status into the log file.
|
|
150
|
+
#
|
|
151
|
+
#log_output_exit_status : true
|
|
152
|
+
#log_output_exit_status : false
|
|
153
|
+
|
|
145
154
|
# Send Mail
|
|
146
155
|
#
|
|
147
156
|
# Default is false.
|
data/lib/rbatch/log.rb
CHANGED
|
@@ -86,6 +86,9 @@ module RBatch
|
|
|
86
86
|
# If this is true, delete old log files when this is called.
|
|
87
87
|
# If log filename does not include "<date>", do nothing.
|
|
88
88
|
# @option opt [Integer] :delete_old_log_date
|
|
89
|
+
# @option opt [Boolean] :output_exit_status
|
|
90
|
+
# When you use the "exist" method in a log block,
|
|
91
|
+
# output exit status into the log file.
|
|
89
92
|
# @option opt [Boolean] :send_mail
|
|
90
93
|
# When log.error(str) is called,
|
|
91
94
|
# log.fatal(str) is called , or rescue an Exception,
|
|
@@ -112,7 +115,6 @@ module RBatch
|
|
|
112
115
|
# RBatch::Log.new({:name => "hoge.log"}){ |log|
|
|
113
116
|
# log.info "info string"
|
|
114
117
|
# }
|
|
115
|
-
|
|
116
118
|
def initialize(opt=nil)
|
|
117
119
|
@opt = opt
|
|
118
120
|
@vars = @@def_vars.clone
|
|
@@ -158,16 +160,18 @@ module RBatch
|
|
|
158
160
|
begin
|
|
159
161
|
yield self
|
|
160
162
|
rescue SystemExit => e
|
|
161
|
-
if
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
163
|
+
if @vars[:log_output_exit_status]
|
|
164
|
+
if e.status == 0
|
|
165
|
+
info("RBatch catch SystemExit. Exit with status " + e.status.to_s)
|
|
166
|
+
else
|
|
167
|
+
fatal(e)
|
|
168
|
+
fatal("RBatch catch SystemExit. Exit with status " + e.status.to_s)
|
|
169
|
+
end
|
|
167
170
|
end
|
|
171
|
+
exit e.status
|
|
168
172
|
rescue Exception => e
|
|
169
173
|
fatal(e)
|
|
170
|
-
fatal("
|
|
174
|
+
fatal("RBatch catch an exception. Exit with status 1")
|
|
171
175
|
exit 1
|
|
172
176
|
ensure
|
|
173
177
|
close
|
data/lib/rbatch/run_conf.rb
CHANGED
data/lib/rbatch/version.rb
CHANGED
data/sample/.rbatchrc
CHANGED
|
@@ -138,6 +138,15 @@
|
|
|
138
138
|
#log_bufferd : true
|
|
139
139
|
#log_bufferd : false
|
|
140
140
|
|
|
141
|
+
# Output Exit Status
|
|
142
|
+
#
|
|
143
|
+
# Default is true.
|
|
144
|
+
# When you use the "exist" method in a log block,
|
|
145
|
+
# output exit status into the log file.
|
|
146
|
+
#
|
|
147
|
+
#log_output_exit_status : true
|
|
148
|
+
#log_output_exit_status : false
|
|
149
|
+
|
|
141
150
|
# Send Mail
|
|
142
151
|
#
|
|
143
152
|
# Default is false.
|
data/spec/rbatch/log_spec.rb
CHANGED
|
@@ -96,279 +96,327 @@ describe RBatch::Log do
|
|
|
96
96
|
end
|
|
97
97
|
|
|
98
98
|
describe "option by argument" do
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
it "change log name 2" do
|
|
108
|
-
opt = {:name => "<prog><date>name.log" }
|
|
109
|
-
RBatch::Log.new(opt) { | log | log.info("hoge") }
|
|
110
|
-
|
|
111
|
-
File::open(File.join(@log_dir , "rspec" + Time.now.strftime("%Y%m%d") + "name.log")) {|f|
|
|
112
|
-
expect(f.read).to match /hoge/
|
|
113
|
-
}
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
it "change log name 3" do
|
|
117
|
-
opt = {:name => "<prog>-<date>-name.log" }
|
|
118
|
-
RBatch::Log.new(opt) { | log | log.info("hoge") }
|
|
119
|
-
|
|
120
|
-
File::open(File.join(@log_dir , "rspec-" + Time.now.strftime("%Y%m%d") + "-name.log")) {|f|
|
|
121
|
-
expect(f.read).to match /hoge/
|
|
122
|
-
}
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
it "change log dir" do
|
|
126
|
-
@tmp = File.join(ENV["RB_HOME"],"log3")
|
|
127
|
-
Dir.mkdir(@tmp)
|
|
128
|
-
opt = {:name => "c.log", :dir=> @tmp }
|
|
129
|
-
RBatch::Log.new(opt) { | log | log.info("hoge") }
|
|
130
|
-
|
|
131
|
-
File::open(File.join(@tmp , "c.log")) {|f|
|
|
132
|
-
expect(f.read).to match /hoge/
|
|
133
|
-
}
|
|
134
|
-
FileUtils.rm(File.join(@tmp , "c.log"))
|
|
135
|
-
Dir.rmdir(@tmp)
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
it "is append mode" do
|
|
139
|
-
opt = {:append => true, :name => "a.log" }
|
|
140
|
-
RBatch::Log.new(opt) { | log | log.info("line1") }
|
|
141
|
-
|
|
142
|
-
opt = {:append => true, :name => "a.log" }
|
|
143
|
-
RBatch::Log.new(opt) { | log | log.info("line2") }
|
|
144
|
-
|
|
145
|
-
File::open(File.join(@log_dir , "a.log")) {|f|
|
|
146
|
-
str = f.read
|
|
147
|
-
expect(str).to match /line1/
|
|
148
|
-
expect(str).to match /line2/
|
|
149
|
-
}
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
it "is overwrite mode" do
|
|
153
|
-
opt = {:append => false, :name => "a.log" }
|
|
154
|
-
RBatch::Log.new(opt) { | log | log.info("line1") }
|
|
155
|
-
|
|
156
|
-
opt = {:append => false, :name => "a.log" }
|
|
157
|
-
RBatch::Log.new(opt) { | log | log.info("line2") }
|
|
158
|
-
|
|
159
|
-
File::open(File.join(@log_dir , "a.log")) {|f|
|
|
160
|
-
str = f.read
|
|
161
|
-
expect(str).to_not match /line1/
|
|
162
|
-
expect(str).to match /line2/
|
|
163
|
-
}
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
it "is debug level" do
|
|
167
|
-
opt = { :level => "debug",:name => "a.log" }
|
|
168
|
-
RBatch::Log.new(opt) do | log |
|
|
169
|
-
log.debug("test_debug")
|
|
170
|
-
log.info("test_info")
|
|
171
|
-
log.warn("test_warn")
|
|
172
|
-
log.error("test_error")
|
|
173
|
-
log.fatal("test_fatal")
|
|
99
|
+
describe ":name option" do
|
|
100
|
+
it "change log name" do
|
|
101
|
+
opt = {:name => "name1.log" }
|
|
102
|
+
RBatch::Log.new(opt) { | log | log.info("hoge") }
|
|
103
|
+
File::open(File.join(@log_dir , "name1.log")) {|f|
|
|
104
|
+
expect(f.read).to match /hoge/
|
|
105
|
+
}
|
|
174
106
|
end
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
it "is info level" do
|
|
187
|
-
opt = { :level => "info",:name => "a.log" }
|
|
188
|
-
RBatch::Log.new(opt) do | log |
|
|
189
|
-
log.debug("test_debug")
|
|
190
|
-
log.info("test_info")
|
|
191
|
-
log.warn("test_warn")
|
|
192
|
-
log.error("test_error")
|
|
193
|
-
log.fatal("test_fatal")
|
|
107
|
+
|
|
108
|
+
it "change log name 2" do
|
|
109
|
+
opt = {:name => "<prog><date>name.log" }
|
|
110
|
+
RBatch::Log.new(opt) { | log | log.info("hoge") }
|
|
111
|
+
|
|
112
|
+
File::open(File.join(@log_dir , "rspec" + Time.now.strftime("%Y%m%d") + "name.log")) {|f|
|
|
113
|
+
expect(f.read).to match /hoge/
|
|
114
|
+
}
|
|
194
115
|
end
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
it "is warn level" do
|
|
207
|
-
opt = { :level => "warn",:name => "a.log" }
|
|
208
|
-
RBatch::Log.new(opt) do | log |
|
|
209
|
-
log.debug("test_debug")
|
|
210
|
-
log.info("test_info")
|
|
211
|
-
log.warn("test_warn")
|
|
212
|
-
log.error("test_error")
|
|
213
|
-
log.fatal("test_fatal")
|
|
116
|
+
|
|
117
|
+
it "change log name 3" do
|
|
118
|
+
opt = {:name => "<prog>-<date>-name.log" }
|
|
119
|
+
RBatch::Log.new(opt) { | log | log.info("hoge") }
|
|
120
|
+
|
|
121
|
+
File::open(File.join(@log_dir , "rspec-" + Time.now.strftime("%Y%m%d") + "-name.log")) {|f|
|
|
122
|
+
expect(f.read).to match /hoge/
|
|
123
|
+
}
|
|
214
124
|
end
|
|
215
|
-
|
|
216
|
-
File::open(File.join(@log_dir , "a.log")) {|f|
|
|
217
|
-
str = f.read
|
|
218
|
-
expect(str).to_not match /test_debug/
|
|
219
|
-
expect(str).to_not match /test_info/
|
|
220
|
-
expect(str).to match /test_warn/
|
|
221
|
-
expect(str).to match /test_error/
|
|
222
|
-
expect(str).to match /test_fatal/
|
|
223
|
-
}
|
|
224
125
|
end
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
log
|
|
231
|
-
log.
|
|
232
|
-
|
|
233
|
-
|
|
126
|
+
|
|
127
|
+
describe ":dir option" do
|
|
128
|
+
it "change log dir" do
|
|
129
|
+
@tmp = File.join(ENV["RB_HOME"],"log3")
|
|
130
|
+
Dir.mkdir(@tmp)
|
|
131
|
+
opt = {:name => "c.log", :dir=> @tmp }
|
|
132
|
+
RBatch::Log.new(opt) { | log | log.info("hoge") }
|
|
133
|
+
|
|
134
|
+
File::open(File.join(@tmp , "c.log")) {|f|
|
|
135
|
+
expect(f.read).to match /hoge/
|
|
136
|
+
}
|
|
137
|
+
FileUtils.rm(File.join(@tmp , "c.log"))
|
|
138
|
+
Dir.rmdir(@tmp)
|
|
234
139
|
end
|
|
235
|
-
|
|
236
|
-
File::open(File.join(@log_dir , "a.log")) {|f|
|
|
237
|
-
str = f.read
|
|
238
|
-
expect(str).to_not match /test_debug/
|
|
239
|
-
expect(str).to_not match /test_info/
|
|
240
|
-
expect(str).to_not match /test_warn/
|
|
241
|
-
expect(str).to match /test_error/
|
|
242
|
-
expect(str).to match /test_fatal/
|
|
243
|
-
}
|
|
244
140
|
end
|
|
245
141
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
log.
|
|
250
|
-
|
|
251
|
-
log
|
|
252
|
-
log.
|
|
253
|
-
|
|
142
|
+
describe ":append option" do
|
|
143
|
+
it "is append mode" do
|
|
144
|
+
opt = {:append => true, :name => "a.log" }
|
|
145
|
+
RBatch::Log.new(opt) { | log | log.info("line1") }
|
|
146
|
+
|
|
147
|
+
opt = {:append => true, :name => "a.log" }
|
|
148
|
+
RBatch::Log.new(opt) { | log | log.info("line2") }
|
|
149
|
+
|
|
150
|
+
File::open(File.join(@log_dir , "a.log")) {|f|
|
|
151
|
+
str = f.read
|
|
152
|
+
expect(str).to match /line1/
|
|
153
|
+
expect(str).to match /line2/
|
|
154
|
+
}
|
|
254
155
|
end
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
RBatch::Log.new(opt) do | log |
|
|
269
|
-
log.debug("test_debug")
|
|
270
|
-
log.info("test_info")
|
|
271
|
-
log.warn("test_warn")
|
|
272
|
-
log.error("test_error")
|
|
273
|
-
log.fatal("test_fatal")
|
|
156
|
+
|
|
157
|
+
it "is overwrite mode" do
|
|
158
|
+
opt = {:append => false, :name => "a.log" }
|
|
159
|
+
RBatch::Log.new(opt) { | log | log.info("line1") }
|
|
160
|
+
|
|
161
|
+
opt = {:append => false, :name => "a.log" }
|
|
162
|
+
RBatch::Log.new(opt) { | log | log.info("line2") }
|
|
163
|
+
|
|
164
|
+
File::open(File.join(@log_dir , "a.log")) {|f|
|
|
165
|
+
str = f.read
|
|
166
|
+
expect(str).to_not match /line1/
|
|
167
|
+
expect(str).to match /line2/
|
|
168
|
+
}
|
|
274
169
|
end
|
|
275
|
-
|
|
276
|
-
File::open(File.join(@log_dir , "a.log")) {|f|
|
|
277
|
-
str = f.read
|
|
278
|
-
expect(str).to_not match /test_debug/
|
|
279
|
-
expect(str).to match /test_info/
|
|
280
|
-
expect(str).to match /test_warn/
|
|
281
|
-
expect(str).to match /test_error/
|
|
282
|
-
expect(str).to match /test_fatal/
|
|
283
|
-
}
|
|
284
170
|
end
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
171
|
+
describe ":level option" do
|
|
172
|
+
it "is debug level" do
|
|
173
|
+
opt = { :level => "debug",:name => "a.log" }
|
|
174
|
+
RBatch::Log.new(opt) do | log |
|
|
175
|
+
log.debug("test_debug")
|
|
176
|
+
log.info("test_info")
|
|
177
|
+
log.warn("test_warn")
|
|
178
|
+
log.error("test_error")
|
|
179
|
+
log.fatal("test_fatal")
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
File::open(File.join(@log_dir , "a.log")) {|f|
|
|
183
|
+
str = f.read
|
|
184
|
+
expect(str).to match /test_debug/
|
|
185
|
+
expect(str).to match /test_info/
|
|
186
|
+
expect(str).to match /test_warn/
|
|
187
|
+
expect(str).to match /test_error/
|
|
188
|
+
expect(str).to match /test_fatal/
|
|
189
|
+
}
|
|
289
190
|
end
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
191
|
+
|
|
192
|
+
it "is info level" do
|
|
193
|
+
opt = { :level => "info",:name => "a.log" }
|
|
194
|
+
RBatch::Log.new(opt) do | log |
|
|
195
|
+
log.debug("test_debug")
|
|
196
|
+
log.info("test_info")
|
|
197
|
+
log.warn("test_warn")
|
|
198
|
+
log.error("test_error")
|
|
199
|
+
log.fatal("test_fatal")
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
File::open(File.join(@log_dir , "a.log")) {|f|
|
|
203
|
+
str = f.read
|
|
204
|
+
expect(str).to_not match /test_debug/
|
|
205
|
+
expect(str).to match /test_info/
|
|
206
|
+
expect(str).to match /test_warn/
|
|
207
|
+
expect(str).to match /test_error/
|
|
208
|
+
expect(str).to match /test_fatal/
|
|
209
|
+
}
|
|
297
210
|
end
|
|
298
|
-
|
|
299
|
-
|
|
211
|
+
|
|
212
|
+
it "is warn level" do
|
|
213
|
+
opt = { :level => "warn",:name => "a.log" }
|
|
214
|
+
RBatch::Log.new(opt) do | log |
|
|
215
|
+
log.debug("test_debug")
|
|
216
|
+
log.info("test_info")
|
|
217
|
+
log.warn("test_warn")
|
|
218
|
+
log.error("test_error")
|
|
219
|
+
log.fatal("test_fatal")
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
File::open(File.join(@log_dir , "a.log")) {|f|
|
|
223
|
+
str = f.read
|
|
224
|
+
expect(str).to_not match /test_debug/
|
|
225
|
+
expect(str).to_not match /test_info/
|
|
226
|
+
expect(str).to match /test_warn/
|
|
227
|
+
expect(str).to match /test_error/
|
|
228
|
+
expect(str).to match /test_fatal/
|
|
229
|
+
}
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
it "is error level" do
|
|
233
|
+
opt = { :level => "error",:name => "a.log" }
|
|
234
|
+
RBatch::Log.new(opt) do | log |
|
|
235
|
+
log.debug("test_debug")
|
|
236
|
+
log.info("test_info")
|
|
237
|
+
log.warn("test_warn")
|
|
238
|
+
log.error("test_error")
|
|
239
|
+
log.fatal("test_fatal")
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
File::open(File.join(@log_dir , "a.log")) {|f|
|
|
243
|
+
str = f.read
|
|
244
|
+
expect(str).to_not match /test_debug/
|
|
245
|
+
expect(str).to_not match /test_info/
|
|
246
|
+
expect(str).to_not match /test_warn/
|
|
247
|
+
expect(str).to match /test_error/
|
|
248
|
+
expect(str).to match /test_fatal/
|
|
249
|
+
}
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
it "is fatal level" do
|
|
253
|
+
opt = { :level => "fatal",:name => "a.log" }
|
|
254
|
+
RBatch::Log.new(opt) 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
|
+
|
|
262
|
+
File::open(File.join(@log_dir , "a.log")) {|f|
|
|
263
|
+
str = f.read
|
|
264
|
+
expect(str).to_not match /test_debug/
|
|
265
|
+
expect(str).to_not match /test_info/
|
|
266
|
+
expect(str).to_not match /test_warn/
|
|
267
|
+
expect(str).to_not match /test_error/
|
|
268
|
+
expect(str).to match /test_fatal/
|
|
269
|
+
}
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
it "is default level" do
|
|
273
|
+
opt = {:name => "a.log" }
|
|
274
|
+
RBatch::Log.new(opt) do | log |
|
|
275
|
+
log.debug("test_debug")
|
|
276
|
+
log.info("test_info")
|
|
277
|
+
log.warn("test_warn")
|
|
278
|
+
log.error("test_error")
|
|
279
|
+
log.fatal("test_fatal")
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
File::open(File.join(@log_dir , "a.log")) {|f|
|
|
283
|
+
str = f.read
|
|
284
|
+
expect(str).to_not match /test_debug/
|
|
285
|
+
expect(str).to match /test_info/
|
|
286
|
+
expect(str).to match /test_warn/
|
|
287
|
+
expect(str).to match /test_error/
|
|
288
|
+
expect(str).to match /test_fatal/
|
|
289
|
+
}
|
|
300
290
|
end
|
|
301
291
|
end
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
292
|
+
describe ":delete_old_log option" do
|
|
293
|
+
it "delete old log which name include <date>" do
|
|
294
|
+
loglist = [*0..20].map do |day|
|
|
295
|
+
File.join(@log_dir , (Date.today - day).strftime("%Y%m%d") + "_test_delete.log")
|
|
296
|
+
end
|
|
297
|
+
FileUtils.touch(loglist)
|
|
298
|
+
|
|
299
|
+
opt = { :name => "<date>_test_delete.log",:delete_old_log => true}
|
|
300
|
+
RBatch::Log.new(opt) { | log | }
|
|
301
|
+
|
|
302
|
+
loglist[1..6].each do |filename|
|
|
303
|
+
expect(File.exists?(filename)).to be true
|
|
304
|
+
end
|
|
305
|
+
loglist[7..20].each do |filename|
|
|
306
|
+
expect(File.exists?(filename)).to be false
|
|
307
|
+
end
|
|
306
308
|
end
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
309
|
+
|
|
310
|
+
it "delete old log which name include <date> even if <date> position is changed" do
|
|
311
|
+
loglist = [*0..20].map do |day|
|
|
312
|
+
File.join(@log_dir , "235959-" + (Date.today - day).strftime("%Y%m%d") + "_test_delete.log")
|
|
313
|
+
end
|
|
314
|
+
FileUtils.touch(loglist)
|
|
315
|
+
|
|
316
|
+
opt = { :name => "<time>-<date>_test_delete.log",:delete_old_log => true}
|
|
317
|
+
RBatch::Log.new(opt) { | log | }
|
|
318
|
+
|
|
319
|
+
loglist[1..6].each do |filename|
|
|
320
|
+
expect(File.exists?(filename)).to be true
|
|
321
|
+
end
|
|
322
|
+
loglist[7..20].each do |filename|
|
|
323
|
+
expect(File.exists?(filename)).to be false
|
|
324
|
+
end
|
|
314
325
|
end
|
|
315
|
-
|
|
316
|
-
|
|
326
|
+
|
|
327
|
+
it "does not delete old log which name does not include <date>" do
|
|
328
|
+
opt = { :name => "test_delete.log",:delete_old_log => true}
|
|
329
|
+
RBatch::Log.new(opt) { | log | }
|
|
330
|
+
|
|
331
|
+
expect(File.exists?(File.join(@log_dir,"test_delete.log"))).to be true
|
|
317
332
|
end
|
|
318
333
|
end
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
334
|
+
|
|
335
|
+
describe ":bufferd option" do
|
|
336
|
+
it "works bufferd is true" do
|
|
337
|
+
opt = { :name => "test_buffer.log",:bufferd => true}
|
|
338
|
+
RBatch::Log.new(opt) { | log | log.info("hoge") }
|
|
339
|
+
File::open(File.join(@log_dir , "test_buffer.log")) {|f|
|
|
340
|
+
expect(f.read).to match /hoge/
|
|
341
|
+
}
|
|
342
|
+
end
|
|
343
|
+
it "works bufferd is false" do
|
|
344
|
+
opt = { :name => "test_buffer2.log",:bufferd => false}
|
|
345
|
+
RBatch::Log.new(opt) { | log | log.info("hoge") }
|
|
346
|
+
File::open(File.join(@log_dir , "test_buffer2.log")) {|f|
|
|
347
|
+
expect(f.read).to match /hoge/
|
|
348
|
+
}
|
|
349
|
+
end
|
|
325
350
|
end
|
|
326
351
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
352
|
+
describe ":output_exit_status option" do
|
|
353
|
+
describe "option is true" do
|
|
354
|
+
it "output FATAL error when exit status is 1" do
|
|
355
|
+
opt = { :name => "test_output_system_exit.log",:output_exit_status => true}
|
|
356
|
+
expect{RBatch::Log.new(opt) { | log | exit 1 }}.to raise_error(SystemExit)
|
|
357
|
+
File::open(File.join(@log_dir , "test_output_system_exit.log")) {|f|
|
|
358
|
+
expect(f.read).to match /.FATAL. RBatch catch SystemExit. Exit with status 1/
|
|
359
|
+
}
|
|
360
|
+
end
|
|
361
|
+
it "output nothing when exit status is 0" do
|
|
362
|
+
opt = { :name => "test_output_system_exit2.log",:output_exit_status => true}
|
|
363
|
+
expect{RBatch::Log.new(opt) { | log | exit 0 }}.to raise_error(SystemExit)
|
|
364
|
+
File::open(File.join(@log_dir , "test_output_system_exit2.log")) {|f|
|
|
365
|
+
expect(f.read).not_to match /.INFO. RBatch catch SystemExit. Exit with status 0/
|
|
366
|
+
}
|
|
367
|
+
end
|
|
368
|
+
end
|
|
369
|
+
describe "option is false" do
|
|
370
|
+
it "output nothing when exit status is not 1" do
|
|
371
|
+
opt = { :name => "test_output_system_exit3.log",:output_exit_status => false}
|
|
372
|
+
expect{RBatch::Log.new(opt) { | log | exit 1 }}.to raise_error(SystemExit)
|
|
373
|
+
File::open(File.join(@log_dir , "test_output_system_exit3.log")) {|f|
|
|
374
|
+
expect(f.read).not_to match /RBatch catch SystemExit/
|
|
375
|
+
}
|
|
376
|
+
end
|
|
377
|
+
it "output nothing when exit status is 0" do
|
|
378
|
+
opt = { :name => "test_output_system_exit4.log",:output_exit_status => false}
|
|
379
|
+
expect{RBatch::Log.new(opt) { | log | exit 0 }}.to raise_error(SystemExit)
|
|
380
|
+
File::open(File.join(@log_dir , "test_output_system_exit4.log")) {|f|
|
|
381
|
+
expect(f.read).not_to match /RBatch catch SystemExit/
|
|
382
|
+
}
|
|
383
|
+
end
|
|
384
|
+
end
|
|
340
385
|
end
|
|
341
|
-
|
|
342
|
-
|
|
343
386
|
end
|
|
344
387
|
|
|
345
388
|
describe "option by run_conf" do
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
389
|
+
describe "log_name option" do
|
|
390
|
+
it "change log name" do
|
|
391
|
+
@def_vars.merge!({:log_name => "name1.log"})
|
|
392
|
+
RBatch::Log.def_vars = @def_vars
|
|
393
|
+
RBatch::Log.new { | log | log.info("hoge") }
|
|
394
|
+
|
|
395
|
+
File::open(File.join(@log_dir , "name1.log")) {|f|
|
|
396
|
+
expect(f.read).to match /hoge/
|
|
397
|
+
}
|
|
398
|
+
end
|
|
354
399
|
end
|
|
355
400
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
401
|
+
describe "log_dir option" do
|
|
402
|
+
it "change log dir" do
|
|
403
|
+
@tmp = File.join(ENV["RB_HOME"],"log2")
|
|
404
|
+
Dir.mkdir(@tmp)
|
|
405
|
+
@def_vars.merge!({:log_dir => @tmp})
|
|
406
|
+
RBatch::Log.def_vars = @def_vars
|
|
407
|
+
|
|
408
|
+
opt = {:name => "c.log" }
|
|
409
|
+
RBatch::Log.new(opt) { | log | log.info("hoge") }
|
|
410
|
+
|
|
411
|
+
File::open(File.join(@tmp , "c.log")) {|f|
|
|
412
|
+
expect(f.read).to match /hoge/
|
|
413
|
+
}
|
|
414
|
+
FileUtils.rm(File.join(@tmp , "c.log"))
|
|
415
|
+
Dir.rmdir(@tmp)
|
|
416
|
+
end
|
|
370
417
|
end
|
|
371
418
|
end
|
|
419
|
+
|
|
372
420
|
describe "option both run_conf and opt" do
|
|
373
421
|
it "change log name" do
|
|
374
422
|
@def_vars.merge!({:log_name => "name1.log"})
|
metadata
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: rbatch
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease:
|
|
5
|
-
version: 2.
|
|
5
|
+
version: 2.4.0
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
8
8
|
- fetaro
|
|
@@ -10,7 +10,7 @@ autorequire:
|
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
12
|
|
|
13
|
-
date:
|
|
13
|
+
date: 2015-06-08 00:00:00 Z
|
|
14
14
|
dependencies: []
|
|
15
15
|
|
|
16
16
|
description: Batch Script Framework
|