Skip to content

Commit

Permalink
Redirect logs based on env var (#1474) (#1495)
Browse files Browse the repository at this point in the history
(cherry picked from commit 8798744)

Co-authored-by: Dobiko <kobidogao@yahoo.com>
  • Loading branch information
BloodAxe and jnccd committed Oct 3, 2023
1 parent cefaffe commit 110dd8e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/super_gradients/common/auto_logging/auto_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def _setup_default_logging(self, log_level: str = None) -> None:
# Therefore the log file will have the parent PID to being able to discriminate the logs corresponding to a single run.
timestamp = time.strftime("%Y_%m_%d_%H_%M_%S", time.localtime())
self._setup_logging(
filename=os.path.expanduser(f"~/sg_logs/logs_{os.getppid()}_{timestamp}.log"),
filename=os.path.join(env_variables.SUPER_GRADIENTS_LOG_DIR, f"logs_{os.getppid()}_{timestamp}.log"),
copy_already_logged_messages=False,
filemode="w",
log_level=log_level,
Expand Down
3 changes: 2 additions & 1 deletion src/super_gradients/common/auto_logging/console_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from threading import Lock

from super_gradients.common.environment.ddp_utils import multi_process_safe, is_main_process
from super_gradients.common.environment.env_variables import env_variables


class BufferWriter:
Expand Down Expand Up @@ -117,7 +118,7 @@ def __init__(self):
@multi_process_safe
def _setup(self):
"""On instantiation, setup the default sink file."""
filename = Path.home() / "sg_logs" / "console.log"
filename = Path(env_variables.SUPER_GRADIENTS_LOG_DIR) / "console.log"
filename.parent.mkdir(exist_ok=True)
self.filename = str(filename)
os.makedirs(os.path.dirname(self.filename), exist_ok=True)
Expand Down
5 changes: 5 additions & 0 deletions src/super_gradients/common/environment/env_variables.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from pathlib import Path
from typing import Optional


Expand Down Expand Up @@ -45,5 +46,9 @@ def HYDRA_FULL_ERROR(self) -> Optional[str]:
def HYDRA_FULL_ERROR(self, value: str):
os.environ["HYDRA_FULL_ERROR"] = value

@property
def SUPER_GRADIENTS_LOG_DIR(self) -> str:
return os.getenv("SUPER_GRADIENTS_LOG_DIR", default=str(Path.home() / "sg_logs"))


env_variables = EnvironmentVariables()

0 comments on commit 110dd8e

Please sign in to comment.