Skip to content

Commit

Permalink
fix(logging): initialize logging in logger file and move version log (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Lordmau5 authored Mar 26, 2023
1 parent 7b9ee0e commit 441d51f
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 41 deletions.
4 changes: 4 additions & 0 deletions src/so_vits_svc_fork/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
__version__ = "1.4.1"

from .logger import init_logger

init_logger()
42 changes: 5 additions & 37 deletions src/so_vits_svc_fork/__main__.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,23 @@
from __future__ import annotations

import os
from logging import (
DEBUG,
INFO,
FileHandler,
StreamHandler,
basicConfig,
captureWarnings,
getLogger,
)
from logging import getLogger
from pathlib import Path
from typing import Literal

import click
import pyinputplus as pyip
import torch
from rich.logging import RichHandler

from so_vits_svc_fork import __version__

LOG = getLogger(__name__)
LOGGER_INIT = False


def init_logger() -> None:
global LOGGER_INIT
if LOGGER_INIT:
return
IN_COLAB = os.getenv("COLAB_RELEASE_TAG")
IS_TEST = "test" in Path(__file__).parent.stem

basicConfig(
level=DEBUG if IS_TEST else INFO,
format="%(asctime)s %(message)s",
datefmt="[%X]",
handlers=[
RichHandler() if not IN_COLAB else StreamHandler(),
FileHandler(f"{__name__.split('.')[0]}.log"),
],
)
captureWarnings(True)
if IS_TEST:
LOG.debug("Test mode is on.")

LOG.info(f"Version: {__version__}")
LOGGER_INIT = True

IS_TEST = "test" in Path(__file__).parent.stem
if IS_TEST:
LOG.debug("Test mode is on.")

init_logger()
LOG.info(f"Version: {__version__}")


class RichHelpFormatter(click.HelpFormatter):
Expand Down Expand Up @@ -100,7 +69,6 @@ def cli():
To train a model, run pre-resample, pre-config, pre-hubert, train.\n
To infer a model, run infer.
"""
init_logger()


@cli.command()
Expand Down
2 changes: 0 additions & 2 deletions src/so_vits_svc_fork/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
from pebble import ProcessFuture, ProcessPool
from tqdm.tk import tqdm_tk

from .__main__ import init_logger
from .utils import ensure_hubert_model

GUI_DEFAULT_PRESETS_PATH = Path(__file__).parent / "default_gui_presets.json"
GUI_PRESETS_PATH = Path("./user_gui_presets.json").absolute()
init_logger()

LOG = getLogger(__name__)

Expand Down
35 changes: 35 additions & 0 deletions src/so_vits_svc_fork/logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os
from logging import (
DEBUG,
INFO,
FileHandler,
StreamHandler,
basicConfig,
captureWarnings,
)
from pathlib import Path

from rich.logging import RichHandler

LOGGER_INIT = False


def init_logger() -> None:
global LOGGER_INIT
if LOGGER_INIT:
return

IN_COLAB = os.getenv("COLAB_RELEASE_TAG")
IS_TEST = "test" in Path(__file__).parent.stem

basicConfig(
level=DEBUG if IS_TEST else INFO,
format="%(asctime)s %(message)s",
datefmt="[%X]",
handlers=[
RichHandler() if not IN_COLAB else StreamHandler(),
FileHandler(f"{__name__.split('.')[0]}.log"),
],
)
captureWarnings(True)
LOGGER_INIT = True
4 changes: 2 additions & 2 deletions src/so_vits_svc_fork/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def clean_checkpoints(
sort_by_time -- True -> chronologically delete ckpts
False -> lexicographically delete ckpts
"""
LOG.warning("Cleaning old checkpoints...")
LOG.info("Cleaning old checkpoints...")
path_to_models = Path(path_to_models)

# Define sort key functions
Expand All @@ -488,7 +488,7 @@ def clean_checkpoints(
to_delete_list = list(group_items)[:-n_ckpts_to_keep]

for to_delete in to_delete_list:
LOG.warning(f"Removing {to_delete}")
LOG.info(f"Removing {to_delete}")
to_delete.unlink()


Expand Down

0 comments on commit 441d51f

Please sign in to comment.