13
13
from optparse import OptionParser
14
14
from collections import defaultdict
15
15
from socket import error as SocketError
16
- from re import compile as compile_regex
16
+ from time import localtime , strftime , time
17
17
from datetime import date , datetime , timedelta
18
18
from os import environ , getcwd , makedirs , path
19
- from time import asctime , localtime , strftime , time
20
19
21
20
22
21
import circuits
42
41
USAGE = "%prog [options] <host> [<port>]"
43
42
VERSION = "%prog v" + __version__
44
43
45
- LOGFILE_REGEX = compile_regex ( "^(.*)\.(.*)\.log$" )
44
+
46
45
PIDFILE = path .join (path .dirname (__file__ ), "{0:s}.pid" .format (__name__ ))
47
46
48
47
@@ -100,21 +99,12 @@ def parse_options():
100
99
return opts , args
101
100
102
101
103
- def timestamp ():
104
- return asctime (localtime (time ()))
105
-
106
-
107
102
def generate_logfile (channel ):
108
103
return path .join (channel , "{0:s}.log" .format (
109
104
strftime ("%Y-%m-%d" , localtime ()))
110
105
)
111
106
112
107
113
- def parse_logfile (filename ):
114
- match = LOGFILE_REGEX .match (filename )
115
- return match .groups () if match is not None else "" , ""
116
-
117
-
118
108
class log (Event ):
119
109
"""log Event"""
120
110
@@ -134,9 +124,7 @@ def init(self, *args, **kwargs):
134
124
Timer (interval , rotate (), self .channel ).register (self )
135
125
136
126
def rotate (self ):
137
- dirname = path .dirname (self .filename )
138
- filename = path .basename (self .filename )
139
- channel , _ = parse_logfile (filename )
127
+ channel = dirname = path .dirname (self .filename )
140
128
logfile = generate_logfile (channel )
141
129
self .fire (close (), self .channel )
142
130
self .fire (open (path .join (dirname , logfile ), "a" ), self .channel )
0 commit comments