当前位置: 首页>>代码示例>>Python>>正文


Python cherrypy.log方法代码示例

本文整理汇总了Python中cherrypy.log方法的典型用法代码示例。如果您正苦于以下问题:Python cherrypy.log方法的具体用法?Python cherrypy.log怎么用?Python cherrypy.log使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cherrypy的用法示例。


在下文中一共展示了cherrypy.log方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: log_hooks

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import log [as 别名]
def log_hooks(debug=False):
    """Write request.hooks to the cherrypy error log."""
    request = cherrypy.serving.request

    msg = []
    # Sort by the standard points if possible.
    from cherrypy import _cprequest
    points = _cprequest.hookpoints
    for k in request.hooks.keys():
        if k not in points:
            points.append(k)

    for k in points:
        msg.append('    %s:' % k)
        v = request.hooks.get(k, [])
        v.sort()
        for h in v:
            msg.append('        %r' % h)
    cherrypy.log('\nRequest Hooks for ' + cherrypy.url() +
                 ':\n' + '\n'.join(msg), 'HTTP') 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:22,代码来源:cptools.py

示例2: trailing_slash

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import log [as 别名]
def trailing_slash(missing=True, extra=False, status=None, debug=False):
    """Redirect if path_info has (missing|extra) trailing slash."""
    request = cherrypy.serving.request
    pi = request.path_info

    if debug:
        cherrypy.log('is_index: %r, missing: %r, extra: %r, path_info: %r' %
                     (request.is_index, missing, extra, pi),
                     'TOOLS.TRAILING_SLASH')
    if request.is_index is True:
        if missing:
            if not pi.endswith('/'):
                new_url = cherrypy.url(pi + '/', request.query_string)
                raise cherrypy.HTTPRedirect(new_url, status=status or 301)
    elif request.is_index is False:
        if extra:
            # If pi == '/', don't redirect to ''!
            if pi.endswith('/') and pi != '/':
                new_url = cherrypy.url(pi[:-1], request.query_string)
                raise cherrypy.HTTPRedirect(new_url, status=status or 301) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:22,代码来源:cptools.py

示例3: flatten

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import log [as 别名]
def flatten(debug=False):
    """Wrap response.body in a generator that recursively iterates over body.

    This allows cherrypy.response.body to consist of 'nested generators';
    that is, a set of generators that yield generators.
    """
    def flattener(input):
        numchunks = 0
        for x in input:
            if not is_iterator(x):
                numchunks += 1
                yield x
            else:
                for y in flattener(x):
                    numchunks += 1
                    yield y
        if debug:
            cherrypy.log('Flattened %d chunks' % numchunks, 'TOOLS.FLATTEN')
    response = cherrypy.serving.response
    response.body = flattener(response.body) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:22,代码来源:cptools.py

示例4: save

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import log [as 别名]
def save(self):
        """Save session data."""
        try:
            # If session data has never been loaded then it's never been
            #   accessed: no need to save it
            if self.loaded:
                t = datetime.timedelta(seconds=self.timeout * 60)
                expiration_time = self.now() + t
                if self.debug:
                    cherrypy.log('Saving session %r with expiry %s' %
                                 (self.id, expiration_time),
                                 'TOOLS.SESSIONS')
                self._save(expiration_time)
            else:
                if self.debug:
                    cherrypy.log(
                        'Skipping save of session %r (no session loaded).' %
                        self.id, 'TOOLS.SESSIONS')
        finally:
            if self.locked:
                # Always release the lock if the user didn't release it
                self.release_lock()
                if self.debug:
                    cherrypy.log('Lock released after save.', 'TOOLS.SESSIONS') 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:26,代码来源:sessions.py

示例5: acquire_lock

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import log [as 别名]
def acquire_lock(self, path=None):
        """Acquire an exclusive lock on the currently-loaded session data."""
        if path is None:
            path = self._get_file_path()
        path += self.LOCK_SUFFIX
        checker = locking.LockChecker(self.id, self.lock_timeout)
        while not checker.expired():
            try:
                self.lock = zc.lockfile.LockFile(path)
            except zc.lockfile.LockError:
                time.sleep(0.1)
            else:
                break
        self.locked = True
        if self.debug:
            cherrypy.log('Lock acquired.', 'TOOLS.SESSIONS') 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:18,代码来源:sessions.py

示例6: _attempt

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import log [as 别名]
def _attempt(filename, content_types, debug=False):
    if debug:
        cherrypy.log('Attempting %r (content_types %r)' %
                     (filename, content_types), 'TOOLS.STATICDIR')
    try:
        # you can set the content types for a
        # complete directory per extension
        content_type = None
        if content_types:
            r, ext = os.path.splitext(filename)
            content_type = content_types.get(ext[1:], None)
        serve_file(filename, content_type=content_type, debug=debug)
        return True
    except cherrypy.NotFound:
        # If we didn't find the static file, continue handling the
        # request. We might find a dynamic handler instead.
        if debug:
            cherrypy.log('NotFound', 'TOOLS.STATICFILE')
        return False 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:21,代码来源:static.py

示例7: error

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import log [as 别名]
def error(self, msg='', context='', severity=logging.INFO,
              traceback=False):
        """Write the given ``msg`` to the error log.

        This is not just for errors! Applications may call this at any time
        to log application-specific information.

        If ``traceback`` is True, the traceback of the current exception
        (if any) will be appended to ``msg``.
        """
        exc_info = None
        if traceback:
            exc_info = _cperror._exc_info()

        self.error_log.log(
            severity,
            ' '.join((self.time(), context, msg)),
            exc_info=exc_info,
        ) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:21,代码来源:_cplogging.py

