2022-12-31 10:08:14 +03:00
|
|
|
import logging
|
2023-11-28 23:18:53 +03:00
|
|
|
import traceback
|
2022-12-31 10:08:14 +03:00
|
|
|
|
2023-03-10 19:56:10 +03:00
|
|
|
|
2023-01-14 13:27:18 +03:00
|
|
|
class UvicornSuppressFilter(logging.Filter):
|
|
|
|
def filter(self, record):
|
|
|
|
return False
|
2023-01-14 00:44:30 +03:00
|
|
|
|
2023-03-10 19:56:10 +03:00
|
|
|
|
2023-07-26 22:06:25 +03:00
|
|
|
class NullHandler(logging.Handler):
|
|
|
|
def emit(self, record):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2023-11-28 23:18:53 +03:00
|
|
|
class DebugStreamHandler(logging.StreamHandler):
|
|
|
|
def emit(self, record):
|
|
|
|
try:
|
|
|
|
super().emit(record)
|
|
|
|
except Exception as e:
|
|
|
|
print(f"Error logging message: {e}", file=sys.stderr)
|
|
|
|
traceback.print_exc()
|
|
|
|
|
|
|
|
|
|
|
|
class DebugFileHandler(logging.FileHandler):
|
|
|
|
def emit(self, record):
|
|
|
|
try:
|
|
|
|
super().emit(record)
|
|
|
|
except Exception as e:
|
|
|
|
print(f"Error writing log message to file: {e}", file=sys.stderr)
|
|
|
|
traceback.print_exc()
|
|
|
|
|
|
|
|
|
2023-07-26 22:06:25 +03:00
|
|
|
class VoiceChangaerLogger:
|
|
|
|
_instance = None
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get_instance(cls):
|
|
|
|
if cls._instance is None:
|
|
|
|
cls._instance = cls()
|
|
|
|
return cls._instance
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
# logger = logging.getLogger("uvicorn.error")
|
|
|
|
# logger.addFilter(UvicornSuppressFilter())
|
|
|
|
|
|
|
|
# logging.basicConfig(filename='myapp.log', level=logging.INFO)
|
|
|
|
# logging.basicConfig(level=logging.NOTSET)
|
|
|
|
logging.root.handlers = [NullHandler()]
|
|
|
|
|
|
|
|
logger = logging.getLogger("fairseq.tasks.hubert_pretraining")
|
|
|
|
logger.addFilter(UvicornSuppressFilter())
|
|
|
|
|
|
|
|
logger = logging.getLogger("fairseq.models.hubert.hubert")
|
|
|
|
logger.addFilter(UvicornSuppressFilter())
|
|
|
|
|
|
|
|
logger = logging.getLogger("fairseq.tasks.text_to_speech")
|
|
|
|
logger.addFilter(UvicornSuppressFilter())
|
|
|
|
|
|
|
|
logger = logging.getLogger("numba.core.ssa")
|
|
|
|
logger.addFilter(UvicornSuppressFilter())
|
|
|
|
|
|
|
|
logger = logging.getLogger("numba.core.interpreter")
|
|
|
|
logger.addFilter(UvicornSuppressFilter())
|
|
|
|
|
|
|
|
logger = logging.getLogger("numba.core.byteflow")
|
|
|
|
logger.addFilter(UvicornSuppressFilter())
|
|
|
|
|
|
|
|
# logger.propagate = False
|
|
|
|
|
|
|
|
logger = logging.getLogger("multipart.multipart")
|
|
|
|
logger.propagate = False
|
|
|
|
|
|
|
|
logging.getLogger("asyncio").setLevel(logging.WARNING)
|
|
|
|
|
|
|
|
logger = logging.getLogger("vcclient")
|
|
|
|
logger.setLevel(logging.DEBUG)
|
2023-08-14 05:08:31 +03:00
|
|
|
self.logger = logger
|
2023-07-26 22:06:25 +03:00
|
|
|
|
2023-08-14 05:08:31 +03:00
|
|
|
def initialize(self, initialize: bool):
|
|
|
|
if not self.logger.handlers:
|
|
|
|
if initialize:
|
2023-11-28 23:18:53 +03:00
|
|
|
# file_handler = logging.FileHandler("vcclient.log", encoding="utf-8", mode="w")
|
|
|
|
file_handler = DebugFileHandler("vcclient.log", encoding="utf-8", mode="w")
|
2023-08-14 05:08:31 +03:00
|
|
|
else:
|
2023-11-28 23:18:53 +03:00
|
|
|
# file_handler = logging.FileHandler("vcclient.log", encoding="utf-8")
|
|
|
|
file_handler = DebugFileHandler("vcclient.log", encoding="utf-8")
|
|
|
|
file_formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(process)d - %(message)s")
|
2023-07-26 22:06:25 +03:00
|
|
|
file_handler.setFormatter(file_formatter)
|
|
|
|
file_handler.setLevel(logging.DEBUG)
|
2023-08-14 05:08:31 +03:00
|
|
|
self.logger.addHandler(file_handler)
|
2023-07-26 22:06:25 +03:00
|
|
|
|
2023-11-28 23:18:53 +03:00
|
|
|
stream_formatter = logging.Formatter("%(message)s")
|
|
|
|
# stream_handler = logging.StreamHandler()
|
|
|
|
stream_handler = DebugStreamHandler()
|
2023-07-26 22:06:25 +03:00
|
|
|
stream_handler.setFormatter(stream_formatter)
|
|
|
|
stream_handler.setLevel(logging.INFO)
|
2023-08-14 05:08:31 +03:00
|
|
|
self.logger.addHandler(stream_handler)
|
2023-07-26 22:06:25 +03:00
|
|
|
|
|
|
|
def getLogger(self):
|
|
|
|
return self.logger
|