diff --git a/geoportailv3/PF.py b/geoportailv3/PF.py index a89227e16..726ccdeef 100644 --- a/geoportailv3/PF.py +++ b/geoportailv3/PF.py @@ -6,7 +6,9 @@ import logging import os import sys -import traceback + + +log = logging.getLogger(__name__) # Classe pour accéder aux attributs de la publicité foncière## @@ -54,8 +56,8 @@ def get_measurement_list(self, number_prim, number_sec, req.townCode = town_code try: resp = self.client_mesurage.service.searchMeasurement(req) - except: - traceback.print_exc(file=sys.stdout) + except Exception as e: + log.exception(e) return [] if not hasattr(resp, 'measurementList'): diff --git a/geoportailv3/views/geocode.py b/geoportailv3/views/geocode.py index 5249acf82..ee9c2fede 100644 --- a/geoportailv3/views/geocode.py +++ b/geoportailv3/views/geocode.py @@ -1,7 +1,5 @@ # -*- coding: utf-8 -*- -import sys -import traceback from pyramid.view import view_config from pyramid.httpexceptions import HTTPBadRequest from pyramid.response import Response @@ -409,8 +407,8 @@ def transform_to_latlon(self, x, y): isinstance(result.geom, str): result.geom = loads(result.geom) return result - except: - traceback.print_exc(file=sys.stdout) + except Exception as e: + log.exception(e) DBSession.rollback() return None @@ -694,9 +692,9 @@ def search_in_well_known_poi_table( feature.accuracy = 7 results.append(self.encode_result(feature)) - except: + except Exception as e: + log.exception(e) p_session.rollback() - traceback.print_exc(file=sys.stdout) return results @@ -1089,8 +1087,8 @@ def search(self): if results is not None and len(results) == 0: results.append(self.encoded_country_result()) - except: - traceback.print_exc() + except Exception as e: + log.exception(e) DBSession.rollback() results = [self.encoded_country_result()] diff --git a/geoportailv3/views/getfeatureinfo.py b/geoportailv3/views/getfeatureinfo.py index 3090103ce..0959d9164 100644 --- a/geoportailv3/views/getfeatureinfo.py +++ b/geoportailv3/views/getfeatureinfo.py @@ -1,8 +1,6 @@ # -*- coding: utf-8 -*- import sqlahelper import logging -import sys -import traceback import urllib2 from urllib import urlencode @@ -366,8 +364,8 @@ def get_lux_feature_definition(self, layers): LuxGetfeatureDefinition.role == None ).all(): # noqa luxgetfeaturedefinitions.append(res) - except: - traceback.print_exc(file=sys.stdout) + except Exception as e: + log.exception(e) return HTTPBadRequest() return luxgetfeaturedefinitions @@ -613,8 +611,8 @@ def _get_external_data(self, layer_id, url, id_column='objectid', try: result = urllib2.urlopen(query, None, 15) content = result.read() - except: - traceback.print_exc(file=sys.stdout) + except Exception as e: + log.exception(e) return [] features = [] diff --git a/geoportailv3/views/luxprintproxy.py b/geoportailv3/views/luxprintproxy.py index 1d6a8bc40..0caa62fa2 100644 --- a/geoportailv3/views/luxprintproxy.py +++ b/geoportailv3/views/luxprintproxy.py @@ -47,8 +47,6 @@ import json import logging -import sys -import traceback from cStringIO import StringIO from datetime import datetime @@ -99,8 +97,8 @@ def lux_report_create(self): def lux_status(self): try: return self.status() - except: - traceback.print_exc(file=sys.stdout) + except Exception as e: + log.exception(e) ref = self.request.matchdict.get("ref") job = DBSession.query(LuxPrintJob).get(ref) job.is_error = True @@ -188,9 +186,9 @@ def lux_report_get(self): return self._build_response( resp, content, NO_CACHE, "print" ) - except: - traceback.print_exc(file=sys.stdout) - print "reference is : " + ref + except Exception as e: + log.exception(e) + log.error("reference is : " + ref) if job is not None: job.is_error = True return HTTPInternalServerError() diff --git a/geoportailv3/views/mymaps.py b/geoportailv3/views/mymaps.py index ffefa2f1a..91f7e53c9 100644 --- a/geoportailv3/views/mymaps.py +++ b/geoportailv3/views/mymaps.py @@ -20,12 +20,13 @@ from pyramid.response import Response from pyramid.view import view_config from PIL import Image -import sys -import traceback from geoportailv3.mymaps import DBSession from sqlalchemy.orm import make_transient from sqlalchemy import and_, or_, func from c2cgeoportal.lib.caching import set_common_headers, NO_CACHE +import logging +log = logging.getLogger(__name__) + _CONTENT_TYPES = { "gpx": "application/gpx", @@ -426,9 +427,9 @@ def save_feature(self): map.features.append(obj) DBSession.commit() return {'success': True, 'id': obj.id} - except: + except Exception as e: + log.exception(e) DBSession.rollback() - traceback.print_exc(file=sys.stdout) return {'success': False, 'id': None} @view_config(route_name="mymaps_save_features", renderer='json') @@ -461,9 +462,9 @@ def save_features(self): DBSession.commit() return {'success': True} - except: + except Exception as e: + log.exception(e) DBSession.rollback() - traceback.print_exc(file=sys.stdout) return {'success': False} @view_config(route_name="mymaps_delete_feature", renderer='json') @@ -621,8 +622,8 @@ def save(self, map, id=None): try: DBSession.add(map) DBSession.commit() - except: - traceback.print_exc(file=sys.stdout) + except Exception as e: + log.exception(e) return {'success': False} return {'success': True, 'uuid': map.uuid} @@ -845,8 +846,8 @@ def get_symbols(self): 'url': "/symbol/%s" % (str(symbol.id)), 'symboltype': 'us'}) - except: - traceback.print_exc(file=sys.stdout) + except Exception as e: + log.exception(e) if 'cb' not in self.request.params: headers = {'Content-Type': 'application/json;charset=utf-8;'} @@ -928,9 +929,9 @@ def upload_symbol(self): try: self.generate_symbol_file() - except: + except Exception as e: + log.exception(e) DBSession.rollback() - traceback.print_exc(file=sys.stdout) return {'success': 'true', 'description': 'file added', @@ -972,8 +973,8 @@ def comment(self): 'feedback_name': feedback_name, 'feedback_mail': feedback_mail}, plain=comment) - except: - traceback.print_exc(file=sys.stdout) + except Exception as e: + log.exception(e) return HTTPNotFound() message.encoding = 'utf-8' message.send() diff --git a/geoportailv3/views/wms.py b/geoportailv3/views/wms.py index b945f263c..0273ef2f6 100644 --- a/geoportailv3/views/wms.py +++ b/geoportailv3/views/wms.py @@ -7,7 +7,6 @@ from pyramid.httpexceptions import HTTPNotFound, HTTPUnauthorized import logging import urllib2 -import traceback log = logging.getLogger(__name__) @@ -113,8 +112,8 @@ def internal_proxy_wms(self): # Retry to get the result f = urllib2.urlopen(url, None, timeout) data = f.read() - except: - traceback.print_exc() + except Exception as e: + log.exception(e) log.error(url) return HTTPBadGateway()