Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect logs based on env var #1474

Merged
merged 2 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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()