Commit cce06aeb authored by Boris Kocherov's avatar Boris Kocherov

improve logging

parent a5157949
...@@ -58,6 +58,8 @@ class Application(object): ...@@ -58,6 +58,8 @@ class Application(object):
finally: finally:
if pid_exists(process_pid) or self.status(): if pid_exists(process_pid) or self.status():
Process(process_pid).kill() Process(process_pid).kill()
logger.debug("Process " + str(process_pid) + " killed with returncode " + str(self.process.returncode))
logger.debug("Process " + str(process_pid) + " terminated with returncode " + str(self.process.returncode))
delattr(self, "process") delattr(self, "process")
def loadSettings(self, hostname, port, path_run_dir, **kwargs): def loadSettings(self, hostname, port, path_run_dir, **kwargs):
......
...@@ -119,11 +119,18 @@ class Handler(object): ...@@ -119,11 +119,18 @@ class Handler(object):
self._startTimeout() self._startTimeout()
process = Popen(command_list, stdout=PIPE, stderr=PIPE, close_fds=True, process = Popen(command_list, stdout=PIPE, stderr=PIPE, close_fds=True,
env=openoffice.environment_dict.copy()) env=openoffice.environment_dict.copy())
logger.debug("Process " + str(process.pid) + " runned")
stdout, stderr = process.communicate() stdout, stderr = process.communicate()
finally: finally:
self._stopTimeout() self._stopTimeout()
if pid_exists(process.pid): if pid_exists(process.pid):
logger.debug("Process " + str(process.pid) + " terminated")
process.terminate() process.terminate()
if (process.returncode < 0 and process.returncode != -6) or stderr:
logger.error("Process " + str(process.pid) + " command:" + " ".join(command_list))
logger.error("Process " + str(process.pid) + " stdout:" + stdout)
logger.error("Process " + str(process.pid) + " stderr:" + stderr)
logger.debug("Process " + str(process.pid) + " terminated with returncode " + str(process.returncode))
return stdout, stderr return stdout, stderr
def _callUnoConverter(self, *feature_list, **kw): def _callUnoConverter(self, *feature_list, **kw):
...@@ -131,7 +138,9 @@ class Handler(object): ...@@ -131,7 +138,9 @@ class Handler(object):
if not openoffice.status(): if not openoffice.status():
openoffice.start() openoffice.start()
command_list = self._getCommand(*feature_list, **kw) command_list = self._getCommand(*feature_list, **kw)
logger.debug("run convert first")
stdout, stderr = self._subprocess(command_list) stdout, stderr = self._subprocess(command_list)
logger.debug("stop convert first")
if not stdout and stderr: if not stdout and stderr:
first_error = stderr first_error = stderr
logger.error(stderr) logger.error(stderr)
...@@ -139,10 +148,11 @@ class Handler(object): ...@@ -139,10 +148,11 @@ class Handler(object):
openoffice.restart() openoffice.restart()
kw['document_url'] = self.document.getUrl() kw['document_url'] = self.document.getUrl()
command = self._getCommand(*feature_list, **kw) command = self._getCommand(*feature_list, **kw)
logger.debug("run convert second")
stdout, stderr = self._subprocess(command) stdout, stderr = self._subprocess(command)
logger.debug("stop convert second")
if not stdout and stderr: if not stdout and stderr:
second_error = "\nerror of the second run: " + stderr second_error = "\nerror of the second run: " + stderr
logger.error(second_error)
raise Exception(first_error + second_error) raise Exception(first_error + second_error)
return stdout, stderr return stdout, stderr
......
...@@ -33,6 +33,7 @@ from subprocess import STDOUT ...@@ -33,6 +33,7 @@ from subprocess import STDOUT
from zope.interface import implements from zope.interface import implements
from filter import Filter from filter import Filter
from os import environ, path from os import environ, path
from cloudooo.util import logger
from cloudooo.interfaces.mimemapper import IMimemapper from cloudooo.interfaces.mimemapper import IMimemapper
from types import InstanceType from types import InstanceType
import json import json
...@@ -124,8 +125,10 @@ class MimeMapper(object): ...@@ -124,8 +125,10 @@ class MimeMapper(object):
"--hostname=%s" % hostname, "--hostname=%s" % hostname,
"--port=%s" % port] "--port=%s" % port]
process = Popen(command, stdout=PIPE, stderr=STDOUT, close_fds=True) process = Popen(command, stdout=PIPE, stderr=PIPE, close_fds=True)
stdout, stderr = process.communicate() stdout, stderr = process.communicate()
if stderr:
logger.error(stderr)
if process.returncode: if process.returncode:
raise ValueError(stdout) raise ValueError(stdout)
filter_dict, type_dict = json.loads(stdout) filter_dict, type_dict = json.loads(stdout)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment