Skip to content

Commit

Permalink
Changed implementation for the log_state function as well as the YAML…
Browse files Browse the repository at this point in the history
… arguments

Default value now falls to Debug->Log_state variable
Log_state functional parameter has None as default value
  • Loading branch information
DhruvSondhi committed Jun 30, 2021
1 parent fd947a2 commit f63b8d5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 36 deletions.
51 changes: 20 additions & 31 deletions tardis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"ERROR": logging.ERROR,
"CRITICAL": logging.CRITICAL,
}
DEFAULT_LOG_STATE = "CRITICAL"


class FilterLog(object):
Expand Down Expand Up @@ -99,51 +100,39 @@ def logging_state(log_state, tardis_config, specific):
specific: boolean
Allows to set specific logging levels. Logs of the `log_state` level would be output.
"""

if "debug" in tardis_config:
if specific or tardis_config["debug"]["specific"]:
specific = True
else:
specific = False

if tardis_config["debug"]["log_state"] or log_state:
if (
log_state.upper() == "CRITICAL"
and tardis_config["debug"]["log_state"]
):
logging_level = tardis_config["debug"]["log_state"]
elif log_state:
logging_level = log_state
if tardis_config["debug"]["log_state"] and log_state:
print(
"log_state is defined both in Functional Argument & YAML Configuration {debug section}"
)
print(
f"log_state = {log_state} will be used for Log Level Determination\n"
)
else:
logging_level = tardis_config["debug"]["log_state"]
specific = (
tardis_config["debug"]["specific"] if specific is None else specific
)

logging_level = (
log_state if log_state else tardis_config["debug"]["log_state"]
)
logging_level = logging_level.upper()

if not logging_level in LOGGING_LEVELS:
raise ValueError(
f"Passed Value for log_state = {logging_level} is Invalid. Must be one of the following {list(LOGGING_LEVELS.keys())}"
)
else:
logging_level = log_state
specific = specific
tardis_config["debug"] = {"log_state": DEFAULT_LOG_STATE}
logging_level = tardis_config["debug"]["log_state"]

loggers = [
logging.getLogger(name) for name in logging.root.manager.loggerDict
]
if logging_level.upper() in LOGGING_LEVELS.keys():
if logging_level in LOGGING_LEVELS:
for logger in loggers:
logger.setLevel(LOGGING_LEVELS[logging_level.upper()])
else:
raise ValueError(
f"Passed Value for log_state = {logging_level.upper()} is Invalid. Must be one of the following {list(LOGGING_LEVELS.keys())}"
)
logger.setLevel(LOGGING_LEVELS[logging_level])

if len(list_of_filter) > 0:
for filter in list_of_filter:
for logger in loggers:
logger.removeFilter(filter)

if specific:
filter_log = FilterLog(LOGGING_LEVELS[logging_level.upper()])
filter_log = FilterLog(LOGGING_LEVELS[logging_level])
list_of_filter.append(filter_log)
for logger in loggers:
logger.addFilter(filter_log)
Expand Down
4 changes: 2 additions & 2 deletions tardis/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ def run_tardis(
packet_source=None,
simulation_callbacks=[],
virtual_packet_logging=False,
log_state="Critical",
specific=False,
log_state=None,
specific=None,
):
"""
This function is one of the core functions to run TARDIS from a given
Expand Down
4 changes: 1 addition & 3 deletions tardis/io/schemas/debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ additionalProperties: false
properties:
log_state:
type: string
default: "Info"
default: "Critical"
description: Sets the logging Level for the logger
properties:
type:
Expand All @@ -20,5 +20,3 @@ properties:
default: false
description: Allows for logging on the specified logging levels

required:
- log_state

0 comments on commit f63b8d5

Please sign in to comment.