def setProperties(self, keep_entries, copy_to_zlog=0, ignored_exceptions=(), getsentry_dsn='', track_js=0, RESPONSE=None): """Sets the properties of this site error log. """ getsentry_dsn = getsentry_dsn.strip() if getsentry_dsn != self.getsentry_dsn: self.getsentry_dsn = getsentry_dsn self.track_js = bool(track_js) exceptions = list() for entry in ignored_exceptions: if entry: value = entry if not isinstance(value, six.text_type): value = value.decode('utf-8') exceptions.append(value) SiteErrorLog.setProperties(self, keep_entries, copy_to_zlog, exceptions, RESPONSE)
def install_errorlog(self): app = self.getApp() if app._getInitializerFlag('error_log'): # do nothing if we've already installed one return # Install an error_log if not hasattr(app, 'error_log'): from Products.SiteErrorLog.SiteErrorLog import SiteErrorLog error_log = SiteErrorLog() app._setObject('error_log', error_log) # Added for Five 1.2: error_log = app.error_log error_log.manage_afterAdd(error_log, app) # End added app._setInitializerFlag('error_log') self.commit('Added site error_log at /error_log')
def raising(self, info): """ Log an exception and send the info to sentry """ exc_info = sys.exc_info() res = SiteErrorLog.raising(self, info) send_anyway = os.environ.get(SEND_ANYWAY_ENV_VAR, '') if getConfiguration().debug_mode and not send_anyway: # We are in debug mode, do not send tb to Sentry logger.info('Zope is in debug mode. Not sending error to sentry') return res dsn = self.getsentry_dsn dsn = dsn and dsn or os.environ.get(DSN_ENV_VAR, '') if not dsn: logger.warning('Missing DSN. Unable to send errors to sentry') return res if res is not None: client = get_or_create_client(dsn) event, hint = event_from_exception(exc_info, client_options=client.options) hub = Hub.current hub.start_session() with sentry_sdk.push_scope() as scope: request = getattr(self, 'REQUEST', None) if not request: request = getRequest() _prepare_scope_and_event(request, scope, event) sentry_sdk.capture_event(event, hint, scope) hub.end_session() return res
def install_errorlog(self): app = self.getApp() if app._getInitializerFlag('error_log'): # do nothing if we've already installed one return # Install an error_log if not hasattr(app, 'error_log'): from Products.SiteErrorLog.SiteErrorLog import SiteErrorLog error_log = SiteErrorLog() app._setObject('error_log', error_log) # FIXME explicitely call manage_afterAdd, as sometimes # events are initialized too late error_log = app.error_log error_log.manage_afterAdd(error_log, app) app._setInitializerFlag('error_log') self.commit('Added site error_log at /error_log')
def setupSiteErrorLog(app): '''Sets up the error_log object required by ZPublisher.''' if not hasattr(app, 'error_log'): try: from Products.SiteErrorLog.SiteErrorLog import SiteErrorLog except ImportError: pass else: app._setObject('error_log', SiteErrorLog()) transaction.commit()
def setUp(self): transaction.begin() self.app = makerequest(Zope2.app()) try: if not hasattr(self.app, 'error_log'): # If ZopeLite was imported, we have no default error_log from Products.SiteErrorLog.SiteErrorLog import SiteErrorLog self.app._setObject('error_log', SiteErrorLog()) self.app.manage_addDTMLMethod('doc', '') except: self.tearDown()
def setUp(self): transaction.begin() self.app = makerequest(Zope2.app()) try: if not hasattr(self.app, 'error_log'): # If ZopeLite was imported, we have no default error_log from Products.SiteErrorLog.SiteErrorLog import SiteErrorLog self.app._setObject('error_log', SiteErrorLog()) self.app.manage_addDTMLMethod('doc', '') self.logger = logging.getLogger('Zope.SiteErrorLog') self.log = logging.handlers.BufferingHandler(sys.maxint) self.logger.addHandler(self.log) self.old_level = self.logger.level self.logger.setLevel(logging.ERROR) except: self.tearDown()
def test_error_log_object(self): from Products.SiteErrorLog.SiteErrorLog import SiteErrorLog error_log = SiteErrorLog().__of__(self.folder) # this should render without errors error_log.manage_main()
def getProperties(self): props = SiteErrorLog.getProperties(self) props['getsentry_dsn'] = self.getsentry_dsn props['env_dsn'] = os.environ.get(DSN_ENV_VAR, '') props['track_js'] = self.track_js return props