simple_rotate 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/simple_rotate.rb +1 -1
- data/lib/simple_rotate/simple_rotate.rb +30 -4
- metadata +4 -4
data/lib/simple_rotate.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
class SimpleRotate
|
2
|
-
|
3
|
-
def initialize(log_file=$0+".log", max_size=
|
2
|
+
public
|
3
|
+
def initialize(log_file=$0+".log", max_size='1M', rotate=true, log_format=".", log_mess=true)
|
4
4
|
@log_file = log_file
|
5
|
-
@max_size = max_size
|
5
|
+
@max_size = trim_byte(max_size)
|
6
6
|
@log_format = log_format
|
7
7
|
@rotate = rotate
|
8
8
|
@log_mess = log_mess
|
@@ -22,6 +22,7 @@ class SimpleRotate
|
|
22
22
|
w("\n----- Start Logs [Date: #{get_time('milestone')}] [PID: #{$$}] -----\n") if @log_mess
|
23
23
|
end
|
24
24
|
|
25
|
+
private
|
25
26
|
def over_size(f)
|
26
27
|
if File.size(f) > @max_size
|
27
28
|
return true
|
@@ -30,6 +31,7 @@ class SimpleRotate
|
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
34
|
+
private
|
33
35
|
def ch_name(f)
|
34
36
|
cnt = 1
|
35
37
|
rename_f = "#{@log_file}#{@log_format}#{cnt}"
|
@@ -60,6 +62,7 @@ class SimpleRotate
|
|
60
62
|
end
|
61
63
|
end
|
62
64
|
|
65
|
+
private
|
63
66
|
def get_time(request)
|
64
67
|
if request == "party"
|
65
68
|
return Time.now.strftime("[%Y/%m/%d %H:%M:%S] ")
|
@@ -68,6 +71,28 @@ class SimpleRotate
|
|
68
71
|
end
|
69
72
|
end
|
70
73
|
|
74
|
+
private
|
75
|
+
def trim_byte(max_size)
|
76
|
+
kiro = "000"
|
77
|
+
mega = kiro + "000"
|
78
|
+
giga = mega + "000"
|
79
|
+
tera = giga + "000"
|
80
|
+
max_size = max_size.to_s
|
81
|
+
|
82
|
+
if /K$/ =~ max_size
|
83
|
+
max_size = max_size.sub(/K$/, "") + kiro
|
84
|
+
elsif /M$/ =~ max_size
|
85
|
+
max_size = max_size.sub(/M$/, "") + mega
|
86
|
+
elsif /G$/ =~ max_size
|
87
|
+
max_size = max_size.sub(/G$/, "") + giga
|
88
|
+
elsif /T$/ =~ max_size
|
89
|
+
max_size = max_size.sub(/T$/, "") + tera
|
90
|
+
end
|
91
|
+
|
92
|
+
return max_size.to_i
|
93
|
+
end
|
94
|
+
|
95
|
+
public
|
71
96
|
def flush
|
72
97
|
e
|
73
98
|
ch_name(@log_file)
|
@@ -76,6 +101,7 @@ class SimpleRotate
|
|
76
101
|
w("\n----- Start Logs [Date: #{get_time('milestone')}] [PID: #{$$}] -----\n") if @log_mess
|
77
102
|
end
|
78
103
|
|
104
|
+
public
|
79
105
|
def w(str, output=false, rec_time=false)
|
80
106
|
if rec_time
|
81
107
|
@logf.puts(get_time('party')+str)
|
@@ -86,9 +112,9 @@ class SimpleRotate
|
|
86
112
|
end
|
87
113
|
end
|
88
114
|
|
115
|
+
public
|
89
116
|
def e
|
90
117
|
w("----- End Logs [Date: #{get_time('milestone')}] [PID: #{$$}] -----\n") if @log_mess
|
91
118
|
@logf.close
|
92
119
|
end
|
93
|
-
|
94
120
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_rotate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- nyanko
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2013-02-26 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: hoe
|