From e6ca15c13f30e1433f91507c9f20743b7eb4725b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sat, 26 Dec 2015 22:49:52 +0200 Subject: [PATCH] Passed logging message parameters as arguments instead of interpolating them. --- django/contrib/gis/admin/widgets.py | 9 +++------ django/contrib/gis/db/backends/mysql/schema.py | 4 ++-- django/contrib/gis/forms/widgets.py | 9 +++------ django/contrib/gis/gdal/libgdal.py | 2 +- django/contrib/gis/geos/libgeos.py | 4 ++-- django/db/backends/base/schema.py | 2 +- django/db/backends/utils.py | 4 ++-- 7 files changed, 14 insertions(+), 20 deletions(-) diff --git a/django/contrib/gis/admin/widgets.py b/django/contrib/gis/admin/widgets.py index 52b624a112..abf38ddac4 100644 --- a/django/contrib/gis/admin/widgets.py +++ b/django/contrib/gis/admin/widgets.py @@ -35,10 +35,7 @@ class OpenLayersWidget(Textarea): try: value = GEOSGeometry(value) except (GEOSException, ValueError) as err: - logger.error( - "Error creating geometry from value '%s' (%s)" % ( - value, err) - ) + logger.error("Error creating geometry from value '%s' (%s)", value, err) value = None if (value and value.geom_type.upper() != self.geom_type and @@ -68,8 +65,8 @@ class OpenLayersWidget(Textarea): wkt = ogr.wkt except GDALException as err: logger.error( - "Error transforming geometry from srid '%s' to srid '%s' (%s)" % ( - value.srid, srid, err) + "Error transforming geometry from srid '%s' to srid '%s' (%s)", + value.srid, srid, err ) wkt = '' else: diff --git a/django/contrib/gis/db/backends/mysql/schema.py b/django/contrib/gis/db/backends/mysql/schema.py index e60f3d2fcc..a9b1b4867a 100644 --- a/django/contrib/gis/db/backends/mysql/schema.py +++ b/django/contrib/gis/db/backends/mysql/schema.py @@ -57,7 +57,7 @@ class MySQLGISSchemaEditor(DatabaseSchemaEditor): except OperationalError: logger.error( "Couldn't remove spatial index: %s (may be expected " - "if your storage engine doesn't support them)." % sql + "if your storage engine doesn't support them).", sql ) super(MySQLGISSchemaEditor, self).remove_field(model, field) @@ -72,6 +72,6 @@ class MySQLGISSchemaEditor(DatabaseSchemaEditor): except OperationalError: logger.error( "Cannot create SPATIAL INDEX %s. Only MyISAM and (as of " - "MySQL 5.7.5) InnoDB support them." % sql + "MySQL 5.7.5) InnoDB support them.", sql ) self.geometry_sql = [] diff --git a/django/contrib/gis/forms/widgets.py b/django/contrib/gis/forms/widgets.py index 1fbe19b082..77291396a9 100644 --- a/django/contrib/gis/forms/widgets.py +++ b/django/contrib/gis/forms/widgets.py @@ -40,10 +40,7 @@ class BaseGeometryWidget(Widget): try: return GEOSGeometry(value, self.map_srid) except (GEOSException, ValueError) as err: - logger.error( - "Error creating geometry from value '%s' (%s)" % ( - value, err) - ) + logger.error("Error creating geometry from value '%s' (%s)", value, err) return None def render(self, name, value, attrs=None): @@ -61,8 +58,8 @@ class BaseGeometryWidget(Widget): value = ogr except gdal.GDALException as err: logger.error( - "Error transforming geometry from srid '%s' to srid '%s' (%s)" % ( - value.srid, self.map_srid, err) + "Error transforming geometry from srid '%s' to srid '%s' (%s)", + value.srid, self.map_srid, err ) context = self.build_attrs( diff --git a/django/contrib/gis/gdal/libgdal.py b/django/contrib/gis/gdal/libgdal.py index f2f62b727d..b7fb97fb89 100644 --- a/django/contrib/gis/gdal/libgdal.py +++ b/django/contrib/gis/gdal/libgdal.py @@ -105,7 +105,7 @@ CPLErrorHandler = CFUNCTYPE(None, c_int, c_int, c_char_p) def err_handler(error_class, error_number, message): - logger.error('GDAL_ERROR %d: %s' % (error_number, message)) + logger.error('GDAL_ERROR %d: %s', error_number, message) err_handler = CPLErrorHandler(err_handler) diff --git a/django/contrib/gis/geos/libgeos.py b/django/contrib/gis/geos/libgeos.py index f4f93b57cc..78665894bc 100644 --- a/django/contrib/gis/geos/libgeos.py +++ b/django/contrib/gis/geos/libgeos.py @@ -84,7 +84,7 @@ def notice_h(fmt, lst): warn_msg = fmt % lst except TypeError: warn_msg = fmt - logger.warning('GEOS_NOTICE: %s\n' % warn_msg) + logger.warning('GEOS_NOTICE: %s\n', warn_msg) notice_h = NOTICEFUNC(notice_h) ERRORFUNC = CFUNCTYPE(None, c_char_p, c_char_p) @@ -96,7 +96,7 @@ def error_h(fmt, lst): err_msg = fmt % lst except TypeError: err_msg = fmt - logger.error('GEOS_ERROR: %s\n' % err_msg) + logger.error('GEOS_ERROR: %s\n', err_msg) error_h = ERRORFUNC(error_h) # #### GEOS Geometry C data structures, and utility functions. #### diff --git a/django/db/backends/base/schema.py b/django/db/backends/base/schema.py index 191478a6a3..35dcb2e296 100644 --- a/django/db/backends/base/schema.py +++ b/django/db/backends/base/schema.py @@ -98,7 +98,7 @@ class BaseDatabaseSchemaEditor(object): Executes the given SQL statement, with optional parameters. """ # Log the command we're running, then run it - logger.debug("%s; (params %r)" % (sql, params)) + logger.debug("%s; (params %r)", sql, params) if self.collect_sql: ending = "" if sql.endswith(";") else ";" if params is not None: diff --git a/django/db/backends/utils.py b/django/db/backends/utils.py index 84444548d3..94134811dd 100644 --- a/django/db/backends/utils.py +++ b/django/db/backends/utils.py @@ -85,7 +85,7 @@ class CursorDebugWrapper(CursorWrapper): 'sql': sql, 'time': "%.3f" % duration, }) - logger.debug('(%.3f) %s; args=%s' % (duration, sql, params), + logger.debug('(%.3f) %s; args=%s', duration, sql, params, extra={'duration': duration, 'sql': sql, 'params': params} ) @@ -104,7 +104,7 @@ class CursorDebugWrapper(CursorWrapper): 'sql': '%s times: %s' % (times, sql), 'time': "%.3f" % duration, }) - logger.debug('(%.3f) %s; args=%s' % (duration, sql, param_list), + logger.debug('(%.3f) %s; args=%s', duration, sql, param_list, extra={'duration': duration, 'sql': sql, 'params': param_list} )