Skip to content

Commit a60920e

Browse files
committed
enhance verbose output of hook loader
Fix the logging configuration so the console output actually appears. Move the console log output to stderr. Clean up some of the indivual log messages. Change-Id: I55d1bda61eca7435c3cc776cade8920412f31e03
1 parent 343667c commit a60920e

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

virtualenvwrapper/hook_loader.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def main():
8282
parser.disable_interspersed_args() # stop when on option without an '-'
8383
options, args = parser.parse_args()
8484

85-
root_logger = logging.getLogger('')
85+
root_logger = logging.getLogger('virtualenvwrapper')
8686

8787
# Set up logging to a file
8888
logfile = os.environ.get('VIRTUALENVWRAPPER_LOG_FILE')
@@ -98,7 +98,7 @@ def main():
9898
root_logger.addHandler(file_handler)
9999

100100
# Send higher-level messages to the console, too
101-
console = logging.StreamHandler()
101+
console = logging.StreamHandler(stream=sys.stderr)
102102
console_level = [logging.WARNING,
103103
logging.INFO,
104104
logging.DEBUG,
@@ -107,6 +107,7 @@ def main():
107107
formatter = logging.Formatter('%(name)s %(message)s')
108108
console.setFormatter(formatter)
109109
root_logger.addHandler(console)
110+
root_logger.setLevel(console_level)
110111

111112
# logging.getLogger(__name__).debug('cli args %s', args)
112113

@@ -125,7 +126,7 @@ def main():
125126
if options.sourcing:
126127
hook += '_source'
127128

128-
log = logging.getLogger(__name__)
129+
log = logging.getLogger('virtualenvwrapper.hook_loader')
129130

130131
log.debug('Running %s hooks', hook)
131132
run_hooks(hook, options, args)
@@ -147,13 +148,16 @@ def main():
147148

148149

149150
def run_hooks(hook, options, args, output=None):
151+
log = logging.getLogger('virtualenvwrapper.hook_loader')
150152
if output is None:
151153
output = sys.stdout
152154

153155
namespace = 'virtualenvwrapper.%s' % hook
154156
if options.names:
157+
log.debug('looking for %s hooks %s' % (namespace, options.names))
155158
hook_mgr = NamedExtensionManager(namespace, options.names)
156159
else:
160+
log.debug('looking for %s hooks' % namespace)
157161
hook_mgr = ExtensionManager(namespace)
158162

159163
if options.listing:
@@ -169,6 +173,7 @@ def show(ext):
169173
def get_source(ext, args):
170174
# Show the shell commands so they can
171175
# be run in the calling shell.
176+
log.debug('getting source instructions for %s' % ext.name)
172177
contents = (ext.plugin(args) or '').strip()
173178
if contents:
174179
output.write('# %s\n' % ext.name)
@@ -182,6 +187,7 @@ def get_source(ext, args):
182187
else:
183188
# Just run the plugin ourselves
184189
def invoke(ext, args):
190+
log.debug('running %s' % ext.name)
185191
ext.plugin(args)
186192
try:
187193
hook_mgr.map(invoke, args[1:])

virtualenvwrapper/user_scripts.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ def pre_mkvirtualenv(args):
217217

218218

219219
def post_mkvirtualenv_source(args):
220+
log.debug('post_mkvirtualenv_source %s', str(args))
220221
return """
221222
#
222223
# Run user-provided scripts
@@ -237,6 +238,7 @@ def pre_cpvirtualenv(args):
237238

238239

239240
def post_cpvirtualenv_source(args):
241+
log.debug('post_cpvirtualenv_source %s', str(args))
240242
return """
241243
#
242244
# Run user-provided scripts
@@ -268,7 +270,7 @@ def pre_activate(args):
268270

269271

270272
def post_activate_source(args):
271-
log.debug('post_activate')
273+
log.debug('post_activate_source')
272274
return """
273275
#
274276
# Run user-provided scripts
@@ -281,7 +283,7 @@ def post_activate_source(args):
281283

282284

283285
def pre_deactivate_source(args):
284-
log.debug('pre_deactivate')
286+
log.debug('pre_deactivate_source')
285287
return """
286288
#
287289
# Run user-provided scripts
@@ -294,7 +296,7 @@ def pre_deactivate_source(args):
294296

295297

296298
def post_deactivate_source(args):
297-
log.debug('post_deactivate')
299+
log.debug('post_deactivate_source')
298300
return """
299301
#
300302
# Run user-provided scripts

0 commit comments

Comments
 (0)