def test_clear_log(self): """Verify deleting the log file""" log_file = pathfinder.log_path() if os.path.exists(log_file): try: model.clear_log() self.assertFalse(os.path.exists(log_file)) except WindowsError: # file in use (Windows) pass
def get_logger(module_name): """Returns a Logger instance for the specified module_name""" logger = logging.getLogger('.'.join(['nditoolbox', module_name])) logger.setLevel(get_loglevel()) # Default to starting a new log every 7 days, keeping a copy of the last 7 days' events log_handler = logging.FileHandler(pathfinder.log_path()) log_format = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') log_handler.setFormatter(log_format) logger.addHandler(log_handler) return logger
def get_logger(module_name): """Returns a Logger instance for the specified module_name""" logger = logging.getLogger('.'.join(['nditoolbox', module_name])) logger.setLevel(get_loglevel()) # Default to starting a new log every 7 days, keeping a copy of the last 7 days' events log_handler = logging.FileHandler(pathfinder.log_path()) log_format = logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s') log_handler.setFormatter(log_format) logger.addHandler(log_handler) return logger
def on_clear_log(self, evt): """Handles request to delete the application log.""" log_path = pathfinder.log_path() if os.path.exists(log_path): confirm_deletion_dlg = wx.MessageDialog(parent=self.view.parent, caption="Delete Log?", message="Are you sure you want to delete the log?", style=wx.OK | wx.CANCEL) if confirm_deletion_dlg.ShowModal() == wx.ID_OK: try: mainmodel.clear_log() except WindowsError: # File in use (Windows) err_msg = "Unable to delete log-Windows reports the file is in use." err_dlg = wx.MessageDialog(self.view, message=err_msg, caption="Unable To Delete Log", style=wx.ICON_ERROR) err_dlg.ShowModal() err_dlg.Destroy()
def on_clear_log(self, evt): """Handles request to delete the application log.""" log_path = pathfinder.log_path() if os.path.exists(log_path): confirm_deletion_dlg = wx.MessageDialog(parent=self.view, caption="Delete Log?", message="Are you sure you want to delete the log?", style=wx.OK | wx.CANCEL) if confirm_deletion_dlg.ShowModal() == wx.ID_OK: try: mainmodel.clear_log() except WindowsError: # File in use (Windows) err_msg = "Unable to delete log-Windows reports the file is in use." err_dlg = wx.MessageDialog(self.view, message=err_msg, caption="Unable To Delete Log", style=wx.ICON_ERROR) err_dlg.ShowModal() err_dlg.Destroy()
def on_display_log(self, evt): """Handles request to display application log""" try: wx.BeginBusyCursor() log_path = pathfinder.log_path() default_log_contents = ['Log is currently empty.'] log_contents = [] if os.path.exists(log_path): with open(log_path, "r") as fidin: log_contents = fidin.readlines() if len(log_contents) is 0: log_contents = default_log_contents text_display_dlg = dlg.TextDisplayDialog(parent=self.view, text=log_contents, title='NDIToolbox Log - {0}'.format(log_path), wrap=False, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER) text_display_dlg.Show() finally: wx.EndBusyCursor()
def clear_log(): """Deletes the current log file. Backup log files (if any) are untouched. On Windows, raises WindowsError if file is in use.""" log_file = pathfinder.log_path() if os.path.exists(log_file): os.remove(log_file)
def test_log_path(self): """Verify returning correct path to log file""" self.assertEqual(self.log_path, pathfinder.log_path())