-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(logging): initialize logging in logger file and move version log (#…
…131)
- Loading branch information
Showing
5 changed files
with
46 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
__version__ = "1.4.1" | ||
|
||
from .logger import init_logger | ||
|
||
init_logger() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters