Attachments you submit will be routed for moderation. If you have an account, please log in first.

Ticket #1211: 0001-let-the-logger-do-the-formatting.patch

File 0001-let-the-logger-do-the-formatting.patch, 14.2 KB (added by sascha_silbe, 4 years ago)

let the logger do the formatting

  • src/carquinyol/datastore.py

    From e555903564cffb1a206606d9e7c8848e3bc99efa Mon Sep 17 00:00:00 2001
    From: Sascha Silbe <sascha@silbe.org>
    Date: Wed, 19 Aug 2009 16:00:22 +0200
    Subject: [PATCH] let the logger do the formatting
    
    ---
     src/carquinyol/datastore.py  |   41 +++++++++++++++++++----------------------
     src/carquinyol/filestore.py  |   20 ++++++++++----------
     src/carquinyol/indexstore.py |    3 +--
     src/carquinyol/migration.py  |   10 ++++------
     src/carquinyol/optimizer.py  |   14 +++++++-------
     5 files changed, 41 insertions(+), 47 deletions(-)
    
    diff --git a/src/carquinyol/datastore.py b/src/carquinyol/datastore.py
    index 41b16b5..dc2e167 100644
    a b  
    7171        try: 
    7272            self._index_store.open_index() 
    7373        except Exception: 
    74             logging.error('Failed to open index, will rebuild\n%s' \ 
    75                     % traceback.format_exc()) 
     74            logging.exception('Failed to open index, will rebuild') 
    7675            layout_manager.index_updated = False 
    7776            self._index_store.remove_index() 
    7877            self._index_store.open_index() 
     
    8786 
    8887    def _rebuild_index(self): 
    8988        uids = layoutmanager.get_instance().find_all() 
    90         logging.debug('Going to update the index with uids %r' % uids) 
     89        logging.debug('Going to update the index with uids %r', uids) 
    9190        gobject.idle_add(lambda: self.__rebuild_index_cb(uids), 
    9291                            priority=gobject.PRIORITY_LOW) 
    9392 
     
    9594        if uids: 
    9695            uid = uids.pop() 
    9796 
    98             logging.debug('Updating entry %r in index. %d to go.' % \ 
    99                           (uid, len(uids))) 
     97            logging.debug('Updating entry %r in index. %d to go.', uid, 
     98                len(uids)) 
    10099 
    101100            if not self._index_store.contains(uid): 
    102101                try: 
    103102                    props = self._metadata_store.retrieve(uid) 
    104103                    self._index_store.store(uid, props) 
    105104                except Exception: 
    106                     logging.error('Error processing %r\n%s.' \ 
    107                             % (uid, traceback.format_exc())) 
     105                    logging.exception('Error processing %r', uid) 
    108106 
    109107        if not uids: 
    110108            logging.debug('Finished updating index.') 
     
    114112            return True 
    115113 
    116114    def _create_completion_cb(self, async_cb, async_err_cb, uid, exc=None): 
    117         logger.debug("_create_completion_cb(%r, %r, %r, %r)" % \ 
    118             (async_cb, async_err_cb, uid, exc)) 
     115        logger.debug('_create_completion_cb(%r, %r, %r, %r)', async_cb, 
     116            async_err_cb, uid, exc) 
    119117        if exc is not None: 
    120118            async_err_cb(exc) 
    121119            return 
    122120 
    123121        self.Created(uid) 
    124122        self._optimizer.optimize(uid) 
    125         logger.debug("created %s" % uid) 
     123        logger.debug('created %s', uid) 
    126124        async_cb(uid) 
    127125 
    128126    @dbus.service.method(DS_DBUS_INTERFACE, 
     
    133131    def create(self, props, file_path, transfer_ownership, 
    134132               async_cb, async_err_cb): 
    135133        uid = str(uuid.uuid4()) 
    136         logging.debug('datastore.create %r' % uid) 
     134        logging.debug('datastore.create %r', uid) 
    137135 
    138136        if not props.get('timestamp', ''): 
    139137            props['timestamp'] = int(time.time()) 
     
    151149        pass 
    152150 
    153151    def _update_completion_cb(self, async_cb, async_err_cb, uid, exc=None): 
    154         logger.debug("_update_completion_cb() called with %r / %r, exc %r" % \ 
    155             (async_cb, async_err_cb, exc)) 
     152        logger.debug('_update_completion_cb() called with %r / %r, exc %r', 
     153            async_cb, async_err_cb, exc) 
    156154        if exc is not None: 
    157155            async_err_cb(exc) 
    158156            return 
    159157 
    160158        self.Updated(uid) 
    161159        self._optimizer.optimize(uid) 
    162         logger.debug("updated %s" % uid) 
     160        logger.debug('updated %s', uid) 
    163161        async_cb() 
    164162 
    165163    @dbus.service.method(DS_DBUS_INTERFACE, 
     
    169167             byte_arrays=True) 
    170168    def update(self, uid, props, file_path, transfer_ownership, 
    171169               async_cb, async_err_cb): 
    172         logging.debug('datastore.update %r' % uid) 
     170        logging.debug('datastore.update %r', uid) 
    173171 
    174172        if not props.get('timestamp', ''): 
    175173            props['timestamp'] = int(time.time()) 
     
    194192             in_signature='a{sv}as', 
    195193             out_signature='aa{sv}u') 
    196194    def find(self, query, properties): 
    197         logging.debug('datastore.find %r' % query) 
     195        logging.debug('datastore.find %r', query) 
    198196        t = time.time() 
    199197 
    200198        if layoutmanager.get_instance().index_updated: 
    201199            try: 
    202200                uids, count = self._index_store.find(query) 
    203201            except Exception: 
    204                 logging.error('Failed to query index, will rebuild\n%s' \ 
    205                         % traceback.format_exc()) 
     202                logging.exception('Failed to query index, will rebuild') 
    206203                layoutmanager.get_instance().index_updated = False 
    207204                self._index_store.close_index() 
    208205                self._index_store.remove_index() 
     
    231228            metadata = self._metadata_store.retrieve(uid, properties) 
    232229            entries.append(metadata) 
    233230 
    234         logger.debug('find(): %r' % (time.time() - t)) 
     231        logger.debug('find(): %r', time.time() - t) 
    235232 
    236233        return entries, count 
    237234 
     
    255252             out_signature='s', 
    256253             sender_keyword='sender') 
    257254    def get_filename(self, uid, sender=None): 
    258         logging.debug('datastore.get_filename %r' % uid) 
     255        logging.debug('datastore.get_filename %r', uid) 
    259256        user_id = dbus.Bus().get_unix_user(sender) 
    260257        extension = self._get_extension(uid) 
    261258        return self._file_store.retrieve(uid, user_id, extension) 
     
    270267                         in_signature='s', 
    271268                         out_signature='a{sv}') 
    272269    def get_properties(self, uid): 
    273         logging.debug('datastore.get_properties %r' % uid) 
     270        logging.debug('datastore.get_properties %r', uid) 
    274271        metadata = self._metadata_store.retrieve(uid) 
    275272        return metadata 
    276273 
     
    302299        os.removedirs(entry_path) 
    303300 
    304301        self.Deleted(uid) 
    305         logger.debug("deleted %s" % uid) 
     302        logger.debug('deleted %s', uid) 
    306303 
    307304    @dbus.service.signal(DS_DBUS_INTERFACE, signature="s") 
    308305    def Deleted(self, uid): 
  • src/carquinyol/filestore.py

    diff --git a/src/carquinyol/filestore.py b/src/carquinyol/filestore.py
    index 0e018bd..71d6344 100644
    a b  
    4545                raise ValueError('No file at %r' % file_path) 
    4646            if transfer_ownership: 
    4747                try: 
    48                     logging.debug('FileStore moving from %r to %r' % \ 
    49                                   (file_path, destination_path)) 
     48                    logging.debug('FileStore moving from %r to %r', file_path, 
     49                        destination_path) 
    5050                    os.rename(file_path, destination_path) 
    5151                    completion_cb() 
    5252                except OSError, e: 
     
    7272        """Start copying a file asynchronously. 
    7373 
    7474        """ 
    75         logging.debug('FileStore copying from %r to %r' % \ 
    76                       (file_path, destination_path)) 
     75        logging.debug('FileStore copying from %r to %r', file_path, 
     76            destination_path) 
    7777        async_copy = AsyncCopy(file_path, destination_path, completion_cb) 
    7878        async_copy.start() 
    7979 
     
    8585        """ 
    8686        file_path = layoutmanager.get_instance().get_data_path(uid) 
    8787        if not os.path.exists(file_path): 
    88             logging.debug('Entry %r doesnt have any file' % uid) 
     88            logging.debug('Entry %r doesnt have any file', uid) 
    8989            return '' 
    9090 
    9191        use_instance_dir = os.path.exists('/etc/olpc-security') and \ 
     
    158158        existing_file = layoutmanager.get_instance().get_data_path(existing_uid) 
    159159        new_file = layoutmanager.get_instance().get_data_path(new_uid) 
    160160 
    161         logging.debug('removing %r' % new_file) 
     161        logging.debug('removing %r', new_file) 
    162162        os.remove(new_file) 
    163163 
    164         logging.debug('hard linking %r -> %r' % (new_file, existing_file)) 
     164        logging.debug('hard linking %r -> %r', new_file, existing_file) 
    165165        os.link(existing_file, new_file) 
    166166 
    167167 
     
    193193            # error writing data to file? 
    194194            if count < len(data): 
    195195                logging.error('AC: Error writing %s -> %s: wrote less than ' 
    196                         'expected' % (self.src, self.dest)) 
     196                        'expected', self.src, self.dest) 
    197197                self._cleanup() 
    198198                self.completion(RuntimeError( 
    199199                        'Error writing data to destination file')) 
     
    207207                self.completion(None) 
    208208                return False 
    209209        except Exception, err: 
    210             logging.error("AC: Error copying %s -> %s: %r" % \ 
    211                     (self.src, self.dest, err)) 
     210            logging.error('AC: Error copying %s -> %s: %r', self.src, self. 
     211                dest, err) 
    212212            self._cleanup() 
    213213            self.completion(err) 
    214214            return False 
  • src/carquinyol/indexstore.py

    diff --git a/src/carquinyol/indexstore.py b/src/carquinyol/indexstore.py
    index 06a41e0..6a70aee 100644
    a b  
    304304 
    305305    def _flush(self, force=False): 
    306306        """Called after any database mutation""" 
    307         logging.debug('IndexStore.flush: %r %r' % 
    308             (force, self._pending_writes)) 
     307        logging.debug('IndexStore.flush: %r %r', force, self._pending_writes) 
    309308 
    310309        if self._flush_timeout is not None: 
    311310            gobject.source_remove(self._flush_timeout) 
  • src/carquinyol/migration.py

    diff --git a/src/carquinyol/migration.py b/src/carquinyol/migration.py
    index ed82558..95ee391 100644
    a b  
    4343        if ext != '.metadata': 
    4444            continue 
    4545 
    46         logging.debug('Migrating entry %r' % uid) 
     46        logging.debug('Migrating entry %r', uid) 
    4747        try: 
    4848            _migrate_metadata(root_path, old_root_path, uid) 
    4949            _migrate_file(root_path, old_root_path, uid) 
    5050            _migrate_preview(root_path, old_root_path, uid) 
    5151        except Exception: 
    52             logging.error('Error while migrating entry %r: %s\n' % \ 
    53                           (uid, traceback.format_exc())) 
     52            logging.exception('Error while migrating entry %r', uid) 
    5453 
    5554    # Just be paranoid, it's cheap. 
    5655    if old_root_path.endswith('datastore/store'): 
     
    8685            finally: 
    8786                f.close() 
    8887        except Exception: 
    89             logging.error( 
    90                     'Error while migrating property %s of entry %s: %s\n' % \ 
    91                     (key, uid, traceback.format_exc())) 
     88            logging.exception( 
     89                    'Error while migrating property %s of entry %s', key, uid) 
    9290 
    9391 
    9492def _migrate_file(root_path, old_root_path, uid): 
  • src/carquinyol/optimizer.py

    diff --git a/src/carquinyol/optimizer.py b/src/carquinyol/optimizer.py
    index 6cb1374..2b6ce29 100644
    a b  
    4242 
    4343        queue_path = layoutmanager.get_instance().get_queue_path() 
    4444        open(os.path.join(queue_path, uid), 'w').close() 
    45         logging.debug('optimize %r' % os.path.join(queue_path, uid)) 
     45        logging.debug('optimize %r', os.path.join(queue_path, uid)) 
    4646 
    4747        if self._enqueue_checksum_id is None: 
    4848            self._enqueue_checksum_id = \ 
     
    6262        checksum_entry_path = os.path.join(checksum_path, uid) 
    6363 
    6464        if os.path.exists(checksum_entry_path): 
    65             logging.debug('remove %r' % checksum_entry_path) 
     65            logging.debug('remove %r', checksum_entry_path) 
    6666            os.remove(checksum_entry_path) 
    6767 
    6868        if os.path.exists(checksum_path): 
    6969            try: 
    7070                os.rmdir(checksum_path) 
    71                 logging.debug('removed %r' % checksum_path) 
     71                logging.debug('removed %r', checksum_path) 
    7272            except OSError, e: 
    7373                if e.errno != errno.ENOTEMPTY: 
    7474                    raise 
     
    9696        """ 
    9797        checksums_dir = layoutmanager.get_instance().get_checksums_dir() 
    9898        checksum_path = os.path.join(checksums_dir, checksum) 
    99         logging.debug('create dir %r' % checksum_path) 
     99        logging.debug('create dir %r', checksum_path) 
    100100        os.mkdir(checksum_path) 
    101101 
    102102    def _add_checksum_entry(self, uid, checksum): 
     
    106106        checksums_dir = layoutmanager.get_instance().get_checksums_dir() 
    107107        checksum_path = os.path.join(checksums_dir, checksum) 
    108108 
    109         logging.debug('touch %r' % os.path.join(checksum_path, uid)) 
     109        logging.debug('touch %r', os.path.join(checksum_path, uid)) 
    110110        open(os.path.join(checksum_path, uid), 'w').close() 
    111111 
    112112    def _already_linked(self, uid, checksum): 
     
    128128        queue = os.listdir(queue_path) 
    129129        if queue: 
    130130            uid = queue[0] 
    131             logging.debug('_process_entry_cb processing %r' % uid) 
     131            logging.debug('_process_entry_cb processing %r', uid) 
    132132 
    133133            file_in_entry_path = self._file_store.get_file_path(uid) 
    134134            if not os.path.exists(file_in_entry_path): 
    135                 logging.info('non-existent entry in queue: %r' % uid) 
     135                logging.info('non-existent entry in queue: %r', uid) 
    136136            else: 
    137137                checksum = self._calculate_md5sum(file_in_entry_path) 
    138138                self._metadata_store.set_property(uid, 'checksum', checksum)