Exemple #1
0
                                           stock_prices)

            last_predictions = predictions_to_plot
            current_date += timedelta(seconds=INTERVAL_IN_SECONDS)
        else:
            execution_time = (datetime.now() - current_date).total_seconds()

            if INTERVAL_IN_SECONDS - execution_time > 0:
                sleep(INTERVAL_IN_SECONDS - execution_time + 1)

            current_date = datetime.now()

    logging.info("Trading bots have finished trading")
    for bot in bots:
        bot.trader.save_data(f"datasets/traders/{bot.trader.name}.json")

    logging.info("Successfully saved trading bots' data")


if __name__ == '__main__':
    seqlog.log_to_seq(
        server_url="http://localhost:5341/",
        api_key="",
        level=logging.INFO,
        batch_size=10,
        auto_flush_timeout=10,
        override_root_logger=True,
    )

    main(datetime(2021, 3, 18, 9, 35))
Exemple #2
0
from seqlog import StructuredRootLogger, StructuredLogger, ConsoleStructuredLogHandler

if bool(os.environ.get('PROD')):

    # Production logging setup
    url = os.environ.get('SEQ_URL')
    key = os.environ.get('SEQ_BOT_KEY')

    if not key:
        raise Exception('SEQ_BOT_KEY not found but SEQ_URL was specified')

    seqlog.log_to_seq(
        # Initialize the seq logging url before the secrets are loaded
        # this is ok because seq logging only happens in prod
        server_url=url,
        api_key=key,
        level=logging.INFO,
        batch_size=5,
        auto_flush_timeout=10,  # seconds
        override_root_logger=False,
    )
else:
    # Development logging setup
    logging.setLoggerClass(StructuredLogger)

    logging.root = StructuredRootLogger(logging.WARNING)
    logging.Logger.root = logging.root
    logging.Logger.manager = logging.Manager(logging.Logger.root)

    logging.basicConfig(
        format='%(asctime)s %(levelname)s %(message)s',
        handlers=[ConsoleStructuredLogHandler()],
Exemple #3
0
#!/usr/bin/env python3
import json
import logging
import os
import socketserver
import seqlog

seq_server = os.environ['SEQ_SERVER']
seq_apikey = os.environ['SEQ_APIKEY']


class SyslogUDPHandler(socketserver.BaseRequestHandler):
    def handle(self):
        data = bytes.decode(self.request[0].strip())
        logging.info(data)


if __name__ == "__main__":
    seqlog.log_to_seq(server_url=seq_server,
                      api_key=seq_apikey,
                      level=logging.INFO,
                      batch_size=10,
                      auto_flush_timeout=10,
                      override_root_logger=True)

    server = socketserver.ThreadingUDPServer(('127.0.0.1', 514),
                                             SyslogUDPHandler)
    server.serve_forever()
Exemple #4
0
import logging
import socket
import os
from time import sleep

import seqlog

server_url = os.getenv("SEQ_SERVER_URL", "http://localhost:5341/")
api_key = os.getenv("SEQ_API_KEY", "")

print("Logging to Seq server '{}' (API key = '{}').".format(
    server_url, api_key))

log_handler = seqlog.log_to_seq(server_url,
                                api_key,
                                level=logging.INFO,
                                auto_flush_timeout=0.2,
                                additional_handlers=[logging.StreamHandler()],
                                override_root_logger=True)

print("Running...")

logging.info("Hi, {name}. {greeting}",
             name="Root logger",
             greeting="Nice to meet you")

logger1 = logging.getLogger("A")
logger1.info("Hi, {name}! {greeting}",
             name="world",
             greeting="Nice to meet you")

logger2 = logging.getLogger("A.B")
Exemple #5
0
import logging
import seqlog
import time

seqlog.log_to_seq(
    server_url="http://127.0.0.1:5341/",
    api_key="RK2UCFPEIY7dsttQJA9F",
    level=logging.NOTSET,
    batch_size=10,
    auto_flush_timeout=1,  # seconds
    override_root_logger=True,
    # json_encoder_class=json.encoder.JSONEncoder  # Optional; only specify this if you want to use a custom JSON encoder
)

logging.debug("A log message in level debug")
logging.info("A log message in level info")
logging.warning("A log message in level warning")
logging.error("A log message in level error")
logging.critical("A log message in level critical")
logging.info("Hello, {name}!", name="World")

logging.info("Processed order {orderId} by {customer}",
             orderId=15,
             customer="Johnny")

try:
    result = 2 / 0
except Exception as exception:
    logging.exception("We got an exception")

time.sleep(2)  # sleep for 2 seconds to give seqlog time to write to Seq
Exemple #6
0
import sys
from datetime import datetime

import discord
import seqlog
from discord.ext import commands

from config.config import *
from libs.server import servers, Server
from libs.leaderboard import leaderboards, Leaderboard, stats

# Seq configuration
seqlog.log_to_seq(
    server_url="http://seq.pyre-bot.com:80",
    api_key=seq_api,
    level=log_level,
    batch_size=5,
    auto_flush_timeout=5,  # seconds
    override_root_logger=True)

logging.info(
    f'[Pyre-Bot:Admin][{datetime.now(tz).strftime(t_fmt)}] Bot started')

intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(command_prefix=('>', '$'),
                   case_insensitive=True,
                   intents=intents)
cogs = ['cogs.ror2', 'cogs.ror2_admin', 'cogs.misc', 'cogs.chat']

# # Error handling
Exemple #7
0
class OneLineExceptionFormatter(logging.Formatter):
    def formatException(self, exc_info):
        result = super().formatException(exc_info)
        return repr(result)

    def format(self, record):
        result = super().format(record)
        if record.exc_text:
            result = result.replace("\n", "")
        return result


handler = logging.StreamHandler(sys.stdout)
formatter = OneLineExceptionFormatter(logging.BASIC_FORMAT)
handler.setFormatter(formatter)


seq_handler = seqlog.log_to_seq(
    server_url=f'http://{mwexpress_config.seq_host}:5341/',
    level=logging.INFO,
    batch_size=10,
    auto_flush_timeout=1,  # seconds
    override_root_logger=False,
    additional_handlers=[handler],
)

logging.getLogger().setLevel(logging.ERROR)
logging.getLogger("mwexpress").setLevel(logging.INFO)

mwelog = logging.getLogger("mwexpress")