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

WIP #561: use logging module for outputs

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