def start(log_filename=None): logs_path = env.get_logs_path() try: os.makedirs(logs_path) except OSError: pass # remove existing handlers, or logging.basicConfig() won't have no effect. root_logger = logging.getLogger('') for handler in root_logger.handlers: root_logger.removeHandler(handler) class SafeLogWrapper(object): """Small file-like wrapper to gracefully handle ENOSPC errors when logging.""" def __init__(self, stream): self._stream = stream def write(self, s): try: self._stream.write(s) except IOError, e: # gracefully deal w/ disk full if e.errno != errno.ENOSPC: raise e def flush(self): try: self._stream.flush() except IOError, e: # gracefully deal w/ disk full if e.errno != errno.ENOSPC: raise e
def start(log_filename=None): logs_path = env.get_logs_path() try: os.makedirs(logs_path) except OSError: pass # remove existing handlers, or logging.basicConfig() won't have no effect. root_logger = logging.getLogger('') for handler in root_logger.handlers: root_logger.removeHandler(handler) class SafeLogWrapper(object): """Small file-like wrapper to gracefully handle ENOSPC errors when logging.""" def __init__(self, stream): self._stream = stream def write(self, s): try: self._stream.write(s) except IOError as e: # gracefully deal w/ disk full if e.errno != errno.ENOSPC: raise e def flush(self): try: self._stream.flush() except IOError as e: # gracefully deal w/ disk full if e.errno != errno.ENOSPC: raise e logging.basicConfig( level=logging.WARNING, format="%(created)f %(levelname)s %(name)s: %(message)s", stream=SafeLogWrapper(sys.stderr)) if 'SUGAR_LOGGER_LEVEL' in os.environ: set_level(os.environ['SUGAR_LOGGER_LEVEL']) if log_filename: try: log_path = os.path.join(logs_path, log_filename + '.log') log_fd = os.open(log_path, os.O_WRONLY | os.O_CREAT, buffer=1) os.dup2(log_fd, sys.stdout.fileno()) os.dup2(log_fd, sys.stderr.fileno()) os.close(log_fd) sys.stdout = SafeLogWrapper(sys.stdout) sys.stderr = SafeLogWrapper(sys.stderr) except OSError as e: # if we're out of space, just continue if e.errno != errno.ENOSPC: raise e sys.excepthook = _except_hook
def open_log_file(activity): i = 1 while True: path = env.get_logs_path('%s-%s.log' % (activity.get_bundle_id(), i)) try: fd = os.open(path, os.O_EXCL | os.O_CREAT | os.O_WRONLY, 0644) f = os.fdopen(fd, 'w', 0) return (path, f) except OSError, e: if e.errno == EEXIST: i += 1 elif e.errno == ENOSPC: # not the end of the world; let's try to keep going. return ('/dev/null', open('/dev/null', 'w')) else: raise e
def __init__(self, namefilter): self._openlogs = [] logging.info('creating LogFilesViewer namefilter %s', namefilter) self._path = env.get_logs_path() logging.error('LOGS PATH %s', self._path) self._extra_files = [os.path.join(self._path, 'shell.log')] self._namefilter = namefilter Gtk.ScrolledWindow.__init__(self) self.props.hscrollbar_policy = Gtk.PolicyType.AUTOMATIC self.props.vscrollbar_policy = Gtk.PolicyType.AUTOMATIC self.set_size_request(style.GRID_CELL_SIZE * 3, -1) self._tree_view = Gtk.TreeView() self._tree_view.connect('cursor-changed', self.__cursor_changed_cb) self.add(self._tree_view) self._tree_view.show() self._tree_view.props.headers_visible = False selection = self._tree_view.get_selection() selection.connect('changed', self.__selection_changed_cb) cell = Gtk.CellRendererText() self._column = Gtk.TreeViewColumn() self._column.pack_start(cell, True) self._column.add_attribute(cell, 'text', 0) self._tree_view.append_column(self._column) self._tree_view.set_search_column(0) # Configuration self.set_title(_("Sugar logs")) self.init_logs(self._filter_by_name) self._monitors = [] self._configure_watcher()
def get_logs_dir(): return env.get_logs_path()
def start(log_filename=None): logs_path = env.get_logs_path() try: os.makedirs(logs_path) except OSError: pass # remove existing handlers, or logging.basicConfig() won't have no effect. root_logger = logging.getLogger('') for handler in root_logger.handlers: root_logger.removeHandler(handler) class SafeLogWrapper(object): """Small file-like wrapper to gracefully handle ENOSPC errors when logging.""" def __init__(self, stream): self._stream = stream def write(self, s): try: self._stream.write(s) except IOError as e: # gracefully deal w/ disk full if e.errno != errno.ENOSPC: raise e def flush(self): try: self._stream.flush() except IOError as e: # gracefully deal w/ disk full if e.errno != errno.ENOSPC: raise e logging.basicConfig( level=logging.WARNING, format="%(created)f %(levelname)s %(name)s: %(message)s", stream=SafeLogWrapper(sys.stderr)) if 'SUGAR_LOGGER_LEVEL' in os.environ: set_level(os.environ['SUGAR_LOGGER_LEVEL']) if log_filename: try: log_path = os.path.join(logs_path, log_filename + '.log') log_fd = os.open(log_path, os.O_WRONLY | os.O_CREAT) os.dup2(log_fd, sys.stdout.fileno()) os.dup2(log_fd, sys.stderr.fileno()) os.close(log_fd) sys.stdout = SafeLogWrapper(sys.stdout) sys.stderr = SafeLogWrapper(sys.stderr) except OSError as e: # if we're out of space, just continue if e.errno != errno.ENOSPC: raise e sys.excepthook = _except_hook