File tree Expand file tree Collapse file tree 7 files changed +27
-41
lines changed
Expand file tree Collapse file tree 7 files changed +27
-41
lines changed Original file line number Diff line number Diff line change 88 mode. (:bbuser: `upsuper `)
99 - Add ``--help `` option to ``mkproject ``.
1010 - Add ``--help `` option to ``workon ``.
11+ - Turn off logging from the hook loader by default, and replace
12+ ``VIRTUALENVWRAPPER_LOG_DIR `` environment variable with
13+ ``VIRTUALENVWRAPPER_LOG_FILE ``. The rotating log behavior remains
14+ the same. The motivation for this change is the race condition
15+ caused by that rotating behavior, especially when the wrappers are
16+ being used by users with different permissions and
17+ umasks. (:bbissue: `152 `)
1118
12193.6.1
1320
Original file line number Diff line number Diff line change @@ -220,14 +220,14 @@ default is ``$WORKON_HOME``.
220220
221221 * :ref: `scripts `
222222
223- .. _variable-VIRTUALENVWRAPPER_LOG_DIR :
223+ .. _variable-VIRTUALENVWRAPPER_LOG_FILE :
224224
225225Location of Hook Logs
226226---------------------
227227
228- The variable ``VIRTUALENVWRAPPER_LOG_DIR `` tells virtualenvwrapper
228+ The variable ``VIRTUALENVWRAPPER_LOG_FILE `` tells virtualenvwrapper
229229where the logs for the hook loader should be written. The default is
230- `` $WORKON_HOME `` .
230+ to not log from the hooks .
231231
232232.. _variable-VIRTUALENVWRAPPER_VIRTUALENV :
233233
Original file line number Diff line number Diff line change @@ -26,7 +26,6 @@ test_virtualenvwrapper_initialize() {
2626 assertTrue " Global $WORKON_HOME /$hook was not created" " [ -f $WORKON_HOME /$hook ]"
2727 assertTrue " Global $WORKON_HOME /$hook is not executable" " [ -x $WORKON_HOME /$hook ]"
2828 done
29- assertTrue " Log file was not created" " [ -f $WORKON_HOME /hook.log ]"
3029 export pre_test_dir=$( cd " $test_dir " ; pwd)
3130 echo " echo GLOBAL initialize >> \" $pre_test_dir /catch_output\" " >> " $WORKON_HOME /initialize"
3231 virtualenvwrapper_initialize
Original file line number Diff line number Diff line change @@ -8,27 +8,25 @@ setUp () {
88}
99
1010test_set_by_user () {
11- export VIRTUALENVWRAPPER_LOG_DIR=" $WORKON_HOME /logs"
12- mkdir -p " $VIRTUALENVWRAPPER_LOG_DIR "
11+ export VIRTUALENVWRAPPER_LOG_FILE=" $WORKON_HOME /hooks.log"
1312 source " $test_dir /../virtualenvwrapper.sh"
14- assertTrue " Log file was not created" " [ -f $WORKON_HOME /logs/hook.log ]"
13+ assertTrue " Log file was not created" " [ -f $VIRTUALENVWRAPPER_LOG_FILE ]"
1514}
1615
1716test_file_permissions () {
18- export VIRTUALENVWRAPPER_LOG_DIR=" $WORKON_HOME /logs"
19- mkdir -p " $VIRTUALENVWRAPPER_LOG_DIR "
17+ export VIRTUALENVWRAPPER_LOG_FILE=" $WORKON_HOME /hooks.log"
2018 source " $test_dir /../virtualenvwrapper.sh"
21- perms=$( ls -l " $WORKON_HOME /logs/hook.log " | cut -f1 -d' ' )
19+ perms=$( ls -l " $VIRTUALENVWRAPPER_LOG_FILE " | cut -f1 -d' ' )
2220 # echo $perms
2321 assertTrue " Log file permissions are wrong: $perms " " echo $perms | grep '^-rw-rw'"
2422}
2523
2624test_not_set_by_user () {
2725 unset WORKON_HOME
28- unset VIRTUALENVWRAPPER_LOG_DIR
26+ unset VIRTUALENVWRAPPER_LOG_FILE
2927 unset VIRTUALENVWRAPPER_HOOK_DIR
3028 source " $test_dir /../virtualenvwrapper.sh"
31- assertSame " $WORKON_HOME " " $VIRTUALENVWRAPPER_LOG_DIR "
29+ assertSame " " " $VIRTUALENVWRAPPER_LOG_FILE "
3230}
3331
3432. " $test_dir /shunit2"
Original file line number Diff line number Diff line change @@ -64,11 +64,4 @@ test_virtualenvwrapper_run_hook_permissions() {
6464 assertSame " Errno 13] Permission denied" " $error "
6565}
6666
67- test_virtualenvwrapper_run_hook_without_log_dir () {
68- old_log_dir=" $VIRTUALENVWRAPPER_LOG_DIR "
69- unset VIRTUALENVWRAPPER_LOG_DIR
70- assertFalse " virtualenvwrapper_run_hook initialize"
71- export VIRTUALENVWRAPPER_LOG_DIR=" $old_log_dir "
72- }
73-
7467. " $test_dir /shunit2"
Original file line number Diff line number Diff line change @@ -202,12 +202,6 @@ function virtualenvwrapper_run_hook {
202202
203203 hook_script=" $( virtualenvwrapper_tempfile ${1} -hook) " || return 1
204204
205- if [ -z " $VIRTUALENVWRAPPER_LOG_DIR " ]
206- then
207- echo " ERROR: VIRTUALENVWRAPPER_LOG_DIR is not set." 1>&2
208- command \r m -f " $hook_script "
209- return 1
210- fi
211205 " $VIRTUALENVWRAPPER_PYTHON " -c ' from virtualenvwrapper.hook_loader import main; main()' $HOOK_VERBOSE_OPTION --script " $hook_script " " $@ "
212206 result=$?
213207
@@ -286,12 +280,6 @@ function virtualenvwrapper_initialize {
286280 export VIRTUALENVWRAPPER_HOOK_DIR=" $WORKON_HOME "
287281 fi
288282
289- # Set the location of the hook script logs
290- if [ " $VIRTUALENVWRAPPER_LOG_DIR " = " " ]
291- then
292- export VIRTUALENVWRAPPER_LOG_DIR=" $WORKON_HOME "
293- fi
294-
295283 virtualenvwrapper_run_hook " initialize"
296284
297285 virtualenvwrapper_setup_tab_completion
Original file line number Diff line number Diff line change @@ -85,16 +85,17 @@ def main():
8585 root_logger = logging .getLogger ('' )
8686
8787 # Set up logging to a file
88- root_logger .setLevel (logging .DEBUG )
89- file_handler = GroupWriteRotatingFileHandler (
90- os .path .expandvars (os .path .join ('$VIRTUALENVWRAPPER_LOG_DIR' ,
91- 'hook.log' )),
92- maxBytes = 10240 ,
93- backupCount = 1 ,
94- )
95- formatter = logging .Formatter (LOG_FORMAT )
96- file_handler .setFormatter (formatter )
97- root_logger .addHandler (file_handler )
88+ logfile = os .environ .get ('VIRTUALENVWRAPPER_LOG_FILE' )
89+ if logfile :
90+ root_logger .setLevel (logging .DEBUG )
91+ file_handler = GroupWriteRotatingFileHandler (
92+ logfile ,
93+ maxBytes = 10240 ,
94+ backupCount = 1 ,
95+ )
96+ formatter = logging .Formatter (LOG_FORMAT )
97+ file_handler .setFormatter (formatter )
98+ root_logger .addHandler (file_handler )
9899
99100 # Send higher-level messages to the console, too
100101 console = logging .StreamHandler ()
You can’t perform that action at this time.
0 commit comments