initial logging install

This commit is contained in:
Kyler Eastridge
2025-06-22 09:40:52 -04:00
parent 73acc30400
commit 88a7cbaf79
2 changed files with 17 additions and 5 deletions

View File

@@ -7,6 +7,9 @@ from . import login
from . import viewer as Viewer from . import viewer as Viewer
from .const import * from .const import *
import logging
logger = logging.getLogger(__name__)
class SimpleBot(EventTarget): class SimpleBot(EventTarget):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
@@ -75,8 +78,11 @@ class SimpleBot(EventTarget):
async def login(self, username, password): async def login(self, username, password):
loginHandle = await login.Login(username, password, isBot = True) loginHandle = await login.Login(username, password, isBot = True)
if loginHandle["login"] == False: if loginHandle["login"] == False:
logger.critical(f"Login failure: {loginHandle["message"]}")
raise ValueError("Incorrect username or password") raise ValueError("Incorrect username or password")
logger.info(f"Login success: {loginHandle["message"]}")
await self.agent.login(loginHandle) await self.agent.login(loginHandle)
async def run(self): async def run(self):

View File

@@ -1,8 +1,12 @@
import asyncio
import struct
from ..eventtarget import EventTarget from ..eventtarget import EventTarget
from .simulator import Simulator from .simulator import Simulator
from . import messages from . import messages
import asyncio
import struct import logging
logger = logging.getLogger(__name__)
sHandle = struct.Struct("<II") sHandle = struct.Struct("<II")
sIP = struct.Struct("<BBBB") sIP = struct.Struct("<BBBB")
@@ -19,6 +23,7 @@ class Agent(EventTarget):
self.messageTemplate = messages.getDefaultTemplate() self.messageTemplate = messages.getDefaultTemplate()
async def addSimulator(self, handle, host, circuit, caps = None, parent = False): async def addSimulator(self, handle, host, circuit, caps = None, parent = False):
logger.debug(f"Connecting to {host} with circuit {circuit}")
sim = Simulator(self) sim = Simulator(self)
await sim.connect(host, circuit) await sim.connect(host, circuit)
self.simulators.append(sim) self.simulators.append(sim)
@@ -31,7 +36,6 @@ class Agent(EventTarget):
sim.on("message", self.handleMessage) sim.on("message", self.handleMessage)
sim.on("event", self.handleEvent) sim.on("event", self.handleEvent)
print("Connecting to", sim)
return sim return sim
def send(self, msg, reliable): def send(self, msg, reliable):
@@ -57,7 +61,6 @@ class Agent(EventTarget):
await self.fire("message", sim, msg) await self.fire("message", sim, msg)
async def handleEvent(self, sim, name, body): async def handleEvent(self, sim, name, body):
print(sim, name, body)
if name == "EnableSimulator": if name == "EnableSimulator":
simulatorInfo = body["SimulatorInfo"][0] simulatorInfo = body["SimulatorInfo"][0]
handle = struct.unpack("<II", simulatorInfo["Handle"]) handle = struct.unpack("<II", simulatorInfo["Handle"])
@@ -110,6 +113,9 @@ class Agent(EventTarget):
if simulator.host == host: if simulator.host == host:
await simulator.fetchCapabilities(body["seed-capability"]) await simulator.fetchCapabilities(body["seed-capability"])
break break
else:
logger.warning(f"Received EstablishAgentCommunication for unknown host {host}")
await self.fire("event", sim, name, body) await self.fire("event", sim, name, body)
@@ -147,7 +153,7 @@ class Agent(EventTarget):
try: try:
if not self.simulator: if not self.simulator:
break break
await asyncio.sleep(0.1) await asyncio.sleep(0.1)
except asyncio.exceptions.CancelledError: except asyncio.exceptions.CancelledError: