本文整理匯總了Python中twisted.logger.LogLevel.error方法的典型用法代碼示例。如果您正苦於以下問題:Python LogLevel.error方法的具體用法?Python LogLevel.error怎麽用?Python LogLevel.error使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類twisted.logger.LogLevel
的用法示例。
在下文中一共展示了LogLevel.error方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_event_on_connection
# 需要導入模塊: from twisted.logger import LogLevel [as 別名]
# 或者: from twisted.logger.LogLevel import error [as 別名]
def test_event_on_connection(self):
listener = PostgresListenerService()
start_calls = []
stop_calls = []
listener.events.connected.registerHandler(
lambda: start_calls.append(True)
)
listener.events.disconnected.registerHandler(
lambda reason: stop_calls.append(reason)
)
yield listener.startService()
self.assertEqual(len(start_calls), 1)
yield listener.stopService()
self.assertEqual(len(stop_calls), 1)
[failure] = stop_calls
self.assertIsInstance(failure.value, error.ConnectionDone)
示例2: classify_topic
# 需要導入模塊: from twisted.logger import LogLevel [as 別名]
# 或者: from twisted.logger.LogLevel import error [as 別名]
def classify_topic(self, topic):
if TopicMatchers.data.search(topic): return MessageType.DATA_CONTAINER
if TopicMatchers.discrete.search(topic): return MessageType.DATA_DISCRETE
if TopicMatchers.event.search(topic): return MessageType.EVENT
if TopicMatchers.error.search(topic): return MessageType.ERROR
示例3: emit_message
# 需要導入模塊: from twisted.logger import LogLevel [as 別名]
# 或者: from twisted.logger.LogLevel import error [as 別名]
def emit_message(self, message):
# Compute storage location from topology information.
storage_location = self.strategy.topology_to_storage(message.topology, message_type=message.type)
log.debug(u'Storage location: {storage}', storage=dict(storage_location))
# Store data or event.
if message.type in (MessageType.DATA_CONTAINER, MessageType.EVENT):
self.store_message(storage_location, message.data)
# Provision graphing subsystem.
if message.type == MessageType.DATA_CONTAINER:
# TODO: Purge message from fields to be used as tags
# Namely:
# 'geohash',
# 'location', 'location_id', 'location_name', 'sensor_id', 'sensor_type',
# 'latitude', 'longitude', 'lat', 'lon'
for graphing_subsystem in self.graphing:
# Mix in references to each other. A bit of a hack, but okay for now :-).
graphing_subsystem.strategy = self.strategy
subsystem_name = graphing_subsystem.__class__.__name__
log.debug(u'Provisioning Grafana with {name}', name=subsystem_name)
try:
graphing_subsystem.provision(storage_location, message.data, topology=message.topology)
except Exception as ex:
log.failure(u'Grafana provisioning failed for storage={storage}, message={message}:\n{log_failure}',
storage=storage_location.dump(), message=message.data,
level=LogLevel.error)
return Failure(Exception('Grafana provisioning failed'))
return True
示例4: mqtt_process_error
# 需要導入模塊: from twisted.logger import LogLevel [as 別名]
# 或者: from twisted.logger.LogLevel import error [as 別名]
def mqtt_process_error(self, failure, topic, payload):
"""
Failure handling
:param failure: Failure object from Twisted
:param topic: Full MQTT topic
:param payload: Raw MQTT payload
"""
# Log failure
log.failure(u'Processing MQTT message failed from topic "{topic}":\n{log_failure}', topic=topic, failure=failure, level=LogLevel.error)
# MQTT error signalling
self.mqtt_publish_error(failure, topic, payload)
示例5: mqtt_exception
# 需要導入模塊: from twisted.logger import LogLevel [as 別名]
# 或者: from twisted.logger.LogLevel import error [as 別名]
def mqtt_exception(self, failure, topic, payload):
log.failure(u'Problem publishing error message:\n{log_failure}', failure=failure, level=LogLevel.warn)
示例6: _set_log_level
# 需要導入模塊: from twisted.logger import LogLevel [as 別名]
# 或者: from twisted.logger.LogLevel import error [as 別名]
def _set_log_level(self, level):
# up to the desired level, we don't do anything, as we're a
# "real" Twisted new-logger; for methods *after* the desired
# level, we bind to the no_op method
desired_index = log_levels.index(level)
for (idx, name) in enumerate(log_levels):
if name == 'none':
continue
if idx > desired_index:
current = getattr(self, name, None)
if not current == _no_op or current is None:
setattr(self, name, _no_op)
if name == 'error':
setattr(self, 'failure', _no_op)
else:
if getattr(self, name, None) in (_no_op, None):
if name == 'trace':
setattr(self, "trace", self._trace)
else:
setattr(self, name,
partial(self._log, LogLevel.lookupByName(name)))
if name == 'error':
setattr(self, "failure", self._failure)
self._log_level = level
示例7: __call__
# 需要導入模塊: from twisted.logger import LogLevel [as 別名]
# 或者: from twisted.logger.LogLevel import error [as 別名]
def __call__(self, event):
# it seems if a twisted.logger.Logger() has .failure() called
# on it, the log_format will be None for the traceback after
# "Unhandled error in Deferred" -- perhaps this is a Twisted
# bug?
if event['log_format'] is None:
msg = '{0} {1}{2}'.format(
formatTime(event["log_time"]),
failure_format_traceback(event['log_failure']),
os.linesep,
)
if self._encode:
msg = msg.encode('utf8')
self._file.write(msg)
else:
# although Logger will already have filtered out unwanted
# levels, bare Logger instances from Twisted code won't have.
if 'log_level' in event and self._acceptable_level(event['log_level']):
msg = '{0} {1}{2}'.format(
formatTime(event["log_time"]),
formatEvent(event),
os.linesep,
)
if self._encode:
msg = msg.encode('utf8')
self._file.write(msg)
示例8: failure_message
# 需要導入模塊: from twisted.logger import LogLevel [as 別名]
# 或者: from twisted.logger.LogLevel import error [as 別名]
def failure_message(self, fail):
"""
:param fail: must be an IFailedFuture
returns a unicode error-message
"""
try:
return '{0}: {1}'.format(
fail.value.__class__.__name__,
fail.getErrorMessage(),
)
except Exception:
return 'Failed to produce failure message for "{0}"'.format(fail)
示例9: create_future
# 需要導入模塊: from twisted.logger import LogLevel [as 別名]
# 或者: from twisted.logger.LogLevel import error [as 別名]
def create_future(self, result=_unspecified, error=_unspecified, canceller=None):
if result is not _unspecified and error is not _unspecified:
raise ValueError("Cannot have both result and error.")
f = Deferred(canceller=canceller)
if result is not _unspecified:
resolve(f, result)
elif error is not _unspecified:
reject(f, error)
return f
示例10: create_future_error
# 需要導入模塊: from twisted.logger import LogLevel [as 別名]
# 或者: from twisted.logger.LogLevel import error [as 別名]
def create_future_error(self, error=None):
return fail(create_failure(error))
示例11: test_logging
# 需要導入模塊: from twisted.logger import LogLevel [as 別名]
# 或者: from twisted.logger.LogLevel import error [as 別名]
def test_logging(self):
"""
Logging module configures properly.
"""
defaultLogLevel = Logger.filterPredicate.logLevelForNamespace(None)
self.assertNotEqual(
defaultLogLevel, LogLevel.error,
"This test assumes the default log level is not error."
)
config.setDefaults(DEFAULT_CONFIG)
config.reload()
self.assertEquals(Logger.filterPredicate.logLevelForNamespace(None), defaultLogLevel)
self.assertEquals(Logger.filterPredicate.logLevelForNamespace("some.namespace"), defaultLogLevel)
config.load(self.testConfig)
self.assertEquals(Logger.filterPredicate.logLevelForNamespace(None), LogLevel.error)
self.assertEquals(Logger.filterPredicate.logLevelForNamespace("some.namespace"), LogLevel.debug)
writePlist({}, self.testConfig)
config.reload()
self.assertEquals(Logger.filterPredicate.logLevelForNamespace(None), defaultLogLevel)
self.assertEquals(Logger.filterPredicate.logLevelForNamespace("some.namespace"), defaultLogLevel)
示例12: testSyncToken
# 需要導入模塊: from twisted.logger import LogLevel [as 別名]
# 或者: from twisted.logger.LogLevel import error [as 別名]
def testSyncToken(self):
config.load(self.testConfig)
self.assertEquals(
sorted(config._syncTokenKeys),
['Notifications.Services.APNS.CalDAV.Topic',
'Notifications.Services.APNS.CardDAV.Topic',
'Notifications.Services.APNS.Enabled',
'ServerInfoToken']
)
# no sync token keys specified; need to empty this array here because
# stdconfig is registering keys automatically
config._syncTokenKeys = []
self.assertEquals("d41d8cd98f00b204e9800998ecf8427e", config.syncToken())
# add sync token keys (some with multiple levels)
config.addSyncTokenKey("DefaultLogLevel")
config.addSyncTokenKey("Notifications.Services.APNS.Enabled")
config.addSyncTokenKey("Notifications.Services.APNS.CalDAV.Topic")
config.addSyncTokenKey("Notifications.Services.APNS.CardDAV.Topic")
self.assertEquals("7473205187d7a6ff0c61a2b6b04053c5", config.syncToken())
# modify a sync token key value
config.Notifications.Services.APNS.CalDAV.Topic = "changed"
# direct manipulation of config requires explicit invalidation
self.assertEquals("7473205187d7a6ff0c61a2b6b04053c5", config.syncToken())
config.invalidateSyncToken()
self.assertEquals("4cdbb3841625d001dc768439f5a88cba", config.syncToken())
# add a non existent key (not an error because it could exist later)
config.addSyncTokenKey("Notifications.Services.APNS.CalDAV.NonExistent")
config.invalidateSyncToken()
self.assertEquals("2ffb128cee5a4b217cef82fd31ae7767", config.syncToken())
# reload automatically invalidates
config.reload()
self.assertEquals(config._cachedSyncToken, None)
示例13: twisted_log_observer
# 需要導入模塊: from twisted.logger import LogLevel [as 別名]
# 或者: from twisted.logger.LogLevel import error [as 別名]
def twisted_log_observer(event):
current_loglevel = event.get("log_level")
# Filter
# if current_loglevel != LogLevel.critical or current_loglevel != LogLevel.error:
# return
f = twisted_logger_mapping[current_loglevel]
if 'log_text' in event:
f("[TWISTED] %s", event['log_text'])
示例14: errors
# 需要導入模塊: from twisted.logger import LogLevel [as 別名]
# 或者: from twisted.logger.LogLevel import error [as 別名]
def errors(self):
"""Return a list of events that are at `LogLevel.error` or above.
This returns a list of event *dictionaries*, not strings.
"""
return [
event
for event in self.events
if "log_level" in event
and event["log_level"] is not None
and event["log_level"] >= LogLevel.error
]
示例15: test_tryConnection_logs_error
# 需要導入模塊: from twisted.logger import LogLevel [as 別名]
# 或者: from twisted.logger.LogLevel import error [as 別名]
def test_tryConnection_logs_error(self):
listener = PostgresListenerService()
exception_type = factory.make_exception_type()
exception_message = factory.make_name("message")
startConnection = self.patch(listener, "startConnection")
startConnection.side_effect = exception_type(exception_message)
with TwistedLoggerFixture() as logger:
with ExpectedException(exception_type):
yield listener.tryConnection()
self.assertThat(logger.events, HasLength(1))
self.assertThat(
logger.events[0],
ContainsDict(
{
"log_format": Equals(
"Unable to connect to database: {error}"
),
"log_level": Equals(LogLevel.error),
"error": Equals(exception_message),
}
),
)