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


Python current_app.logger方法代码示例

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


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

示例1: delete_array

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import logger [as 别名]
def delete_array(array_id):
    """
    Delete an array
    :param array_id:
    :return:
    """
    store = Store(array_config_path(), current_app.logger)

    arrays = store.load_arrays()

    array_deleted = None
    if array_id in arrays:
        array_deleted = arrays[array_id]
        store.remove_array_config(array_id)

    return make_rest_response(
        array_deleted.get_json() if array_deleted else None,
        200) 
开发者ID:pure-garyyang,项目名称:pureelk,代码行数:20,代码来源:rest_arrays.py

示例2: _after_request_callback

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import logger [as 别名]
def _after_request_callback(self, response):
        """Consume quota and injects HTTP headers when responding to a request
        """
        log = current_app.logger
        try:
            assert response
            tdelta = time.monotonic() - self._request_start_time
            ipaddr = self._get_client_ipaddr()
            if not self._limiter.is_ipaddr_whitelisted(ipaddr):
                self._limiter.consume_quota(tdelta, ipaddr=ipaddr)
                q = self._limiter.get_minimum_across_quotas(ipaddr=ipaddr)
                response.headers.add("X-RateLimit-Remaining", q)

        except Exception as e:
            log.error(str(e), exc_info=True)

        finally:
            return response 
开发者ID:ooni,项目名称:api,代码行数:20,代码来源:rate_limit_quotas.py

示例3: authenticate

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import logger [as 别名]
def authenticate(self, request):
        user = self._internal_auth(request)
        is_bootstrap_admin = user and user.is_bootstrap_admin
        if self.external_auth_configured \
                and not is_bootstrap_admin \
                and not self.token_based_auth:
            self.logger.debug('using external auth')
            user = user_handler.get_user_from_auth(request.authorization)
            response = self.external_auth.authenticate(request, user)
            if isinstance(response, Response):
                return response
            user = response
        if not user:
            raise_unauthorized_user_error('No authentication info provided')
        self.logger.debug('Authenticated user: {0}'.format(user))

        if request.authorization:
            # Reset the counter only when using basic authentication
            # (User + Password), otherwise the counter will be reset on
            # every UI refresh (every 4 sec) and accounts won't be locked.
            user.failed_logins_counter = 0
            user.last_login_at = datetime.now()
        user_datastore.commit()
        return user 
开发者ID:cloudify-cosmo,项目名称:cloudify-manager,代码行数:26,代码来源:authentication.py

示例4: _http_auth

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import logger [as 别名]
def _http_auth(self, user, username, password):
        """Perform basic user authentication
        - Check that the password that was passed in the request can be
          verified against the password stored in the DB

        :param user: The DB user object
        :param username: The username from the request
        :param password: The password from the request
        :return: The DB user object
        """
        self.logger.debug('Running basic HTTP authentication')
        if not user:
            raise_unauthorized_user_error(
                'Authentication failed for '
                '<User username=`{0}`>'.format(username)
            )
        if not verify_password(password, user.password):
            self._increment_failed_logins_counter(user)
            raise_unauthorized_user_error(
                'Authentication failed for {0}.'
                ' Bad credentials or locked account'.format(user)
            )
        return user 
开发者ID:cloudify-cosmo,项目名称:cloudify-manager,代码行数:25,代码来源:authentication.py

示例5: _authenticate_token

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import logger [as 别名]
def _authenticate_token(self, token):
        """Make sure that the token passed exists, is valid, is not expired,
        and that the user contained within it exists in the DB

        :param token: An authentication token
        :return: A tuple: (A user object, its hashed password)
        """
        self.logger.debug('Authenticating token')
        expired, invalid, user, data, error = \
            user_handler.get_token_status(token)

        if expired:
            raise_unauthorized_user_error('Token is expired')
        elif invalid or (not isinstance(data, list) or len(data) != 2):
            raise_unauthorized_user_error(
                'Authentication token is invalid:\n{0}'.format(error)
            )
        elif not user:
            raise_unauthorized_user_error('No authentication info provided')
        else:
            self._verify_token(token=data[1], user=user)

        return user 
开发者ID:cloudify-cosmo,项目名称:cloudify-manager,代码行数:25,代码来源:authentication.py

示例6: send_request_to_spark_cluster

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import logger [as 别名]
def send_request_to_spark_cluster(message):
    with create_app().app_context():
        rabbitmq_connection = utils.connect_to_rabbitmq(
            username=current_app.config['RABBITMQ_USERNAME'],
            password=current_app.config['RABBITMQ_PASSWORD'],
            host=current_app.config['RABBITMQ_HOST'],
            port=current_app.config['RABBITMQ_PORT'],
            virtual_host=current_app.config['RABBITMQ_VHOST'],
            error_logger=current_app.logger,
        )
        try:
            channel = rabbitmq_connection.channel()
            channel.exchange_declare(exchange=current_app.config['SPARK_REQUEST_EXCHANGE'], exchange_type='fanout')
            channel.basic_publish(
                exchange=current_app.config['SPARK_REQUEST_EXCHANGE'],
                routing_key='',
                body=message,
                properties=pika.BasicProperties(delivery_mode=2,),
            )
        except Exception:
            # this is a relatively non critical part of LB for now, so just log the error and
            # move ahead
            current_app.logger.error('Could not send message to spark cluster: %s', ujson.dumps(message), exc_info=True) 
