def setUpClass(cls): helpers.prepareLogging() # fmt: off cls.data = ( (0xFC, [0xFC]), (0xFD, [0xFD, 0xFD, 0x0]), (wire.MaxUint16, [0xFD, 0xFF, 0xFF]), (wire.MaxUint16 + 1, [0xFE, 0x0, 0x0, 0x1, 0x0]), (wire.MaxUint32, [0xFE, 0xFF, 0xFF, 0xFF, 0xFF]), (wire.MaxUint32 + 1, [0xFF, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0]), (wire.MaxUint64, [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]), )
def initLogging(self): """ Initialize logging for the entire app. """ logDir = os.path.join(config.DATA_DIR, "logs") helpers.mkdir(logDir) logFilePath = os.path.join(logDir, "tinydecred.log") helpers.prepareLogging( logFilePath, logLvl=self.cfg.logLevel, lvlMap=self.cfg.moduleLevels ) log = helpers.getLogger("APP") log.info("configuration file at %s" % config.CONFIG_PATH) log.info("data directory at %s" % config.DATA_DIR) return log
def test_prepareLogging(tmp_path): path = tmp_path / "test.log" helpers.prepareLogging(filepath=path) logger = helpers.getLogger("1") logger1 = logger assert logger.getEffectiveLevel() == logging.INFO logger.info("something") assert path.is_file() helpers.prepareLogging(filepath=path, logLvl=logging.DEBUG) logger = helpers.getLogger("2") assert logger.getEffectiveLevel() == logging.DEBUG helpers.prepareLogging( filepath=path, logLvl=logging.INFO, lvlMap={ "1": logging.NOTSET, "3": logging.WARNING }, ) logger = helpers.getLogger("3") assert logger.getEffectiveLevel() == logging.WARNING assert logger1.getEffectiveLevel() == logging.NOTSET
def prepareLogger(request): helpers.prepareLogging()
import asyncio import logging import asyncio_redis from decred.util import helpers from flask import Flask, jsonify, render_template from flask_uwsgi_websocket import AsyncioWebSocket from challenges import FEED_CHANNEL app = Flask(__name__) ws = AsyncioWebSocket(app) helpers.prepareLogging(logLvl=logging.DEBUG) log = helpers.getLogger("WS") @ws.route('/ws') async def feed(ws): # yield from ws.send("sup") asyncio.get_event_loop().create_task(redis_subscribe(ws, FEED_CHANNEL)) await asyncio_redis.Connection.create() while True: msg = await ws.receive() if msg is not None: log.warn( f"received unexpected message from websocket client: {msg}") else: break
import atexit import subprocess import sys from decred.dcr import nets from decred.util import helpers from challenges import ChallengeManager helpers.prepareLogging() log = helpers.getLogger("SERVER") netParams = nets.mainnet if "--testnet" in sys.argv: netParams = nets.testnet if "--simnet" in sys.argv: netParams = nets.simnet def runWSGI_http(): return subprocess.Popen([ "uwsgi", "--master", "--wsgi=winatoms:app", "--socket=/tmp/winatoms.sock", "--chmod-socket=666", "--vacuum", "--python-autoreload=1", "--die-on-term" ]) def runWSGI_ws(): return subprocess.Popen([ "uwsgi", "--http-websockets", "--asyncio=100", "--greenlet", "--master", "--wsgi=ws:app", "--socket=/tmp/ws.sock",