Commit 064ef774 authored by Guillaume Seguin's avatar Guillaume Seguin

WIP #561: use logging module for outputs

parent 7de6a464
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
from threading import Lock from threading import Lock
import logging import logging
import sys
import traceback import traceback
import numpy import numpy
import numpy.linalg import numpy.linalg
...@@ -117,8 +116,8 @@ class wxGLPanel(wx.Panel): ...@@ -117,8 +116,8 @@ class wxGLPanel(wx.Panel):
self.OnDraw() self.OnDraw()
except pyglet.gl.lib.GLException: except pyglet.gl.lib.GLException:
self.gl_broken = True self.gl_broken = True
logging.error(_("OpenGL failed, disabling it:")) logging.error(_("OpenGL failed, disabling it:")
traceback.print_exc(file = sys.stdout) + "\n" + traceback.format_exc())
event.Skip() event.Skip()
def Destroy(self): def Destroy(self):
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
# along with Printrun. If not, see <http://www.gnu.org/licenses/>. # along with Printrun. If not, see <http://www.gnu.org/licenses/>.
import traceback import traceback
import logging
import wx import wx
...@@ -53,9 +54,9 @@ class VizPane(wx.BoxSizer): ...@@ -53,9 +54,9 @@ class VizPane(wx.BoxSizer):
root.gviz.clickcb = root.show_viz_window root.gviz.clickcb = root.show_viz_window
except: except:
use2dview = True use2dview = True
print "3D view mode requested, but we failed to initialize it." logging.error("3D view mode requested, but we failed to initialize it.\n"
print "Falling back to 2D view, and here is the backtrace:" + "Falling back to 2D view, and here is the backtrace:\n"
traceback.print_exc() + traceback.format_exc())
if use2dview: if use2dview:
root.gviz = gviz.Gviz(parentpanel, (300, 300), root.gviz = gviz.Gviz(parentpanel, (300, 300),
build_dimensions = root.build_dimensions_list, build_dimensions = root.build_dimensions_list,
...@@ -75,9 +76,9 @@ class VizPane(wx.BoxSizer): ...@@ -75,9 +76,9 @@ class VizPane(wx.BoxSizer):
root.gwindow = printrun.gcview.GcodeViewFrame(None, wx.ID_ANY, 'Gcode view, shift to move view, mousewheel to set layer', size = (600, 600), build_dimensions = root.build_dimensions_list, objects = objects, root = root, circular = root.settings.circular_bed, antialias_samples = int(root.settings.antialias3dsamples)) root.gwindow = printrun.gcview.GcodeViewFrame(None, wx.ID_ANY, 'Gcode view, shift to move view, mousewheel to set layer', size = (600, 600), build_dimensions = root.build_dimensions_list, objects = objects, root = root, circular = root.settings.circular_bed, antialias_samples = int(root.settings.antialias3dsamples))
except: except:
use3dview = False use3dview = False
print "3D view mode requested, but we failed to initialize it." logging.error("3D view mode requested, but we failed to initialize it.\n"
print "Falling back to 2D view, and here is the backtrace:" + "Falling back to 2D view, and here is the backtrace:\n"
traceback.print_exc() + traceback.format_exc())
if not use3dview: if not use3dview:
root.gwindow = gviz.GvizWindow(build_dimensions = root.build_dimensions_list, root.gwindow = gviz.GvizWindow(build_dimensions = root.build_dimensions_list,
grid = (root.settings.preview_grid_step1, root.settings.preview_grid_step2), grid = (root.settings.preview_grid_step1, root.settings.preview_grid_step2),
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
# along with Printrun. If not, see <http://www.gnu.org/licenses/>. # along with Printrun. If not, see <http://www.gnu.org/licenses/>.
import platform import platform
import traceback
import logging import logging
import os import os
...@@ -126,9 +125,8 @@ try: ...@@ -126,9 +125,8 @@ try:
def powerset_print_stop(): def powerset_print_stop():
reset_priority() reset_priority()
deinhibit_sleep() deinhibit_sleep()
except ImportError: except ImportError, e:
print "psutil unavailable, could not import power utils:" logging.warning("psutil unavailable, could not import power utils:" + e)
traceback.print_exc()
def powerset_print_start(reason): def powerset_print_start(reason):
pass pass
......
...@@ -115,7 +115,7 @@ class printcore(): ...@@ -115,7 +115,7 @@ class printcore():
def logError(self, error): def logError(self, error):
if self.errorcb: if self.errorcb:
try: self.errorcb(error) try: self.errorcb(error)
except: traceback.print_exc() except: logging.error(traceback.format_exc())
else: else:
logging.error(error) logging.error(error)
...@@ -230,7 +230,7 @@ class printcore(): ...@@ -230,7 +230,7 @@ class printcore():
self.log.append(line) self.log.append(line)
if self.recvcb: if self.recvcb:
try: self.recvcb(line) try: self.recvcb(line)
except: traceback.print_exc() except: self.logError(traceback.format_exc())
if self.loud: logging.info("RECV: %s" % line.rstrip()) if self.loud: logging.info("RECV: %s" % line.rstrip())
return line return line
except SelectError as e: except SelectError as e:
...@@ -287,7 +287,7 @@ class printcore(): ...@@ -287,7 +287,7 @@ class printcore():
self.online = True self.online = True
if self.onlinecb: if self.onlinecb:
try: self.onlinecb() try: self.onlinecb()
except: traceback.print_exc() except: self.logError(traceback.format_exc())
return return
def _listen(self): def _listen(self):
...@@ -307,7 +307,7 @@ class printcore(): ...@@ -307,7 +307,7 @@ class printcore():
if line.startswith('ok') and "T:" in line and self.tempcb: if line.startswith('ok') and "T:" in line and self.tempcb:
# callback for temp, status, whatever # callback for temp, status, whatever
try: self.tempcb(line) try: self.tempcb(line)
except: traceback.print_exc() except: self.logError(traceback.format_exc())
elif line.startswith('Error'): elif line.startswith('Error'):
self.logError(line) self.logError(line)
# Teststrings for resend parsing # Firmware exp. result # Teststrings for resend parsing # Firmware exp. result
...@@ -410,9 +410,9 @@ class printcore(): ...@@ -410,9 +410,9 @@ class printcore():
if e.message == "cannot join current thread": if e.message == "cannot join current thread":
pass pass
else: else:
traceback.print_exc() self.logError(traceback.format_exc())
except: except:
traceback.print_exc() self.logError(traceback.format_exc())
self.print_thread = None self.print_thread = None
...@@ -536,7 +536,7 @@ class printcore(): ...@@ -536,7 +536,7 @@ class printcore():
(prev_layer, prev_line) = self.mainqueue.idxs(self.queueindex - 1) (prev_layer, prev_line) = self.mainqueue.idxs(self.queueindex - 1)
if prev_layer != layer: if prev_layer != layer:
try: self.layerchangecb(layer) try: self.layerchangecb(layer)
except: traceback.print_exc() except: self.logError(traceback.format_exc())
if self.preprintsendcb: if self.preprintsendcb:
if self.queueindex + 1 < len(self.mainqueue): if self.queueindex + 1 < len(self.mainqueue):
(next_layer, next_line) = self.mainqueue.idxs(self.queueindex + 1) (next_layer, next_line) = self.mainqueue.idxs(self.queueindex + 1)
...@@ -562,7 +562,7 @@ class printcore(): ...@@ -562,7 +562,7 @@ class printcore():
self.lineno += 1 self.lineno += 1
if self.printsendcb: if self.printsendcb:
try: self.printsendcb(gline) try: self.printsendcb(gline)
except: traceback.print_exc() except: self.logError(traceback.format_exc())
else: else:
self.clear = True self.clear = True
self.queueindex += 1 self.queueindex += 1
...@@ -594,7 +594,7 @@ class printcore(): ...@@ -594,7 +594,7 @@ class printcore():
logging.info("SENT: %s" % command) logging.info("SENT: %s" % command)
if self.sendcb: if self.sendcb:
try: self.sendcb(command, gline) try: self.sendcb(command, gline)
except: traceback.print_exc() except: self.logError(traceback.format_exc())
try: try:
self.printer.write(str(command + "\n")) self.printer.write(str(command + "\n"))
if self.printer_tcp: if self.printer_tcp:
......
...@@ -369,16 +369,16 @@ class pronsole(cmd.Cmd): ...@@ -369,16 +369,16 @@ class pronsole(cmd.Cmd):
def do_exit(self, l): def do_exit(self, l):
if self.status.extruder_temp_target != 0: if self.status.extruder_temp_target != 0:
print "Setting extruder temp to 0" self.log("Setting extruder temp to 0")
self.p.send_now("M104 S0.0") self.p.send_now("M104 S0.0")
if self.status.bed_enabled: if self.status.bed_enabled:
if self.status.bed_temp_target != 0: if self.status.bed_temp_target != 0:
print "Setting bed temp to 0" self.log("Setting bed temp to 0")
self.p.send_now("M140 S0.0") self.p.send_now("M140 S0.0")
self.log("Disconnecting from printer...") self.log("Disconnecting from printer...")
if self.p.printing: if self.p.printing:
print "Are you sure you want to exit while printing?" self.log(_("Are you sure you want to exit while printing?\n\
print "(this will terminate the print)." (this will terminate the print)."))
if not self.confirm(): if not self.confirm():
return return
self.log(_("Exiting program. Goodbye!")) self.log(_("Exiting program. Goodbye!"))
...@@ -986,8 +986,8 @@ class pronsole(cmd.Cmd): ...@@ -986,8 +986,8 @@ class pronsole(cmd.Cmd):
if isinstance(e, KeyboardInterrupt): if isinstance(e, KeyboardInterrupt):
self.logError(_("...interrupted!")) self.logError(_("...interrupted!"))
else: else:
self.logError(_("Something wrong happened while uploading:")) self.logError(_("Something wrong happened while uploading:")
traceback.print_exc(file = sys.stdout) + "\n" + traceback.format_exc())
self.p.pause() self.p.pause()
self.p.send_now("M29 " + targetname) self.p.send_now("M29 " + targetname)
time.sleep(0.2) time.sleep(0.2)
...@@ -1151,9 +1151,9 @@ class pronsole(cmd.Cmd): ...@@ -1151,9 +1151,9 @@ class pronsole(cmd.Cmd):
def startcb(self, resuming = False): def startcb(self, resuming = False):
self.starttime = time.time() self.starttime = time.time()
if resuming: if resuming:
print _("Print resumed at: %s") % format_time(self.starttime) self.log(_("Print resumed at: %s") % format_time(self.starttime))
else: else:
print _("Print started at: %s") % format_time(self.starttime) self.log(_("Print started at: %s") % format_time(self.starttime))
if not self.sdprinting: if not self.sdprinting:
self.compute_eta = RemainingTimeEstimator(self.fgcode) self.compute_eta = RemainingTimeEstimator(self.fgcode)
else: else:
...@@ -1169,15 +1169,15 @@ class pronsole(cmd.Cmd): ...@@ -1169,15 +1169,15 @@ class pronsole(cmd.Cmd):
try: try:
powerset_print_start(reason = "Preventing sleep during print") powerset_print_start(reason = "Preventing sleep during print")
except: except:
logging.error(_("Failed to set power settings:")) self.logError(_("Failed to set power settings:")
traceback.print_exc(file = sys.stdout) + "\n" + traceback.format_exc())
def endcb(self): def endcb(self):
try: try:
powerset_print_stop() powerset_print_stop()
except: except:
logging.error(_("Failed to set power settings:")) self.logError(_("Failed to set power settings:")
traceback.print_exc(file = sys.stdout) + "\n" + traceback.format_exc())
if self.p.queueindex == 0: if self.p.queueindex == 0:
print_duration = int(time.time() - self.starttime + self.extra_print_time) print_duration = int(time.time() - self.starttime + self.extra_print_time)
self.log(_("Print ended at: %(end_time)s and took %(duration)s") % {"end_time": format_time(time.time()), self.log(_("Print ended at: %(end_time)s and took %(duration)s") % {"end_time": format_time(time.time()),
...@@ -1226,7 +1226,7 @@ class pronsole(cmd.Cmd): ...@@ -1226,7 +1226,7 @@ class pronsole(cmd.Cmd):
and not self.monitoring and (report_type == REPORT_NONE or report_type & REPORT_MANUAL): and not self.monitoring and (report_type == REPORT_NONE or report_type & REPORT_MANUAL):
if tstring[:5] == "echo:": if tstring[:5] == "echo:":
tstring = tstring[5:].lstrip() tstring = tstring[5:].lstrip()
if self.silent is False: print "\r" + tstring.ljust(15) if self.silent is False: self.log("\r" + tstring.ljust(15))
sys.stdout.write(self.promptf()) sys.stdout.write(self.promptf())
sys.stdout.flush() sys.stdout.flush()
...@@ -1294,10 +1294,10 @@ class pronsole(cmd.Cmd): ...@@ -1294,10 +1294,10 @@ class pronsole(cmd.Cmd):
self.p.send_now("M105") self.p.send_now("M105")
time.sleep(0.75) time.sleep(0.75)
if not self.status.bed_enabled: if not self.status.bed_enabled:
print "Hotend: %s/%s" % (self.status.extruder_temp, self.status.extruder_temp_target) self.log(_("Hotend: %s/%s") % (self.status.extruder_temp, self.status.extruder_temp_target))
else: else:
print "Hotend: %s/%s" % (self.status.extruder_temp, self.status.extruder_temp_target) self.log(_("Hotend: %s/%s") % (self.status.extruder_temp, self.status.extruder_temp_target))
print "Bed: %s/%s" % (self.status.bed_temp, self.status.bed_temp_target) self.log(_("Bed: %s/%s") % (self.status.bed_temp, self.status.bed_temp_target))
def help_gettemp(self): def help_gettemp(self):
self.log(_("Read the extruder and bed temperature.")) self.log(_("Read the extruder and bed temperature."))
...@@ -1314,7 +1314,7 @@ class pronsole(cmd.Cmd): ...@@ -1314,7 +1314,7 @@ class pronsole(cmd.Cmd):
if f >= 0: if f >= 0:
if f > 250: if f > 250:
print _("%s is a high temperature to set your extruder to. Are you sure you want to do that?") % f self.log(_("%s is a high temperature to set your extruder to. Are you sure you want to do that?") % f)
if not self.confirm(): if not self.confirm():
return return
if self.p.online: if self.p.online:
...@@ -1396,7 +1396,7 @@ class pronsole(cmd.Cmd): ...@@ -1396,7 +1396,7 @@ class pronsole(cmd.Cmd):
sys.stdout.flush() sys.stdout.flush()
prev_msg_len = len(prev_msg) prev_msg_len = len(prev_msg)
except KeyboardInterrupt: except KeyboardInterrupt:
if self.silent is False: print _("Done monitoring.") if self.silent is False: self.log(_("Done monitoring."))
self.monitoring = 0 self.monitoring = 0
def help_monitor(self): def help_monitor(self):
......
...@@ -912,7 +912,7 @@ Printrun. If not, see <http://www.gnu.org/licenses/>.""" ...@@ -912,7 +912,7 @@ Printrun. If not, see <http://www.gnu.org/licenses/>."""
grid[item - 1] = value grid[item - 1] = value
value = tuple(grid) value = tuple(grid)
except: except:
traceback.print_exc() self.logError(traceback.format_exc())
if hasattr(self.gviz, trueparam): if hasattr(self.gviz, trueparam):
self.apply_gviz_params(self.gviz, trueparam, value) self.apply_gviz_params(self.gviz, trueparam, value)
if hasattr(self.gwindow, "p") and hasattr(self.gwindow.p, trueparam): if hasattr(self.gwindow, "p") and hasattr(self.gwindow.p, trueparam):
...@@ -1032,8 +1032,8 @@ Printrun. If not, see <http://www.gnu.org/licenses/>.""" ...@@ -1032,8 +1032,8 @@ Printrun. If not, see <http://www.gnu.org/licenses/>."""
try: try:
baud = int(self.baud.GetValue()) baud = int(self.baud.GetValue())
except: except:
self.logError(_("Could not parse baud rate: ")) self.logError(_("Could not parse baud rate: ")
traceback.print_exc(file = sys.stdout) + "\n" + traceback.format_exc())
if self.paused: if self.paused:
self.p.paused = 0 self.p.paused = 0
self.p.printing = 0 self.p.printing = 0
...@@ -1251,9 +1251,9 @@ Printrun. If not, see <http://www.gnu.org/licenses/>.""" ...@@ -1251,9 +1251,9 @@ Printrun. If not, see <http://www.gnu.org/licenses/>."""
self.slicep.wait() self.slicep.wait()
self.stopsf = 1 self.stopsf = 1
except: except:
logging.error(_("Failed to execute slicing software: ")) self.logError(_("Failed to execute slicing software: ")
+ "\n" + traceback.format_exc())
self.stopsf = 1 self.stopsf = 1
traceback.print_exc(file = sys.stdout)
def slice_monitor(self): def slice_monitor(self):
while not self.stopsf: while not self.stopsf:
...@@ -1646,7 +1646,7 @@ Printrun. If not, see <http://www.gnu.org/licenses/>.""" ...@@ -1646,7 +1646,7 @@ Printrun. If not, see <http://www.gnu.org/licenses/>."""
if self.display_graph: wx.CallAfter(self.graph.SetBedTargetTemperature, setpoint) if self.display_graph: wx.CallAfter(self.graph.SetBedTargetTemperature, setpoint)
if self.display_gauges: wx.CallAfter(self.bedtgauge.SetTarget, setpoint) if self.display_gauges: wx.CallAfter(self.bedtgauge.SetTarget, setpoint)
except: except:
traceback.print_exc() self.logError(traceback.format_exc())
def update_pos(self): def update_pos(self):
bits = gcoder.m114_exp.findall(self.posreport) bits = gcoder.m114_exp.findall(self.posreport)
......
...@@ -24,6 +24,7 @@ install_locale('pronterface') ...@@ -24,6 +24,7 @@ install_locale('pronterface')
import wx import wx
import time import time
import logging
import threading import threading
import math import math
import sys import sys
...@@ -41,8 +42,8 @@ if "-nogl" not in sys.argv: ...@@ -41,8 +42,8 @@ if "-nogl" not in sys.argv:
from printrun import stlview from printrun import stlview
glview = True glview = True
except: except:
print "Could not load 3D viewer for plater:" logging.warning("Could not load 3D viewer for plater:"
traceback.print_exc() + "\n" + traceback.format_exc())
def evalme(s): def evalme(s):
...@@ -375,16 +376,22 @@ class StlPlater(Plater): ...@@ -375,16 +376,22 @@ class StlPlater(Plater):
try: try:
self.load_stl(filename) self.load_stl(filename)
except: except:
dlg = wx.MessageDialog(self, _("Loading STL file failed"), _("Error"), wx.OK) dlg = wx.MessageDialog(self, _("Loading STL file failed"),
_("Error:") + traceback.format_exc(),
wx.OK)
dlg.ShowModal() dlg.ShowModal()
traceback.print_exc(file = sys.stdout) logging.error(_("Loading STL file failed:")
+ "\n" + traceback.format_exc())
elif filename.lower().endswith(".scad"): elif filename.lower().endswith(".scad"):
try: try:
self.load_scad(filename) self.load_scad(filename)
except: except:
dlg = wx.MessageDialog(self, _("Loading OpenSCAD file failed"), _("Error"), wx.OK) dlg = wx.MessageDialog(self, _("Loading OpenSCAD file failed"),
_("Error:") + traceback.format_exc(),
wx.OK)
dlg.ShowModal() dlg.ShowModal()
traceback.print_exc(file = sys.stdout) logging.error(_("Loading OpenSCAD file failed:")
+ "\n" + traceback.format_exc())
def load_scad(self, name): def load_scad(self, name):
lf = open(name) lf = open(name)
...@@ -470,10 +477,10 @@ class StlPlater(Plater): ...@@ -470,10 +477,10 @@ class StlPlater(Plater):
def autoplate(self, event = None): def autoplate(self, event = None):
try: try:
self.autoplate_simarrange() self.autoplate_simarrange()
except: except Exception, e:
traceback.print_exc(file = sys.stdout) logging.warning(_("Failed to use simarrange for plating, "
print _("Failed to use simarrange for plating, " "falling back to the standard method. "
"falling back to the standard method") "The error was: ") + e)
super(StlPlater, self).autoplate() super(StlPlater, self).autoplate()
def autoplate_simarrange(self): def autoplate_simarrange(self):
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
import sys import sys
import traceback import traceback
import logging
from printrun.pronsole import pronsole from printrun.pronsole import pronsole
if __name__ == "__main__": if __name__ == "__main__":
...@@ -28,6 +29,6 @@ if __name__ == "__main__": ...@@ -28,6 +29,6 @@ if __name__ == "__main__":
except SystemExit: except SystemExit:
interp.p.disconnect() interp.p.disconnect()
except: except:
print _("Caught an exception, exiting:") logging.error(_("Caught an exception, exiting:")
traceback.print_exc() + "\n" + traceback.format_exc())
interp.p.disconnect() interp.p.disconnect()
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