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

213 feature request switch from log class to python logging module #312

Merged
Show file tree
Hide file tree
Changes from 3 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
30 changes: 12 additions & 18 deletions jade/computational.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we replace other print statements in this file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the print statements here should remain as they are, if removed, key informations would not be printed to video for the users. I added a few missing calls to log.info though to have a more complete log

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import sys

import jade.testrun as testrun
import logging


def executeBenchmarksRoutines(session, lib: str, runoption: str, exp=False) -> None:
Expand Down Expand Up @@ -57,8 +58,6 @@ def executeBenchmarksRoutines(session, lib: str, runoption: str, exp=False) -> N
config = session.conf.exp_default.set_index("Description")
else:
config = session.conf.comp_default.set_index("Description")
# Get the log
log = session.log

for testname, row in config.iterrows():
# Check for active test first
Expand Down Expand Up @@ -98,11 +97,8 @@ def executeBenchmarksRoutines(session, lib: str, runoption: str, exp=False) -> N

print(" -- " + testname.upper() + " STARTED --\n")
print(" Generating input files:" + " " + str(datetime.datetime.now()))
log.adjourn(
testname.upper()
+ " run started"
+ " "
+ str(datetime.datetime.now())
logging.info(
"%s run started %s", testname.upper(), str(datetime.datetime.now())
)

# --- Input Generation ---
Expand Down Expand Up @@ -138,7 +134,7 @@ def executeBenchmarksRoutines(session, lib: str, runoption: str, exp=False) -> N

# Generate test
lib_name = session.conf.get_lib_name(var)
args = (inppath, var, row, log, confpath, runoption, lib_name)
args = (inppath, var, row, confpath, runoption, lib_name)
# Handle special cases
if testname == "Sphere Leakage Test":
test = testrun.SphereTest(*args)
Expand Down Expand Up @@ -177,11 +173,10 @@ def executeBenchmarksRoutines(session, lib: str, runoption: str, exp=False) -> N
else:
test.generate_test(outpath, libmanager)
# Adjourn log
log.adjourn(
testname.upper()
+ " test input generated with success"
+ " "
+ str(datetime.datetime.now())
logging.info(
"%s test input generated with success %s",
testname.upper(),
str(datetime.datetime.now()),
)

if bool(row["OnlyInput"]):
Expand All @@ -193,11 +188,10 @@ def executeBenchmarksRoutines(session, lib: str, runoption: str, exp=False) -> N
test.run(session.conf, session.lib_manager, runoption)
print("\n -- " + testname.upper() + " COMPLETED --\n")
# Adjourn log
log.adjourn(
testname.upper()
+ " run completed with success"
+ " "
+ str(datetime.datetime.now())
logging.info(
"%s run completed with success %s",
testname.upper(),
str(datetime.datetime.now()),
)


Expand Down
81 changes: 3 additions & 78 deletions jade/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ def run_option(self, exp=False) -> str:
print(
" Cannot submit as a batch job, as no batch system has been defined in the config file."
)
elif (pd.isnull(self.mpi_exec_prefix)) and (pd.isnull(self.mpi_tasks) is not True):
elif (pd.isnull(self.mpi_exec_prefix)) and (
pd.isnull(self.mpi_tasks) is not True
):
if int(self.mpi_tasks) > 1:
print(
" Cannot submit batch job as MPI, as no MPI executable prefix has been defined in the config file."
Expand Down Expand Up @@ -206,80 +208,3 @@ def get_lib_name(self, suffix: str) -> str:
except KeyError:
name = suffix
return name


jade = """
8888888 oo 888oo o8888o
88 o8 8o 88 8oo 88 8
88 o8 8o 88 8o 88 8
88 o8=====8o 88 8o 88====°
88 88 o8 8o 88 8oo 8o
°°8888 o8 8o 888oo oo88888
"""

initialtext = """
Welcome to JADE, a nuclear libraries V&V test suite

This is the log file, all main events will be recorded here
-------------------------------------------------------------------------------
###############################################################################
"""

bar = """
##############################################################################
"""


class Log:
"""
This object stores important milestones of the session
"""

def __init__(self, logfile):
"""
Initialize the log file

logfile: (str) path to logfile
"""
# outpath for log file
self.file = logfile

self.text = jade + initialtext

def adjourn(self, text, spacing=True, time=False):
"""
Adjourn the log file
"""
if spacing:
text = "\n\n" + text.strip("\n")
self.text = self.text + text

if time:
self.text = self.text + " " + str(datetime.datetime.now())

with open(self.file, "w") as outfile:
outfile.write(self.text)

def bar_adjourn(self, text, spacing=True):
"""
Adjourn the log file with hashtag style
"""
if len(text) > 75: # There is no space, the bar request is ignored
self.text = self.text + text
else:
hashlen = (len(bar) - len(text)) / 2
if hashlen % 1 != 0:
after = int(hashlen - 1)
else:
after = int(hashlen)
before = int(hashlen)

bartext = bar[: before - 1] + " " + text + " " + bar[-after + 1 :]

if spacing:
bartext = "\n\n" + bartext

self.text = self.text + bartext

with open(self.file, "w") as outfile:
outfile.write(self.text)
15 changes: 15 additions & 0 deletions jade/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,18 @@
"""

CODES = {"MCNP": "mcnp", "Serpent": "serpent", "OpenMC": "openmc", "d1S": "d1s"}

JADE_TITLE = """
8888888 oo 888oo o8888o
88 o8 8o 88 8oo 88 8
88 o8 8o 88 8o 88 8
88 o8=====8o 88 8o 88====°
88 88 o8 8o 88 8oo 8o
°°8888 o8 8o 888oo oo88888

Welcome to JADE, a nuclear libraries V&V test suite

This is the log file, all main events will be recorded here
-------------------------------------------------------------------------------
###############################################################################
"""
2 changes: 1 addition & 1 deletion jade/excelsupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from xlsxwriter.utility import xl_rowcol_to_cell


def single_excel_writer(self, outpath, lib, testname, tallies, stats=None):
def single_excel_writer(outpath, lib, testname, tallies, stats=None):
"""
Produces single library summary excel file using XLSXwriter

Expand Down
8 changes: 2 additions & 6 deletions jade/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import sys

# colors
CRED = "\033[91m"
CORANGE = "\033[93m"
CEND = "\033[0m"
import logging


def fatal_exception(message=None):
Expand All @@ -24,5 +20,5 @@ def fatal_exception(message=None):
message = "A Fatal exception have occured"

message = message + ", the application will now exit"
print(CRED + " FATAL EXCEPTION: \n" + message + CEND)
logging.critical(" FATAL EXCEPTION: \n%s", message)
sys.exit()
Loading