Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
sdaza committed Dec 13, 2024
1 parent 32545d9 commit 928c904
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
15 changes: 2 additions & 13 deletions experiment_utils/experiment_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from scipy.stats import gaussian_kde
from pyspark.sql import functions as F
from pyspark.sql import DataFrame
from .utils import turn_off_package_logger, log_and_raise_error
from .utils import turn_off_package_logger, log_and_raise_error, get_logger
from .spark_instance import *


Expand Down Expand Up @@ -66,18 +66,7 @@ def __init__(
List of covariates to include in the final linear regression model, by default None
"""

self.logger = logging.getLogger('Experiment Analyzer')
self.logger.setLevel(logging.INFO)
if self.logger.hasHandlers():
self.logger.handlers.clear()
console_handler = logging.StreamHandler()
console_handler.setFormatter(
logging.Formatter(
fmt='%(asctime)s - %(message)s',
datefmt='%d/%m/%Y %I:%M:%S %p'
)
)
self.logger.addHandler(console_handler)
self.logger = get_logger('Experiment Analyzer')
self.data = self.__ensure_spark_df(data)
self.outcomes = self.__ensure_list(outcomes)
self.covariates = self.__ensure_list(covariates)
Expand Down
20 changes: 20 additions & 0 deletions experiment_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,26 @@ def turn_off_package_logger(package: str):
logger.handlers = [logging.NullHandler()]


def get_logger(name: str):
logger = logging.getLogger(name)

if not logger.hasHandlers():
logger.setLevel(logging.INFO)

while logger.hasHandlers():
logger.removeHandler(logger.handlers[0])

console_handler = logging.StreamHandler()
formatter = logging.Formatter(
fmt='%(asctime)s - %(message)s',
datefmt='%d/%m/%Y %I:%M:%S %p'
)
console_handler.setFormatter(formatter)
logger.addHandler(console_handler)

return logger


def log_and_raise_error(logger, message, exception_type=ValueError):
""""
Logs an error message and raises an exception of the specified type.
Expand Down

0 comments on commit 928c904

Please sign in to comment.