откат изменения логирования
This commit is contained in:
+10
-10
@@ -4,7 +4,7 @@ import socket
|
|||||||
import aiofiles
|
import aiofiles
|
||||||
import call_handler
|
import call_handler
|
||||||
import config
|
import config
|
||||||
from main import logger
|
import logging
|
||||||
|
|
||||||
|
|
||||||
def send_action(s, action):
|
def send_action(s, action):
|
||||||
@@ -59,7 +59,7 @@ async def ami_listening():
|
|||||||
while True:
|
while True:
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
if now.hour == 23 and now.minute == 0 and now.second < 5:
|
if now.hour == 23 and now.minute == 0 and now.second < 5:
|
||||||
logger.info("Checking pending calls...")
|
logging.info("Checking pending calls...")
|
||||||
await callhandler.check_pending()
|
await callhandler.check_pending()
|
||||||
await asyncio.sleep(60)
|
await asyncio.sleep(60)
|
||||||
else:
|
else:
|
||||||
@@ -70,21 +70,21 @@ async def ami_listening():
|
|||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
logger.info("Connecting to Asterisk...")
|
logging.info("Connecting to Asterisk...")
|
||||||
s.connect((config.AMI_HOST, config.AMI_PORT))
|
s.connect((config.AMI_HOST, config.AMI_PORT))
|
||||||
break
|
break
|
||||||
except ConnectionRefusedError:
|
except ConnectionRefusedError:
|
||||||
logger.warning("Connection refused. Retrying...")
|
logging.warning("Connection refused. Retrying...")
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
logger.info("Connected to Asterisk")
|
logging.info("Connected to Asterisk")
|
||||||
logger.info("Logging in...")
|
logging.info("Logging in...")
|
||||||
|
|
||||||
login_action = f"Action: Login\r\nUsername: {config.AMI_USER}\r\nSecret: {config.AMI_PASSWORD}\r\n\r\n"
|
login_action = f"Action: Login\r\nUsername: {config.AMI_USER}\r\nSecret: {config.AMI_PASSWORD}\r\n\r\n"
|
||||||
send_action(s, login_action)
|
send_action(s, login_action)
|
||||||
|
|
||||||
logger.info("Logged in")
|
logging.info("Logged in")
|
||||||
logger.info("Listening for events...")
|
logging.info("Listening for events...")
|
||||||
|
|
||||||
events_action = "Action: Events\r\nEventMask: on\r\n\r\n"
|
events_action = "Action: Events\r\nEventMask: on\r\n\r\n"
|
||||||
send_action(s, events_action)
|
send_action(s, events_action)
|
||||||
@@ -97,9 +97,9 @@ async def ami_listening():
|
|||||||
if config.DEBUG:
|
if config.DEBUG:
|
||||||
await full_log(event)
|
await full_log(event)
|
||||||
except (KeyboardInterrupt, SystemExit):
|
except (KeyboardInterrupt, SystemExit):
|
||||||
logger.info("Exiting...")
|
logging.info("Exiting...")
|
||||||
s.close()
|
s.close()
|
||||||
daily_check_pending_task.cancel()
|
daily_check_pending_task.cancel()
|
||||||
except ConnectionResetError:
|
except ConnectionResetError:
|
||||||
logger.warning("Connection reset. Restarting...")
|
logging.warning("Connection reset. Restarting...")
|
||||||
await ami_listening()
|
await ami_listening()
|
||||||
|
|||||||
+11
-9
@@ -1,5 +1,5 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from main import logger
|
import logging
|
||||||
import wave
|
import wave
|
||||||
import config
|
import config
|
||||||
import medods
|
import medods
|
||||||
@@ -32,11 +32,11 @@ class CallHandler:
|
|||||||
def check_date():
|
def check_date():
|
||||||
if self.date != datetime.now().date():
|
if self.date != datetime.now().date():
|
||||||
self.date = datetime.now().date()
|
self.date = datetime.now().date()
|
||||||
logger.info(f"Date changed to {self.date} and reset calls database")
|
logging.info(f"Date changed to {self.date} and reset calls database")
|
||||||
if config.DEBUG:
|
if config.DEBUG:
|
||||||
if len(self.calls) > 0:
|
if len(self.calls) > 0:
|
||||||
logger.warning("Calls unhandled:")
|
logging.warning("Calls unhandled:")
|
||||||
logger.warning(self.calls)
|
logging.warning(self.calls)
|
||||||
self.finished = []
|
self.finished = []
|
||||||
self.pending = []
|
self.pending = []
|
||||||
self.calls = {}
|
self.calls = {}
|
||||||
@@ -271,7 +271,7 @@ class CallHandler:
|
|||||||
await self.call_pending(linkedid)
|
await self.call_pending(linkedid)
|
||||||
return
|
return
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(e)
|
logging.error(e)
|
||||||
|
|
||||||
async def incoming_call(self, event, linkedid):
|
async def incoming_call(self, event, linkedid):
|
||||||
def phone_number(number: str):
|
def phone_number(number: str):
|
||||||
@@ -297,13 +297,15 @@ class CallHandler:
|
|||||||
}
|
}
|
||||||
|
|
||||||
exten = event.get("Exten") if event.get("Exten") else event.get("Extension")
|
exten = event.get("Exten") if event.get("Exten") else event.get("Extension")
|
||||||
logger.info(f"New incoming call: ID={linkedid}, Client={client}, Phone={exten}")
|
logging.info(
|
||||||
|
f"New incoming call: ID={linkedid}, Client={client}, Phone={exten}"
|
||||||
|
)
|
||||||
await medods.incoming_call(linkedid, client, exten)
|
await medods.incoming_call(linkedid, client, exten)
|
||||||
|
|
||||||
async def call_started(self, linkedid, responsible):
|
async def call_started(self, linkedid, responsible):
|
||||||
|
|
||||||
self.calls[linkedid]["started"] = datetime.now()
|
self.calls[linkedid]["started"] = datetime.now()
|
||||||
logger.info(f"Call started: ID={linkedid}, Responsible={responsible}")
|
logging.info(f"Call started: ID={linkedid}, Responsible={responsible}")
|
||||||
await medods.call_started(linkedid)
|
await medods.call_started(linkedid)
|
||||||
|
|
||||||
async def call_pending(self, linkedid):
|
async def call_pending(self, linkedid):
|
||||||
@@ -406,7 +408,7 @@ class CallHandler:
|
|||||||
).total_seconds()
|
).total_seconds()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
logger.info(
|
logging.info(
|
||||||
f"Call finished: ID={linkedid}, Duration={duration}, Record ID={uniqueid}"
|
f"Call finished: ID={linkedid}, Duration={duration}, Record ID={uniqueid}"
|
||||||
)
|
)
|
||||||
await medods.call_finished(linkedid, duration)
|
await medods.call_finished(linkedid, duration)
|
||||||
@@ -417,5 +419,5 @@ class CallHandler:
|
|||||||
self.calls.pop(linkedid)
|
self.calls.pop(linkedid)
|
||||||
|
|
||||||
async def call_lost(self, linkedid):
|
async def call_lost(self, linkedid):
|
||||||
logger.info(f"Call lost: ID={linkedid}")
|
logging.info(f"Call lost: ID={linkedid}")
|
||||||
await medods.call_lost(linkedid)
|
await medods.call_lost(linkedid)
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ if config.DEBUG:
|
|||||||
else:
|
else:
|
||||||
logging_conf = "logging.conf"
|
logging_conf = "logging.conf"
|
||||||
|
|
||||||
logger = logging.getLogger("main")
|
|
||||||
logging.config.fileConfig(logging_conf)
|
logging.config.fileConfig(logging_conf)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ import aiohttp
|
|||||||
def loggingDict(title: str, data: dict) -> None:
|
def loggingDict(title: str, data: dict) -> None:
|
||||||
call_id = data.get("call_session_id", "None")
|
call_id = data.get("call_session_id", "None")
|
||||||
today = datetime.now().strftime("%Y-%m-%d")
|
today = datetime.now().strftime("%Y-%m-%d")
|
||||||
file_name = f"log/post/{today}/{call_id}.log"
|
file_name = f"log/{today}/{call_id}.log"
|
||||||
if not os.path.exists(f"log/post/{today}"):
|
if not os.path.exists(f"log/{today}"):
|
||||||
os.makedirs(f"log/post/{today}")
|
os.makedirs(f"log/{today}")
|
||||||
with open(file_name, "a") as f:
|
with open(file_name, "a") as f:
|
||||||
f.write(f"{title}:\n{json.dumps(data, indent=4)}\n\n")
|
f.write(f"{title}:\n{json.dumps(data, indent=4)}\n\n")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user