Ticket #7286: all-the-way_enhanced_logging.patch
| File all-the-way_enhanced_logging.patch, 58.5 KB (added by Pedro Algarvio, aka, s0undt3ch <ufs@…>, 7 months ago) |
|---|
-
trac/attachment.py
112 112 self.resource = Resource(parent_realm_or_attachment_resource, 113 113 parent_id).child('attachment', filename) 114 114 self.env = env 115 self.log = self.env.get_logger(__name__) 115 116 self.parent_realm = self.resource.parent.realm 116 117 self.parent_id = unicode(self.resource.parent.id) 117 118 if self.resource.id: … … 180 181 try: 181 182 os.unlink(self.path) 182 183 except OSError: 183 self. env.log.error('Failed to delete attachment file %s',184 self.path, exc_info=True)184 self.log.error('Failed to delete attachment file %s', 185 self.path, exc_info=True) 185 186 if handle_ta: 186 187 db.rollback() 187 188 raise TracError(_('Could not delete attachment')) 188 189 189 self. env.log.info('Attachment removed: %s' %self.title)190 self.log.info('Attachment removed: %s', self.title) 190 191 if handle_ta: 191 192 db.commit() 192 193 … … 233 234 shutil.copyfileobj(fileobj, targetfile) 234 235 self.resource.id = self.filename = filename 235 236 236 self.env.log.info('New attachment: %s by %s', self.title, 237 self.author) 237 self.log.info('New attachment: %s by %s', self.title, self.author) 238 238 239 239 if handle_ta: 240 240 db.commit() … … 269 269 As this is usually done while deleting the parent resource, 270 270 the `db` argument is ''not'' optional here. 271 271 """ 272 log = env.get_logger(__name__) 272 273 attachment_dir = None 273 274 for attachment in list(cls.select(env, parent_realm, parent_id, db)): 274 275 attachment_dir = os.path.dirname(attachment.path) … … 277 278 try: 278 279 os.rmdir(attachment_dir) 279 280 except OSError: 280 env.log.error("Can't delete attachment directory %s",281 attachment_dir, exc_info=True)281 log.error("Can't delete attachment directory %s", 282 attachment_dir, exc_info=True) 282 283 283 284 select = classmethod(select) 284 285 delete_all = classmethod(delete_all) 285 286 286 287 def open(self): 287 self. env.log.debug('Trying to open attachment at %s', self.path)288 self.log.debug('Trying to open attachment at %s', self.path) 288 289 try: 289 290 fd = open(self.path, 'rb') 290 291 except IOError: … … 670 671 add_link(req, 'alternate', raw_href, _('Original Format'), 671 672 mime_type) 672 673 673 self.log.debug("Rendering preview of file %s with mime-type %s" 674 % (attachment.filename, mime_type))674 self.log.debug("Rendering preview of file %s with mime-type %s", 675 attachment.filename, mime_type) 675 676 676 677 data['preview'] = mimeview.preview_data( 677 678 Context.from_request(req, attachment.resource), fd, … … 748 749 if legacy_action: 749 750 decision = legacy_action in perm 750 751 if not decision: 751 self. env.log.debug('LegacyAttachmentPolicy denied %s '752 'access to %s. User needs %s' %753 (username, resource, legacy_action))752 self.log.debug('LegacyAttachmentPolicy denied %s ' 753 'access to %s. User needs %s', 754 username, resource, legacy_action) 754 755 return decision 755 756 else: 756 757 for d in self.delegates: -
trac/env.py
2 2 # 3 3 # Copyright (C) 2003-2008 Edgewall Software 4 4 # Copyright (C) 2003-2007 Jonas Borgström <jonas@edgewall.com> 5 # Copyright (C) 2008 Pedro Algarvio <ufs@ufsoft.org> 5 6 # All rights reserved. 6 7 # 7 8 # This software is licensed as described in the file COPYING, which … … 14 15 # 15 16 # Author: Jonas Borgström <jonas@edgewall.com> 16 17 18 import logging 17 19 import os 18 20 try: 19 21 import threading … … 147 149 - $(path)s the path for the current environment 148 150 - $(basename)s the last path component of the current environment 149 151 - $(project)s the project name 150 151 Note the usage of `$(...)s` instead of `%(...)s` as the latter form152 would be interpreted by the ConfigParser itself.153 154 Example:152 153 Note the usage of `$(...)s` instead of `%(...)s` as the latter form 154 would be interpreted by the ConfigParser itself. 155 156 Example: 155 157 ($(thread)d) Trac[$(basename)s:$(module)s] $(levelname)s: $(message)s 156 157 (since 0.10.5)""") 158 159 (since 0.10.5)""") 160 log_filters = ListOption('logging', 'log_filters', [], doc= 161 """Custom logging handlers. 162 163 If nothing set, logging will be as it was, nothing is changed. 164 165 Example usage is: 166 log_filters = trac:WARNING, trac.ticket:DEBUG 167 168 The above would translate to: 169 * all messages who's module name starts with `trac` and log level 170 is higher than `WARNING` are logged; 171 * all messages who's module name starts with `trac.ticket` and log 172 level is higher than `DEBUG` are logged; 173 * all other messages who's module name does not start with any of 174 the above and for which their level is higher than the default 175 `log_level` will be logged; 176 177 This way you can narrow the debugging messages to the modules you 178 wish to. The same applies to a plugin you're coding: 179 log_filters = trac:ERROR, my.plug.module:DEBUG 180 181 (since 0.12)""") 158 182 159 183 def __init__(self, path, create=False, options=[]): 160 184 """Initialize the Trac environment. … … 201 225 environment configuration) and `log` (a logger object).""" 202 226 component.env = self 203 227 component.config = self.config 204 component.log = self.log 228 component.log = logging.getLogger( 229 "%s.%s" % (self.path, component.__class__.__module__) 230 ) 205 231 206 232 def is_component_enabled(self, cls): 207 233 """Implemented to only allow activation of components that are not … … 347 373 348 374 def setup_log(self): 349 375 """Initialize the logging sub-system.""" 350 from trac.log import logger_factory376 from trac.log import setup_logging 351 377 logtype = self.log_type 352 378 logfile = self.log_file 353 379 if logtype == 'file' and not os.path.isabs(logfile): … … 358 384 .replace('%(path)s', self.path) \ 359 385 .replace('%(basename)s', os.path.basename(self.path)) \ 360 386 .replace('%(project)s', self.project_name) 361 self.log = logger_factory(logtype, logfile, self.log_level, self.path, 362 format=format) 387 # Setup but don't keep the root logger 388 setup_logging(logtype, logfile, self.log_level, self.path, 389 format, self.log_filters) 390 # Get a logger for this module (more correct) 391 self.log = logging.getLogger("%s.%s" % (self.path, __name__)) 392 393 def get_logger(self, name): 394 """Get the correct logger for classes/functions which an env is passed 395 yet, it's not subclassing Component.""" 396 from trac.log import get_logger 397 return get_logger(self.path, name) 363 398 364 399 def get_known_users(self, cnx=None): 365 400 """Generator that yields information about all known users, i.e. users … … 551 586 env.log.info('Reloading environment due to configuration ' 552 587 'change') 553 588 env.shutdown() 554 if hasattr(env.log, '_trac_handler'): 555 hdlr = env.log._trac_handler 556 env.log.removeHandler(hdlr) 589 env_root_logger = logging.getLogger(env.path) 590 if hasattr(env_root_logger, '_trac_handler'): 591 hdlr = env_root_logger._trac_handler 592 env_root_logger.removeHandler(hdlr) 557 593 hdlr.close() 594 del env_root_logger 558 595 del env_cache[env_path] 559 596 env = None 560 597 if env is None: -
trac/mimeview/enscript.py
136 136 mimetype = mimetype.split(';', 1)[0] # strip off charset 137 137 mode = self._types[mimetype][0] 138 138 cmdline += ' --color -h -q --language=html -p - -E%s' % mode 139 self. env.log.debug("Enscript command line: %s" %cmdline)139 self.log.debug("Enscript command line: %s", cmdline) 140 140 141 141 np = NaivePopen(cmdline, content.encode('utf-8'), capturestderr=1) 142 142 if np.errorlevel or np.err: -
trac/mimeview/php.py
81 81 def render(self, context, mimetype, content, filename=None, rev=None): 82 82 # -n to ignore php.ini so we're using default colors 83 83 cmdline = '%s -sn' % self.path 84 self. env.log.debug("PHP command line: %s" %cmdline)84 self.log.debug("PHP command line: %s", cmdline) 85 85 86 86 content = content_to_unicode(self.env, content, mimetype) 87 87 content = content.encode('utf-8') -
trac/ticket/tests/query.py
1 from trac.log import logger_factory1 from trac.log import setup_logging 2 2 from trac.mimeview import Context 3 3 from trac.test import Mock, EnvironmentStub, MockPerm 4 4 from trac.ticket.query import Query, QueryModule -
trac/ticket/report.py
531 531 # The number of tickets is obtained. 532 532 count_sql = 'SELECT COUNT(*) FROM (' + sql + ') AS tab' 533 533 cursor.execute(count_sql, args) 534 self. env.log.debug("Query SQL(Get num items): " + count_sql)534 self.log.debug("Query SQL(Get num items): " + count_sql) 535 535 for row in cursor: 536 536 pass 537 537 self.num_items = row[0] … … 539 539 # The column name is obtained. 540 540 get_col_name_sql = 'SELECT * FROM ( ' + sql + ' ) AS tab LIMIT 1' 541 541 cursor.execute(get_col_name_sql, args) 542 self. env.log.debug("Query SQL(Get col names): " + get_col_name_sql)542 self.log.debug("Query SQL(Get col names): " + get_col_name_sql) 543 543 cols = get_column_names(cursor) 544 544 545 545 sort_col = req.args.get('sort', '') 546 self. env.log.debug("Colnum Names %s, Sort column %s" %546 self.log.debug("Colnum Names %s, Sort column %s" % 547 547 (str(cols), sort_col)) 548 548 order_cols = [] 549 549 if '__group__' in cols: … … 567 567 sql = " ".join(['SELECT * FROM (', sql, ') AS tab', order_by]) 568 568 sql =" ".join([sql, 'LIMIT', str(self.limit), 'OFFSET', 569 569 str(self.offset)]) 570 self. env.log.debug("Query SQL: " + sql)570 self.log.debug("Query SQL: " + sql) 571 571 cursor.execute(sql, args) 572 self. env.log.debug("Query SQL: " + sql)572 self.log.debug("Query SQL: " + sql) 573 573 # FIXME: fetchall should probably not be used. 574 574 info = cursor.fetchall() or [] 575 575 cols = get_column_names(cursor) -
trac/ticket/model.py
40 40 41 41 def __init__(self, env, tkt_id=None, db=None, version=None): 42 42 self.env = env 43 self.log = self.env.get_logger(__name__) 43 44 self.resource = Resource('ticket', tkt_id, version) 44 45 self.fields = TicketSystem(self.env).get_ticket_fields() 45 46 self.values = {} … … 77 78 try: 78 79 default = options[int(default)] 79 80 except (ValueError, IndexError): 80 self. env.log.warning('Invalid default value "%s"'81 'for custom field "%s"'82 % (default, field['name']))81 self.log.warning('Invalid default value "%s" for ' 82 'custom field "%s"', default, 83 field['name']) 83 84 if default: 84 85 self.values.setdefault(field['name'], default) 85 86 … … 350 351 if not self.ticket_col: 351 352 self.ticket_col = self.type 352 353 self.env = env 354 self.log = self.env.get_logger(__name__) 353 355 if name: 354 356 name = simplify_whitespace(name) 355 357 if name: … … 379 381 handle_ta = False 380 382 381 383 cursor = db.cursor() 382 self. env.log.info('Deleting %s %s' % (self.type, self.name))384 self.log.info('Deleting %s %s', self.type, self.name) 383 385 cursor.execute("DELETE FROM enum WHERE type=%s AND value=%s", 384 386 (self.type, self._old_value)) 385 387 # Re-order any enums that have higher value than deleted (close gap) … … 407 409 handle_ta = False 408 410 409 411 cursor = db.cursor() 410 self. env.log.debug("Creating new %s '%s'" % (self.type, self.name))412 self.log.debug("Creating new %s '%s'", self.type, self.name) 411 413 if not self.value: 412 414 cursor.execute(("SELECT COALESCE(MAX(%s),0) FROM enum " 413 415 "WHERE type=%%s") % db.cast('value', 'int'), … … 432 434 handle_ta = False 433 435 434 436 cursor = db.cursor() 435 self. env.log.info('Updating %s "%s"' % (self.type, self.name))437 self.log.info('Updating %s "%s"', self.type, self.name) 436 438 cursor.execute("UPDATE enum SET name=%s,value=%s " 437 439 "WHERE type=%s AND name=%s", 438 440 (self.name, self.value, self.type, self._old_name)) … … 494 496 495 497 def __init__(self, env, name=None, db=None): 496 498 self.env = env 499 self.log = self.env.get_logger(__name__) 497 500 if name: 498 501 name = simplify_whitespace(name) 499 502 if name: … … 525 528 handle_ta = False 526 529 527 530 cursor = db.cursor() 528 self. env.log.info('Deleting component %s' %self.name)531 self.log.info('Deleting component %s', self.name) 529 532 cursor.execute("DELETE FROM component WHERE name=%s", (self.name,)) 530 533 531 534 self.name = self._old_name = None … … 544 547 handle_ta = False 545 548 546 549 cursor = db.cursor() 547 self. env.log.debug("Creating new component '%s'" %self.name)550 self.log.debug("Creating new component '%s'", self.name) 548 551 cursor.execute("INSERT INTO component (name,owner,description) " 549 552 "VALUES (%s,%s,%s)", 550 553 (self.name, self.owner, self.description)) … … 563 566 handle_ta = False 564 567 565 568 cursor = db.cursor() 566 self. env.log.info('Updating component "%s"' %self.name)569 self.log.info('Updating component "%s"', self.name) 567 570 cursor.execute("UPDATE component SET name=%s,owner=%s,description=%s " 568 571 "WHERE name=%s", 569 572 (self.name, self.owner, self.description, … … 596 599 597 600 def __init__(self, env, name=None, db=None): 598 601 self.env = env 602 self.log = self.env.get_logger(__name__) 599 603 if name: 600 604 self._fetch(name, db) 601 605 self._old_name = name … … 641 645 handle_ta = False 642 646 643 647 cursor = db.cursor() 644 self. env.log.info('Deleting milestone %s' %self.name)648 self.log.info('Deleting milestone %s', self.name) 645 649 cursor.execute("DELETE FROM milestone WHERE name=%s", (self.name,)) 646 650 647 651 # Retarget/reset tickets associated with this milestone … … 667 671 668 672 self.name = simplify_whitespace(self.name) 669 673 cursor = db.cursor() 670 self. env.log.debug("Creating new milestone '%s'" %self.name)674 self.log.debug("Creating new milestone '%s'", self.name) 671 675 cursor.execute("INSERT INTO milestone (name,due,completed,description) " 672 676 "VALUES (%s,%s,%s,%s)", 673 677 (self.name, to_timestamp(self.due), to_timestamp(self.completed), … … 686 690 687 691 self.name = simplify_whitespace(self.name) 688 692 cursor = db.cursor() 689 self. env.log.info('Updating milestone "%s"' %self.name)693 self.log.info('Updating milestone "%s"', self.name) 690 694 cursor.execute("UPDATE milestone SET name=%s,due=%s," 691 695 "completed=%s,description=%s WHERE name=%s", 692 696 (self.name, to_timestamp(self.due), to_timestamp(self.completed), 693 697 self.description, 694 698 self._old_name)) 695 self. env.log.info('Updating milestone field of all tickets'696 'associated with milestone "%s"' %self.name)699 self.log.info('Updating milestone field of all tickets associated ' 700 'with milestone "%s"', self.name) 697 701 cursor.execute("UPDATE ticket SET milestone=%s WHERE milestone=%s", 698 702 (self.name, self._old_name)) 699 703 self._old_name = self.name … … 726 730 727 731 def __init__(self, env, name=None, db=None): 728 732 self.env = env 733 self.log = self.env.get_logger(__name__) 729 734 if name: 730 735 if not db: 731 736 db = self.env.get_db_cnx() … … 755 760 handle_ta = False 756 761 757 762 cursor = db.cursor() 758 self. env.log.info('Deleting version %s' %self.name)763 self.log.info('Deleting version %s', self.name) 759 764 cursor.execute("DELETE FROM version WHERE name=%s", (self.name,)) 760 765 761 766 self.name = self._old_name = None … … 774 779 handle_ta = False 775 780 776 781 cursor = db.cursor() 777 self. env.log.debug("Creating new version '%s'" %self.name)782 self.log.debug("Creating new version '%s'", self.name) 778 783 cursor.execute("INSERT INTO version (name,time,description) " 779 784 "VALUES (%s,%s,%s)", 780 785 (self.name, to_timestamp(self.time), self.description)) … … 793 798 handle_ta = False 794 799 795 800 cursor = db.cursor() 796 self. env.log.info('Updating version "%s"' %self.name)801 self.log.info('Updating version "%s"', self.name) 797 802 cursor.execute("UPDATE version SET name=%s,time=%s,description=%s " 798 803 "WHERE name=%s", 799 804 (self.name, to_timestamp(self.time), self.description, -
trac/ticket/roadmap.py
646 646 cursor.execute("UPDATE ticket SET milestone=%s WHERE " 647 647 "milestone=%s and status != 'closed'", 648 648 (retarget_to, old_name)) 649 self. env.log.info('Tickets associated with milestone %s '650 'retargeted to %s' % (old_name, retarget_to))649 self.log.info('Tickets associated with milestone %s ' 650 'retargeted to %s' % (old_name, retarget_to)) 651 651 else: 652 652 milestone.insert() 653 653 db.commit() -
trac/ticket/query.py
53 53 order=None, desc=0, group=None, groupdesc=0, verbose=0, 54 54 rows=None, page=1, max=None): 55 55 self.env = env 56 self.log = self.env.get_logger(__name__) 56 57 self.id = report # if not None, it's the corresponding saved query 57 58 self.constraints = constraints or {} 58 59 self.order = order … … 240 241 cursor = db.cursor() 241 242 242 243 count_sql = 'SELECT COUNT(*) FROM (' + sql + ') AS foo' 243 # self. env.log.debug("Count results in Query SQL: " + count_sql %244 # tuple([repr(a) for a in args]))244 # self.log.debug("Count results in Query SQL: " + count_sql % 245 # tuple([repr(a) for a in args])) 245 246 246 247 cnt = 0 247 248 cursor.execute(count_sql, args); 248 249 for cnt, in cursor: 249 250 break 250 self. env.log.debug("Count results in Query: %d" %cnt)251 self.log.debug("Count results in Query: %d", cnt) 251 252 return cnt 252 253 253 254 def execute(self, req, db=None, cached_ids=None): … … 271 272 raise TracError(_('Page %(page)s is beyond the number of ' 272 273 'pages in the query', page=self.page)) 273 274 274 self. env.log.debug("Query SQL: " + sql % tuple([repr(a) for a in args]))275 self.log.debug("Query SQL: " + sql % tuple([repr(a) for a in args])) 275 276 cursor.execute(sql, args) 276 277 columns = get_column_names(cursor) 277 278 fields = [] -
trac/htdocs/css/admin.css
21 21 22 22 #tabcontent { padding: 0.4em 2em; margin-left: 12em; min-height: 300px; } 23 23 #tabcontent h2 { color: #333; margin-top: 0; } 24 p.help { color: #666; font-size: 90%; margin: 1em .5em .5em; }24 div.help, p.help { color: #666; font-size: 90%; margin: 1em .5em .5em; } 25 25 26 26 #enumlist tbody td { vertical-align: middle; } 27 27 -
trac/db/mysql_backend.py
70 70 from trac.db_default import schema 71 71 for table in schema: 72 72 for stmt in self.to_sql(table): 73 self. env.log.debug(stmt)73 self.log.debug(stmt) 74 74 cursor.execute(stmt) 75 75 cnx.commit() 76 76 -
trac/versioncontrol/tests/svn_fs.py
30 30 except: 31 31 has_svn = False 32 32 33 from trac.log import logger_factory33 from trac.log import setup_logging 34 34 from trac.test import TestSetup 35 35 from trac.core import TracError 36 36 from trac.util.datefmt import utc … … 85 85 86 86 def setUp(self): 87 87 self.repos = SubversionRepository(REPOS_PATH, None, 88 logger_factory('test'))88 setup_logging('test')) 89 89 90 90 def tearDown(self): 91 91 self.repos = None … … 460 460 461 461 def setUp(self): 462 462 self.repos = SubversionRepository(REPOS_PATH + '/trunk', None, 463 logger_factory('test'))463 setup_logging('test')) 464 464 465 465 def tearDown(self): 466 466 self.repos = None … … 688 688 689 689 def setUp(self): 690 690 self.repos = SubversionRepository(REPOS_PATH + '/trunk/dir1', None, 691 logger_factory('test'))691 setup_logging('test')) 692 692 693 693 def tearDown(self): 694 694 self.repos = None … … 708 708 709 709 def setUp(self): 710 710 self.repos = SubversionRepository(REPOS_PATH + '/tags/v1', None, 711 logger_factory('test'))711 setup_logging('test')) 712 712 713 713 def tearDown(self): 714 714 self.repos = None … … 726 726 727 727 def setUp(self): 728 728 self.repos = SubversionRepository(REPOS_PATH + '/branches', None, 729 logger_factory('test'))729 setup_logging('test')) 730 730 731 731 def tearDown(self): 732 732 self.repos = None -
trac/versioncontrol/tests/cache.py
16 16 17 17 from datetime import datetime 18 18 19 from trac.log import logger_factory19 from trac.log import setup_logging 20 20 from trac.test import Mock, InMemoryDatabase 21 21 from trac.util.datefmt import to_timestamp, utc 22 22 from trac.versioncontrol import Repository, Changeset, Node, NoSuchChangeset … … 30 30 31 31 def setUp(self): 32 32 self.db = InMemoryDatabase() 33 self.log = logger_factory('test')33 self.log = setup_logging('test') 34 34 cursor = self.db.cursor() 35 35 cursor.execute("INSERT INTO system (name, value) VALUES (%s,%s)",
