本文整理汇总了Python中misc.Logger类的典型用法代码示例。如果您正苦于以下问题:Python Logger类的具体用法?Python Logger怎么用?Python Logger使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Logger类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Serializer
class Serializer(object):
"""
Should be responsible for representing instances of classes in desired form
"""
def __init__(self):
self.log = Logger().get_logger()
self.log.debug("Instantiated Serializer with data %s" % self.data_hash)
pass
def __repr__(self):
return str(self.data_hash)
def __str__(self):
return self.data_hash
def _assign_attributes(self):
"""
Should change the key names from original API keys to the ones we want
:return: None
"""
for new_key, old_key in self.attributes.iteritems():
try:
self.data[new_key] = self.data_hash[old_key]
except SerializerException, e:
""" possible do something fancy here """
except Exception, e:
self.log.info("Could not assign attribute %s while operating on Object: %s because %s" % (old_key, self.data_hash, e))
示例2: Searcher
class Searcher(dict):
"""
Class responsible for search methods on strings
"""
def __init__(self):
self.log = Logger().get_logger()
def wrap(self, regular_expression):
"""
Turns windows/search type of regexp into python re regexp.
It adds explicit begining '^' and end '$' to matcher and converts
all wildcards to re wildcard '(.*)'
:rtype: str
:param string: regular_expression
"""
return '^' + regular_expression.replace('*', '(.*)') + '$'
def match(self, string, regular_expression):
"""
Match string with a regular expression
:rtype: bool
:param string: given string for matching
:param regular_expression: expression to be run against the given string
"""
regular_expression = self.wrap(regular_expression)
self.log.info("Trying to match regexp: %s against string: %s" % (regular_expression, string))
regex = re.compile(regular_expression)
if re.match(regex, string):
return True
else:
return False
示例3: Space
class Space(Fetchable, Statusable, Deletable, Shutdownable,
Startupable, Activatable, Configurable, Metadatable,
Deployable, Cleanable):
"""
@summary: Space is a LiveActivityGroup aggregator
"""
def __init__(self, data_hash, uri, name=None, ):
self.log = Logger().get_logger()
self.data_hash = data_hash
self.uri = uri
self.absolute_url = self._get_absolute_url()
self.class_name = self.__class__.__name__
super(Space, self).__init__()
self.log.info("Instantiated Activity object with url=%s" % self.absolute_url)
def __repr__(self):
return str(self.data_hash)
def __str__(self):
return self.data_hash
def create(self, live_activity_group_name, live_activity_names):
"""
@summary: Should be responsible for creating space
@param live_activity_group_name: string
@param live_activity_names: list of existing names
"""
raise NotImplementedError
def to_json(self):
"""
@summary: Should selected attributes in json form defined by the template
"""
self.serializer = SpaceSerializer(self.data_hash)
return self.serializer.to_json()
def id(self):
return self.data_hash['id']
def name(self):
"""
@param: Should return live activity name
"""
return self.data_hash['name']
def description(self):
"""
@param: Should return Space description
"""
return self.data_hash['description']
""" Private methods below """
def _get_absolute_url(self):
live_activity_group_id = self.data_hash['id']
url = "%s/space/%s/view.json" % (self.uri, live_activity_group_id)
return url
示例4: __init__
def __init__(self, data_hash, uri, name=None, ):
self.log = Logger().get_logger()
self.data_hash = data_hash
self.uri = uri
self.absolute_url = self._get_absolute_url()
self.class_name = self.__class__.__name__
super(Space, self).__init__()
self.log.info("Instantiated Activity object with url=%s" % self.absolute_url)
示例5: __init__
def __init__(self, data_hash=None, uri=None):
self.log = Logger().get_logger()
self.class_name = self.__class__.__name__
super(SpaceController, self).__init__()
if data_hash==None and uri==None:
self.log.info("No data provided - assuming creation of new LiveActivity")
else:
self.data_hash = data_hash
self.uri = uri
self.absolute_url = self._get_absolute_url()
self.log.info("Instantiated Activity object with url=%s" % self.absolute_url)
示例6: __init__
def __init__(self, host='lg-head', port='8080', prefix='/interactivespaces'):
"""
@param host: default value is lg-head
@param port: default value is 8080
@param prefix: default value is /interactivespaces
@todo: refactor filter_* methods because they're not DRY
"""
self.host, self.port, self.prefix = host, port, prefix
self.log = Logger().get_logger()
self.uri = "http://%s:%s%s" % (self.host, self.port, prefix)
super(Master, self).__init__()
示例7: __init__
def __init__(self, data_hash=None, uri=None, activity_archive_uri=None, name=None):
self.log = Logger().get_logger()
super(Activity, self).__init__()
if (data_hash==None and uri==None):
self.log.info("No data provided - assuming creation of new Activity")
elif (data_hash!=None and uri!=None):
self.data_hash = data_hash
self.uri = uri
self.absolute_url = self._get_absolute_url()
self.log.info("Instantiated Activity object with url=%s" % self.absolute_url)
示例8: __init__
def __init__(self, data_hash=None, uri=None):
self.log = Logger().get_logger()
self.class_name = self.__class__.__name__
super(LiveActivityGroup, self).__init__()
if data_hash==None and uri==None:
self.log.info("No data_hash and uri provided for LiveActivityGroup constructor, assuming creation")
else:
self.data_hash = data_hash
self.uri = uri
self.absolute_url = self._get_absolute_url()
self.log.info("Instantiated Activity object with url=%s" % self.absolute_url)
示例9: __init__
def __init__(self, data_hash=None, uri=None):
self.log = Logger().get_logger()
self.class_name = self.__class__.__name__
super(Space, self).__init__()
if (data_hash==None and uri==None):
self.log.info("No data provided - assuming creation of new Space")
elif (data_hash!=None and uri!=None):
self.data_hash = data_hash
self.uri = uri
self.absolute_url = self._get_absolute_url()
self.log.info("Instantiated Space object with url=%s" % self.absolute_url)
示例10: Deployable
class Deployable(Communicable):
"""
Should be responsible for sending the "deploy" action
"""
def __init__(self):
self.log = Logger().get_logger()
super(Deployable, self).__init__()
def send_deploy(self):
deploy_route = Path().get_route_for(self.class_name, 'deploy') % self.data_hash['id']
if self._send_deploy_request(deploy_route):
self.log.info("Successfully sent 'deploy' for url=%s" % self.absolute_url)
return True
else:
return False
def _send_deploy_request(self, deploy_route):
"""
Makes a 'deploy' request
"""
url = "%s%s" % (self.uri, deploy_route)
self.log.info("Sending deploy GET request to url=%s" %url)
try:
response = self._api_get_json(url)
except urllib2.HTTPError, e:
response = None
self.log.error("Could not send deploy GET request because %s" % e)
if response:
return True
else:
return False
示例11: Shutdownable
class Shutdownable(Communicable):
"""
Should be responsible for sending "shutdown" command to live activities,
controllers, spaces and live groups.
"""
def __init__(self):
self.log = Logger().get_logger()
super(Shutdownable, self).__init__()
def send_shutdown(self):
shutdown_route = Path().get_route_for(self.class_name, 'shutdown') % self.data_hash['id']
if self._send_shutdown_request(shutdown_route):
self.log.info("Successfully sent shutdown for url=%s" % self.absolute_url)
return True
else:
return False
def _send_shutdown_request(self, shutdown_route):
"""
Makes a shutdown request
"""
url = "%s%s" % (self.uri, shutdown_route)
self.log.info("Sending 'shutdown' GET request to url=%s" %url)
try:
response = self._api_get_json(url)
except urllib2.HTTPError, e:
response = None
self.log.error("Could not send 'shutdown' GET request because %s" % e)
if e=='HTTP Error 500: No connection to controller in 5000 milliseconds':
raise CommunicableException('HTTP Error 500: No connection to controller in 5000 milliseconds')
if response:
return True
else:
return False
示例12: Startupable
class Startupable(Communicable):
"""
@summary: Should be responsible for sending "startup" command to live activities,
controllers, spaces and live groups.
"""
def __init__(self):
self.log = Logger().get_logger()
super(Startupable, self).__init__()
def send_startup(self):
startup_route = Path().get_route_for(self.class_name, 'startup') % self.data_hash['id']
if self._send_startup_request(startup_route):
self.log.info("Successfully sent 'startup' for url=%s" % self.absolute_url)
return True
else:
return False
def _send_startup_request(self, startup_route):
"""
@summary: makes a startup request
"""
url = "%s%s" % (self.uri, startup_route)
self.log.info("Sending 'startup' GET request to url=%s" %url)
try:
response = self._api_get_json(url)
except urllib2.HTTPError, e:
response = None
self.log.error("Could not send 'startup' GET request because %s" % e)
if response:
return True
else:
return False
示例13: Deletable
class Deletable(Communicable):
"""
@summary: Should be responsible for the deletion of an object
"""
def __init__(self):
self.log = Logger().get_logger()
super(Deletable, self).__init__()
def send_delete(self):
"""
@summary: sends the "delete" GET request to a route
"""
delete_route = Path().get_route_for(self.class_name, 'delete') % self.data_hash['id']
if self._send_delete_request(delete_route):
self.log.info("Successfully sent 'delete' to url=%s" % self.absolute_url)
return True
else:
return False
def _send_delete_request(self, delete_route):
"""
@rtype: bool
"""
url = "%s%s" % (self.uri, delete_route)
self.log.info("Sending 'delete' to url=%s" %url)
try:
response = self._api_get_html(url)
except urllib2.HTTPError, e:
response = None
self.log.error("Could not send 'delete' because %s" % e)
if response:
return True
else:
return False
示例14: Configurable
class Configurable(Communicable):
"""
@summary: Should be responsible for sending the "configure" action
"""
def __init__(self):
self.log = Logger().get_logger()
super(Configurable, self).__init__()
def send_configure(self):
configure_route = Path().get_route_for(self.class_name, 'configure') % self.data_hash['id']
if self._send_configure_request(configure_route):
self.log.info("Successfully sent 'configure' for url=%s" % self.absolute_url)
return True
else:
return False
def _send_configure_request(self, configure_route):
"""
@summary: makes a 'configure' request
"""
url = "%s%s" % (self.uri, configure_route)
self.log.info("Sending configure GET request to url=%s" %url)
try:
response = self._api_get_json(url)
except urllib2.HTTPError, e:
response = None
self.log.error("Could not send configure GET request because %s" % e)
if response:
return True
else:
return False
示例15: __init__
def __init__(self, data_hash=None, uri=None):
"""
@summary: when called with constructor_args and other vars set to None, new
LiveActivity will be created
@param data_hash: should be master API liveActivity json, may be blank
@param uri: should be a link to "view.json" of the given live activity
"""
self.log = Logger().get_logger()
self.class_name = self.__class__.__name__
super(LiveActivity, self).__init__()
if (data_hash==None and uri==None):
self.log.info("No data provided - assuming creation of new LiveActivity")
elif (data_hash!=None and uri!=None):
self.data_hash = data_hash
self.uri = uri
self.absolute_url = self._get_absolute_url()
self.log.info("Instantiated LiveActivity object with url=%s" % self.absolute_url)