8
8
9
9
import inspect
10
10
import logging
11
+ import logging .handlers
11
12
import optparse
12
13
import os
13
14
@@ -53,12 +54,20 @@ def main():
53
54
parser .disable_interspersed_args () # stop when we hit an option without an '-'
54
55
options , args = parser .parse_args ()
55
56
56
- # Set up logging to a file and to the console
57
- logging .basicConfig (
58
- filename = os .path .expandvars (os .path .join ('$WORKON_HOME' , 'hook.log' )),
59
- level = logging .DEBUG ,
60
- format = '%(asctime)s %(levelname)s %(name)s %(message)s' ,
57
+ root_logger = logging .getLogger ('' )
58
+
59
+ # Set up logging to a file
60
+ root_logger .setLevel (logging .DEBUG )
61
+ file_handler = logging .handlers .RotatingFileHandler (
62
+ os .path .expandvars (os .path .join ('$WORKON_HOME' , 'hook.log' )),
63
+ maxBytes = 10240 ,
64
+ backupCount = 1 ,
61
65
)
66
+ formatter = logging .Formatter ('%(asctime)s %(levelname)s %(name)s %(message)s' )
67
+ file_handler .setFormatter (formatter )
68
+ root_logger .addHandler (file_handler )
69
+
70
+ # Send higher-level messages to the console, too
62
71
console = logging .StreamHandler ()
63
72
console_level = [ logging .WARNING ,
64
73
logging .INFO ,
@@ -67,7 +76,7 @@ def main():
67
76
console .setLevel (console_level )
68
77
formatter = logging .Formatter ('%(name)s %(message)s' )
69
78
console .setFormatter (formatter )
70
- logging . getLogger ( '' ) .addHandler (console )
79
+ root_logger .addHandler (console )
71
80
72
81
#logging.getLogger(__name__).debug('cli args %s', args)
73
82
0 commit comments