mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2024-11-22 08:46:39 -06:00
Enhance logging by tracking stdout and stderr of subprocess when log level set to DEBUG.
If the process terminates abnormally then the error is not logged which makes it very difficult to find the reason for failure. Fixes #5176
This commit is contained in:
parent
2ae279a382
commit
019932c323
@ -14,6 +14,7 @@ New features
|
||||
Housekeeping
|
||||
************
|
||||
|
||||
| `Issue #5176 <https://redmine.postgresql.org/issues/5176>`_ - Enhance logging by tracking stdout and stderr of subprocess when log level set to DEBUG.
|
||||
|
||||
Bug fixes
|
||||
*********
|
||||
|
@ -18,7 +18,8 @@ import psutil
|
||||
from abc import ABCMeta, abstractproperty, abstractmethod
|
||||
from datetime import datetime
|
||||
from pickle import dumps, loads
|
||||
from subprocess import Popen
|
||||
from subprocess import Popen, PIPE
|
||||
import logging
|
||||
|
||||
from pgadmin.utils import IS_PY2, u, file_quote, fs_encoding, \
|
||||
get_complete_file_path
|
||||
@ -382,6 +383,24 @@ class BatchProcess(object):
|
||||
# Explicitly ignoring signals in the child process
|
||||
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
||||
|
||||
# if in debug mode, wait for process to complete and
|
||||
# get the stdout and stderr of popen.
|
||||
if config.CONSOLE_LOG_LEVEL <= logging.DEBUG:
|
||||
p = Popen(
|
||||
cmd, close_fds=True, stdout=PIPE, stderr=PIPE, stdin=None,
|
||||
preexec_fn=preexec_function, env=env
|
||||
)
|
||||
|
||||
output, errors = p.communicate()
|
||||
output = output.decode() \
|
||||
if hasattr(output, 'decode') else output
|
||||
errors = errors.decode() \
|
||||
if hasattr(errors, 'decode') else errors
|
||||
current_app.logger.debug(
|
||||
'Process Watcher Out:{0}'.format(output))
|
||||
current_app.logger.debug(
|
||||
'Process Watcher Err:{0}'.format(errors))
|
||||
else:
|
||||
p = Popen(
|
||||
cmd, close_fds=True, stdout=None, stderr=None, stdin=None,
|
||||
preexec_fn=preexec_function, env=env
|
||||
|
Loading…
Reference in New Issue
Block a user