Skip to content

Commit

Permalink
Making logging directory global (#369)
Browse files Browse the repository at this point in the history
Here we move the log directory to a place inside context.
This allows us to access an absolute path to the log dir anywhere
in the code.
In particular, this is used to help third-party libraries use our
logging tools.
  • Loading branch information
john-science authored Aug 11, 2021
1 parent 36e6ac7 commit 5f5483b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions armi/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

BLUEPRINTS_IMPORTED = False
BLUEPRINTS_IMPORT_CONTEXT = ""

LOG_DIR = os.path.join(os.getcwd(), "logs")

# App name is used when spawning new tasks that should invoke a specific ARMI
# application. For instance, the framework provides some features to help with
Expand Down Expand Up @@ -302,8 +302,12 @@ def disconnectAllHdfDBs():
OS_SECONDS_TIMEOUT = 5 * 60


def createLogDir(mpiRank=1, logDir="logs"):
def createLogDir(mpiRank=1, logDir=None):
"""A helper method to create the log directory"""
# the usual case is the user does not pass in a log dir path, so we use the global one
if logDir is None:
logDir = LOG_DIR

# let only do this from one thread
if mpiRank == 0:
if not os.path.exists(logDir):
Expand Down
4 changes: 2 additions & 2 deletions armi/runLog.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def startLog(self, name):
if self._mpiRank != 0:
# init stderr intercepting logging
filePath = os.path.join(
"logs", _RunLog.STDERR_NAME.format(name, self._mpiRank)
context.LOG_DIR, _RunLog.STDERR_NAME.format(name, self._mpiRank)
)
self.stderrLogger = logging.getLogger(STDERR_LOGGER_NAME)
h = logging.FileHandler(filePath)
Expand Down Expand Up @@ -444,7 +444,7 @@ def __init__(self, *args, **kwargs):
self.setLevel(logging.INFO)
else:
filePath = os.path.join(
"logs", _RunLog.STDOUT_NAME.format(args[0], mpiRank)
context.LOG_DIR, _RunLog.STDOUT_NAME.format(args[0], mpiRank)
)
handler = logging.FileHandler(filePath)
handler.setLevel(logging.WARNING)
Expand Down

0 comments on commit 5f5483b

Please sign in to comment.