示例8: __init__

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import log [as 别名]
def __init__(self):
		cherrypy.log("Initializing Webserver")
		
		cherrypy.config.update({'request.error_response': self.handle_error})
		cherrypy.config.update({'error_page.404': self.error_404})
		cherrypy.config.update({'error_page.401': self.error_401})
		
		self.sensors = SensorsPage()
		self.zones = ZonesPage()
		self.setups = SetupsPage()
		self.alarms = AlarmsPage()
		self.workers = WorkersPage()
		self.actions = ActionsPage()
		self.notifiers = NotifiersPage()
		self.sensorparams = SensorParamsPage()
		self.actionparams = ActionParamsPage()
		self.notifierparams = NotifierParamsPage()
		self.logs = LogEntriesPage()
		self.setupszones = SetupsZonesPage()
		self.workersactions = WorkersActionsPage()
		
		self.alarmdata = AlarmDataPage()
		
		self.connect()
		cherrypy.log("Finished initialization") 
开发者ID:SecPi,项目名称:SecPi,代码行数:27,代码来源:main.py

示例9: add

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import log [as 别名]
def add(self):
		if(hasattr(cherrypy.request, 'json')):
			data = cherrypy.request.json
				
			if(data and len(data)>0):
				cherrypy.log("got something %s"%data)
				newObj = self.baseclass()
				
				for k, v in data.iteritems():
					if(not k == "id"):
						setattr(newObj, k, utils.str_to_value(v))
				
				self.db.add(newObj)
				self.db.commit()
				return {'status': 'success','message':"Added new object with id %i"%newObj.id}	
			
		return {'status': 'error', 'message': 'No data recieved!'} 
开发者ID:SecPi,项目名称:SecPi,代码行数:19,代码来源:base_webpage.py

示例10: update

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import log [as 别名]
def update(self):
		if(hasattr(cherrypy.request, 'json')):
			data = cherrypy.request.json
			
			id = data['id']
			
			# check for valid id
			if(id and id > 0):
				
				if(data and len(data)>0):
					cherrypy.log("update something %s"%data)
					obj = self.db.query(self.baseclass).get(id)
					
					for k, v in data.iteritems():
						if(not k == "id"): # and v is not None --> can be null!?
							setattr(obj, k, utils.str_to_value(v))
					
					self.db.commit()
					
					return {'status': 'success', 'message': "Updated object with id %i"%obj.id}
					
			else:
				return {'status':'error', 'message': "Invalid ID!" }
		
		return {'status': 'error', 'message': 'No data recieved!'} 
开发者ID:SecPi,项目名称:SecPi,代码行数:27,代码来源:base_webpage.py

示例11: run_server

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import log [as 别名]
def run_server():
    # Enable WSGI access logging via Paste
    app_logged = TransLogger(app)

    # Mount the WSGI callable object (app) on the root directory
    cherrypy.tree.graft(app_logged, '/')

    # Set the configuration of the web server
    cherrypy.config.update({
        'engine.autoreload_on': True,
        'log.screen': True,
        'log.error_file': "cherrypy.log",
        'server.socket_port': 5000,
        'server.socket_host': '0.0.0.0',
        'server.thread_pool': 50, # 10 is default
    })

    # Start the CherryPy WSGI web server
    cherrypy.engine.start()
    cherrypy.engine.block()

# Connection 
开发者ID:Azure,项目名称:sql_python_deep_learning,代码行数:24,代码来源:api_service.py

示例12: log_hooks

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import log [as 别名]
def log_hooks(debug=False):
    """Write request.hooks to the cherrypy error log."""
    request = cherrypy.serving.request

    msg = []
    # Sort by the standard points if possible.
    from cherrypy import _cprequest
    points = _cprequest.hookpoints
    for k in request.hooks.keys():
        if k not in points:
            points.append(k)

    for k in points:
        msg.append("    %s:" % k)
        v = request.hooks.get(k, [])
        v.sort()
        for h in v:
            msg.append("        %r" % h)
    cherrypy.log('\nRequest Hooks for ' + cherrypy.url() +
                 ':\n' + '\n'.join(msg), "HTTP") 
开发者ID:naparuba,项目名称:opsbro,代码行数:22,代码来源:cptools.py

示例13: close

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import log [as 别名]
def close(self):
        """Close and de-reference the current request and response. (Core)"""
        streaming = _cherrypy.serving.response.stream
        self.cpapp.release_serving()

        # We avoid the expense of examining the iterator to see if it's
        # closable unless we are streaming the response, as that's the
        # only situation where we are going to have an iterator which
        # may not have been exhausted yet.
        if streaming and is_closable_iterator(self.iter_response):
            iter_close = self.iter_response.close
            try:
                iter_close()
            except Exception:
                _cherrypy.log(traceback=True, severity=40) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:17,代码来源:_cpwsgi.py

示例14: __init__

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import log [as 别名]
def __init__(self, root, script_name='', config=None):
        """Initialize Application with given root."""
        self.log = _cplogging.LogManager(id(self), cherrypy.log.logger_root)
        self.root = root
        self.script_name = script_name
        self.wsgiapp = _cpwsgi.CPWSGIApp(self)

        self.namespaces = self.namespaces.copy()
        self.namespaces['log'] = lambda k, v: setattr(self.log, k, v)
        self.namespaces['wsgi'] = self.wsgiapp.namespace_handler

        self.config = self.__class__.config.copy()
        if config:
            self.merge(config) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:16,代码来源:_cptree.py

示例15: release_serving

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import log [as 别名]
def release_serving(self):
        """Release the current serving (request and response)."""
        req = cherrypy.serving.request

        cherrypy.engine.publish('after_request')

        try:
            req.close()
        except Exception:
            cherrypy.log(traceback=True, severity=40)

        cherrypy.serving.clear() 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:14,代码来源:_cptree.py


注:本文中的cherrypy.log方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。