开发者ID:metabrainz,项目名称:listenbrainz-server,代码行数:25,代码来源:request_manage.py

示例7: find_users

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import logger [as 别名]
def find_users(self):
        with self.app.app_context():
            self.ls = init_influx_connection(current_app.logger, {
                'REDIS_HOST': current_app.config['REDIS_HOST'],
                'REDIS_PORT': current_app.config['REDIS_PORT'],
                'REDIS_NAMESPACE': current_app.config['REDIS_NAMESPACE'],
                'INFLUX_HOST': current_app.config['INFLUX_HOST'],
                'INFLUX_PORT': current_app.config['INFLUX_PORT'],
                'INFLUX_DB_NAME': current_app.config['INFLUX_DB_NAME'],
            })

            for _ in range(CONNECTION_RETRY_COUNT):
                try:
                    users = db_user.get_all_users()
                    break
                except DatabaseError as e:
                    current_app.logger.error('Error while getting users list: %s', str(e), exc_info=True)
                    time.sleep(1)
            else:
                current_app.logger.critical("Cannot connect to PostgreSQL, exiting...")
                raise DatabaseError("Cannot connect to PostgreSQL, exiting")

            return [user['musicbrainz_id'] for user in users if self.condition(user['musicbrainz_id'])] 
开发者ID:metabrainz,项目名称:listenbrainz-server,代码行数:25,代码来源:replay_user.py

示例8: log_errors

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import logger [as 别名]
def log_errors(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        async def tmp():
            try:
                return await func(*args, **kwargs)

            except asyncio.CancelledError:
                raise
            except Exception as e:
                current_app.logger.exception(str(e))
                raise

        return tmp()

    return wrapper 
开发者ID:getsentry,项目名称:zeus,代码行数:18,代码来源:server.py

示例9: worker

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import logger [as 别名]
def worker(channel, queue, tenant, repo_ids=None, build_ids=None):
    allowed_repo_ids = frozenset(tenant.access.keys())

    while await channel.wait_message():
        msg = await channel.get_json()
        data = msg.get("data")
        if data["repository"]["id"] not in allowed_repo_ids:
            continue

        if build_ids and data["id"] not in build_ids:
            continue

        if repo_ids and data["repository"]["id"] not in repo_ids:
            continue

        evt = Event(msg.get("id"), msg.get("event"), data)
        with sentry_sdk.Hub.current.start_span(
            op="pubsub.receive", description=msg.get("id")
        ):
            await queue.put(evt)
        current_app.logger.debug("pubsub.event.received qsize=%s", queue.qsize()) 
开发者ID:getsentry,项目名称:zeus,代码行数:23,代码来源:server.py

示例10: worker

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import logger [as 别名]
def worker(db_pool, queue: asyncio.Queue):
    """
    Async worker to perform tasks like persisting revisions to the database.
    """

    while True:
        event, payload = await queue.get()
        try:
            if event == "revision":
                key = (payload["repo_id"], payload["revision"].sha)
                if key in _revision_cache:
                    continue
                async with db_pool.acquire() as conn:
                    await save_revision(conn, payload["repo_id"], payload["revision"])
                _revision_cache[key] = 1
            if event == "cleanup":
                repo_id = payload["repo_id"]
                async with db_pool.acquire() as conn:
                    await cleanup(conn, repo_id)
        except Exception:
            current_app.logger.error(
                "worker.event-error event=%s", event, exc_info=True
            )
        current_app.logger.debug("worker.event event=%s qsize=%s", event, queue.qsize()) 
开发者ID:getsentry,项目名称:zeus,代码行数:26,代码来源:server.py

示例11: logger

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import logger [as 别名]
def logger() -> SupportsLogging:
    if has_app_context(): # type: ignore
        return current_app.logger # type: ignore
    return logging # type: ignore 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:6,代码来源:logger.py

示例12: fatal

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import logger [as 别名]
def fatal(*args: List[Any]) -> None:
    """Panic stations! Data is being irretrievably lost or other truly terrible things."""
    logger().fatal('\n'.join(map(str, args))) 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:5,代码来源:logger.py

示例13: error

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import logger [as 别名]
def error(*args: Any) -> None:
    """Thing that should not happen or state that should not occur, must be fixed."""
    logger().error('\n'.join(map(str, args))) 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:5,代码来源:logger.py

示例14: warning

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import logger [as 别名]
def warning(*args: Any) -> None:
    """Potentially interesting information that will be logged in production."""
    logger().warning('\n'.join(map(str, args))) 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:5,代码来源:logger.py

示例15: info

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import logger [as 别名]
def info(*args: Any) -> None:
    """Potentially interesting information that will not be logged in production but will be logged in dev."""
    logger().info('\n'.join(map(str, args))) 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:5,代码来源:logger.py


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