Exemplo n.º 1
0
async def scrape_channel(channel, start, file, limit=None):
    logger = JsonLogger()
    handler = AsyncFileHandler(filename=file)
    logger.add_handler(handler)
    limit = int(limit) if limit and limit.isdigit() else None
    async for m in channel.history(limit=limit):
        logger = await log_message(m, logger=logger)
    await logger.shutdown()
    return file, int(time.time() - start)
Exemplo n.º 2
0
 def get_logger(nats_handler, service_type):
     """
     Creates and returns a nats logging handler
     Args:
         nats_handler: a nats_handler object
         service_type: type of service 
     """
     handler = NatsLoggingHandler(nats_handler, service_type)
     formatter = ExtendedJsonFormatter(exclude_fields=["file_path"])
     handler.formatter = formatter
     logger = JsonLogger(name=nats_handler.sender_id)
     logger.add_handler(handler)
     return logger
Exemplo n.º 3
0
import json
import asyncio
import discord

from aiologger.loggers.json import JsonLogger
from aiologger.handlers.files import AsyncFileHandler

logger = JsonLogger()
handler = AsyncFileHandler(filename="./epic/import/history/message_dump.json")
logger.add_handler(handler)


def get_author(author):
    return ({
        "name": author.name,
        "discriminator": author.discriminator,
        "bot": author.bot,
        "icon_url": getattr(author, "icon_url", None),
        "guild": {
            "name": author.guild.name,
            "id": author.guild.id,
        } if getattr(author, "guild", None) else None,
    } if author else None)


def get_field(field):
    return {
        "name": getattr(field, "name", None),
        "value": getattr(field, "value", None),
        "inline": getattr(field, "inline", False),
    }
Exemplo n.º 4
0
from aiologger.handlers.files import RolloverInterval

__all__ = ['build_sample_middleware']

MODEL_NAME = os.environ.get('model_name', None)
MODEL_VERSION = os.environ.get('model_version', None)
SAMPLE_LOG_BACKUP_COUNT = os.environ.get('model_sample_log_backup_count', 7)

sample_logger = JsonLogger(name='jcake', flatten=True)
api_logger = logging.getLogger("demo.predict")

handler = AsyncTimedRotatingFileHandler(filename="sample/sample",
                                        backup_count=SAMPLE_LOG_BACKUP_COUNT,
                                        when=RolloverInterval.DAYS,
                                        encoding='utf-8')
sample_logger.add_handler(handler)


def build_sample_info(request_ms, request, response, model_name,
                      model_version):
    """
    构造采样的信息.
    该采样实现目前只支持POST类型的请求.

    Args:
     request_ms: 请求耗时(ms)
     request: 请求信息
     response: 响应结果
    """

    request_body = request.json