Skip to content

Commit

Permalink
missing file
Browse files Browse the repository at this point in the history
  • Loading branch information
JackUrb committed Aug 15, 2023
1 parent 296cadf commit a925e3f
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions mephisto/configs/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,34 @@

BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
LOG_LEVEL = os.environ.get("LOG_LEVEL", "INFO")
WRITE_LOG_TO_FILE = os.environ.get("WRITE_LOG_TO_FILE", '0')
WRITE_LOG_TO_FILE = os.environ.get("WRITE_LOG_TO_FILE", "0")

_now = datetime.now()
date_string = _now.strftime("%Y-%m-%d")
time_string = _now.strftime("%H-%M-%S")


def get_log_handlers():
""" We enable module-level loggers via env variable (that we can set in the console),
so that hydra doesn't create an empty file for every module-level logger
"""We enable module-level loggers via env variable (that we can set in the console),
so that hydra doesn't create an empty file for every module-level logger
"""
handlers = ["console"]
if WRITE_LOG_TO_FILE == '1':
if WRITE_LOG_TO_FILE == "1":
handlers.append("file")
# Create dirs recursivelly if they do not exist
os.makedirs(
os.path.join(BASE_DIR, "outputs", date_string, time_string),
exist_ok=True
)
os.makedirs(os.path.join(BASE_DIR, "outputs", date_string, time_string), exist_ok=True)
return handlers


def get_log_filename():
""" Compose logfile path formatted same way as hydra """
"""Compose logfile path formatted same way as hydra"""
executed_filename = os.path.splitext(os.path.basename(sys.argv[0]))[0]
return os.path.join(
BASE_DIR, "outputs", date_string, time_string, f'{executed_filename}.log',
BASE_DIR,
"outputs",
date_string,
time_string,
f"{executed_filename}.log",
)


Expand All @@ -58,14 +59,18 @@ def get_log_filename():
"class": "logging.StreamHandler",
"formatter": "default",
},
**({
"file": {
"level": LOG_LEVEL,
"class": "logging.FileHandler",
"filename": log_filename,
"formatter": "default",
**(
{
"file": {
"level": LOG_LEVEL,
"class": "logging.FileHandler",
"filename": log_filename,
"formatter": "default",
}
}
} if "file" in log_handlers else {}),
if "file" in log_handlers
else {}
),
},
"loggers": {
"": {
Expand Down

0 comments on commit a925e3f

Please sign in to comment.