Commit 8fb1bb0b authored by Guillaume Seguin's avatar Guillaume Seguin

Improve printcore logging

parent 22fa509f
...@@ -22,7 +22,6 @@ from select import error as SelectError ...@@ -22,7 +22,6 @@ from select import error as SelectError
from threading import Thread, Lock from threading import Thread, Lock
from Queue import Queue, Empty as QueueEmpty from Queue import Queue, Empty as QueueEmpty
import time import time
import sys
import platform import platform
import os import os
import traceback import traceback
...@@ -170,7 +169,7 @@ class printcore(): ...@@ -170,7 +169,7 @@ class printcore():
self.printer = None self.printer = None
self.printer_tcp = None self.printer_tcp = None
logging.error(_("Socket error %s:") % e.errno,) logging.error(_("Socket error %s:") % e.errno,)
print e.strerror logging.error(e.strerror)
return return
else: else:
disable_hup(self.port) disable_hup(self.port)
...@@ -211,7 +210,7 @@ class printcore(): ...@@ -211,7 +210,7 @@ class printcore():
if self.recvcb: if self.recvcb:
try: self.recvcb(line) try: self.recvcb(line)
except: pass except: pass
if self.loud: print "RECV:", line.rstrip() if self.loud: logging.info("RECV: %s" % line.rstrip())
return line return line
except SelectError as e: except SelectError as e:
if 'Bad file descriptor' in e.args[1]: if 'Bad file descriptor' in e.args[1]:
...@@ -435,7 +434,7 @@ class printcore(): ...@@ -435,7 +434,7 @@ class printcore():
else: else:
self.priqueue.put_nowait(command) self.priqueue.put_nowait(command)
else: else:
print "Not connected to printer." logging.error(_("Not connected to printer."))
def send_now(self, command, wait = 0): def send_now(self, command, wait = 0):
"""Sends a command to the printer ahead of the command queue, without a """Sends a command to the printer ahead of the command queue, without a
...@@ -443,7 +442,7 @@ class printcore(): ...@@ -443,7 +442,7 @@ class printcore():
if self.online: if self.online:
self.priqueue.put_nowait(command) self.priqueue.put_nowait(command)
else: else:
print "Not connected to printer." logging.error(_("Not connected to printer."))
def _print(self, resuming = False): def _print(self, resuming = False):
self._stop_sender() self._stop_sender()
...@@ -452,8 +451,8 @@ class printcore(): ...@@ -452,8 +451,8 @@ class printcore():
#callback for printing started #callback for printing started
try: self.startcb(resuming) try: self.startcb(resuming)
except: except:
print "Print start callback failed with:" logging.error(_("Print start callback failed with:") +
traceback.print_exc(file = sys.stdout) "\n" + traceback.format_exc())
while self.printing and self.printer and self.online: while self.printing and self.printer and self.online:
self._sendnext() self._sendnext()
self.sentlines = {} self.sentlines = {}
...@@ -463,11 +462,11 @@ class printcore(): ...@@ -463,11 +462,11 @@ class printcore():
#callback for printing done #callback for printing done
try: self.endcb() try: self.endcb()
except: except:
print "Print end callback failed with:" logging.error(_("Print end callback failed with:") +
traceback.print_exc(file = sys.stdout) "\n" + traceback.format_exc())
except: except:
print "Print thread died due to the following error:" logging.error(_("Print thread died due to the following error:") +
traceback.print_exc(file = sys.stdout) "\n" + traceback.format_exc())
finally: finally:
self.print_thread = None self.print_thread = None
self._start_sender() self._start_sender()
...@@ -554,10 +553,10 @@ class printcore(): ...@@ -554,10 +553,10 @@ class printcore():
# run the command through the analyzer # run the command through the analyzer
try: self.analyzer.Analyze(command) try: self.analyzer.Analyze(command)
except: except:
print "Warning: could not analyze command %s:" % command logging.error(_("Warning: could not analyze command %s:") % command +
traceback.print_exc(file = sys.stdout) "\n" + traceback.format_exc())
if self.loud: if self.loud:
print "SENT:", command logging.info("SENT: %s" % command)
if self.sendcb: if self.sendcb:
try: self.sendcb(command) try: self.sendcb(command)
except: pass except: pass
......
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