當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。