add logger

This commit is contained in:
w-okada 2023-07-26 17:04:55 +09:00
parent 3c54b6bd2b
commit 2e84fa7407
9 changed files with 47 additions and 6 deletions

2
.gitignore vendored
View File

@ -56,7 +56,7 @@ server/samples_0003_d2.json
server/test_official_v1_v2.json
server/test_ddpn_v1_v2.json
server/vvclient.log
start_trainer.sh
# venv

View File

@ -11,6 +11,7 @@ type ErrorBoundaryState = {
};
class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> {
// @ts-ignore
private eventHandler: () => void;
constructor(props: ErrorBoundaryProps) {
super(props);

View File

@ -1,3 +1,4 @@
import logging
import sys
from distutils.util import strtobool
@ -26,7 +27,8 @@ import subprocess
import multiprocessing as mp
from mods.log_control import setup_loggers
setup_loggers()
setup_loggers(f"Booting PHASE :{__name__}")
logger = logging.getLogger("vcclient")
def setupArgParser():
@ -127,6 +129,8 @@ if __name__ == "__mp_main__":
if __name__ == "__main__":
mp.freeze_support()
logger.info(args)
printMessage(f"PYTHON:{sys.version}", level=2)
printMessage("Voice Changerを起動しています。", level=2)
# ダウンロード(Weight)
@ -135,12 +139,14 @@ if __name__ == "__main__":
except WeightDownladException:
printMessage("RVC用のモデルファイルのダウンロードに失敗しました。", level=2)
printMessage("failed to download weight for rvc", level=2)
logger.warn("failed to download weight for rvc")
# ダウンロード(Sample)
try:
downloadInitialSamples(args.sample_mode, args.model_dir)
except Exception as e:
print("[Voice Changer] loading sample failed", e)
logger.warn(f"[Voice Changer] loading sample failed {e}",)
# PORT = args.p
@ -233,12 +239,12 @@ if __name__ == "__main__":
p.start()
try:
if sys.platform.startswith("win"):
process = subprocess.Popen([NATIVE_CLIENT_FILE_WIN, "-u", f"http://localhost:{PORT}/"])
process = subprocess.Popen([NATIVE_CLIENT_FILE_WIN, "--disable-gpu", "-u", f"http://localhost:{PORT}/"])
return_code = process.wait()
print("client closed.")
p.terminate()
elif sys.platform.startswith("darwin"):
process = subprocess.Popen([NATIVE_CLIENT_FILE_MAC, "-u", f"http://localhost:{PORT}/"])
process = subprocess.Popen([NATIVE_CLIENT_FILE_MAC, "--disable-gpu", "-u", f"http://localhost:{PORT}/"])
return_code = process.wait()
print("client closed.")
p.terminate()

View File

@ -1,3 +1,4 @@
import logging
import os
from concurrent.futures import ThreadPoolExecutor
@ -5,6 +6,8 @@ from downloader.Downloader import download
from voice_changer.utils.VoiceChangerParams import VoiceChangerParams
from Exceptions import WeightDownladException
logger = logging.getLogger("vcclient")
def downloadWeight(voiceChangerParams: VoiceChangerParams):
content_vec_500_onnx = voiceChangerParams.content_vec_500_onnx
@ -16,6 +19,9 @@ def downloadWeight(voiceChangerParams: VoiceChangerParams):
crepe_onnx_tiny = voiceChangerParams.crepe_onnx_tiny
rmvpe = voiceChangerParams.rmvpe
weight_files = [content_vec_500_onnx, hubert_base, hubert_base_jp, hubert_soft,
nsf_hifigan, crepe_onnx_full, crepe_onnx_tiny, rmvpe]
# file exists check (currently only for rvc)
downloadParams = []
if os.path.exists(hubert_base) is False:
@ -109,3 +115,12 @@ def downloadWeight(voiceChangerParams: VoiceChangerParams):
if os.path.exists(hubert_base) is False or os.path.exists(hubert_base_jp) is False or os.path.exists(hubert_soft) is False or os.path.exists(nsf_hifigan) is False or os.path.exists(nsf_hifigan_config) is False:
raise WeightDownladException()
# ファイルサイズをログに書き込む。(デバッグ用)
for weight in weight_files:
if os.path.exists(weight):
file_size = os.path.getsize(weight)
logger.info(f"weight file [{weight}]: {file_size}")
else:
logger.warn(f"weight file is missing. {weight}")
raise WeightDownladException()

View File

@ -8,7 +8,7 @@ class UvicornSuppressFilter(logging.Filter):
return False
def setup_loggers():
def setup_loggers(startMessage: str):
# logger = logging.getLogger("uvicorn.error")
# logger.addFilter(UvicornSuppressFilter())
@ -36,3 +36,12 @@ def setup_loggers():
logger.propagate = False
logging.getLogger("asyncio").setLevel(logging.WARNING)
logger = logging.getLogger("vcclient")
logger.setLevel(logging.INFO)
fh = logging.FileHandler('vvclient.log', encoding='utf-8')
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
fh.setLevel(logging.INFO)
logger.addHandler(fh)
logger.info(f"Start Logging, {startMessage}")

View File

@ -1,6 +1,7 @@
import os
from OpenSSL import crypto
def create_self_signed_cert(certfile, keyfile, certargs, cert_dir="."):
C_F = os.path.join(cert_dir, certfile)
K_F = os.path.join(cert_dir, keyfile)

View File

@ -1,9 +1,12 @@
import logging
from const import UPLOAD_DIR
from data.ModelSlot import ModelSlots, loadAllSlotInfo, saveSlotInfo
import json
import os
import shutil
logger = logging.getLogger("vcclient")
class ModelSlotManager:
_instance = None
@ -11,7 +14,7 @@ class ModelSlotManager:
def __init__(self, model_dir: str):
self.model_dir = model_dir
self.modelSlots = loadAllSlotInfo(self.model_dir)
print("[MODEL SLOT INFO]", self.modelSlots)
logger.info(f"[MODEL SLOT INFO] {self.modelSlots}")
@classmethod
def get_instance(cls, model_dir: str):

View File

@ -1,3 +1,4 @@
import logging
from typing import Any, Union, cast
from const import TMP_DIR
@ -27,6 +28,7 @@ from voice_changer.utils.VoiceChangerParams import VoiceChangerParams
STREAM_INPUT_FILE = os.path.join(TMP_DIR, "in.wav")
STREAM_OUTPUT_FILE = os.path.join(TMP_DIR, "out.wav")
logger = logging.getLogger("vcclient")
@dataclass
@ -80,6 +82,7 @@ class VoiceChanger(VoiceChangerIF):
self.onnx_device = onnxruntime.get_device()
print(f"VoiceChanger Initialized (GPU_NUM(cuda):{self.gpu_num}, mps_enabled:{self.mps_enabled}, onnx_device:{self.onnx_device})")
logger.info(f"VoiceChanger Initialized (GPU_NUM(cuda):{self.gpu_num}, mps_enabled:{self.mps_enabled}, onnx_device:{self.onnx_device})")
def setModel(self, model: Any):
self.voiceChanger = model

View File

@ -9,6 +9,7 @@
'''
import logging
from typing import Any, Union
from const import TMP_DIR
@ -37,6 +38,7 @@ from voice_changer.utils.VoiceChangerParams import VoiceChangerParams
STREAM_INPUT_FILE = os.path.join(TMP_DIR, "in.wav")
STREAM_OUTPUT_FILE = os.path.join(TMP_DIR, "out.wav")
logger = logging.getLogger("vcclient")
@dataclass
@ -90,6 +92,7 @@ class VoiceChangerV2(VoiceChangerIF):
self.onnx_device = onnxruntime.get_device()
print(f"VoiceChangerV2 Initialized (GPU_NUM(cuda):{self.gpu_num}, mps_enabled:{self.mps_enabled}, onnx_device:{self.onnx_device})")
logger.info(f"VoiceChangerV2 Initialized (GPU_NUM(cuda):{self.gpu_num}, mps_enabled:{self.mps_enabled}, onnx_device:{self.onnx_device})")
def setModel(self, model: VoiceChangerModel):
self.voiceChanger = model