Skip to content

Commit

Permalink
Merge pull request #31 from sdaza/dev
Browse files Browse the repository at this point in the history
fix logger
  • Loading branch information
sdaza authored Dec 13, 2024
2 parents 2aa9ad5 + b09b882 commit 308388b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
testing
notebooks
__pycache__
experiment_utils.egg-info
5 changes: 2 additions & 3 deletions experiment_utils/power_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from multiprocess.pool import ThreadPool
from scipy import stats
import statsmodels.api as sm
from .utils import log_and_raise_error
from .utils import log_and_raise_error, get_logger


class PowerSim:
Expand Down Expand Up @@ -47,8 +47,7 @@ def __init__(self, metric='proportion', relative_effect=False, nsim=100,
'negcorr' it corresponds to Benjamini/Yekutieli.
"""

self.logger = logging.getLogger('Power Simulator')
self.logger.setLevel(logging.INFO)
self.logger = get_logger('Power Simulator')
self.metric = metric
self.relative_effect = relative_effect
self.variants = variants
Expand Down
27 changes: 13 additions & 14 deletions experiment_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,19 @@ def turn_off_package_logger(package: str):

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)
logger.setLevel(logging.INFO)

for handler in logger.handlers[::-1]:
logger.removeHandler(handler)

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)
logger.propagate = False

return logger

Expand Down

0 comments on commit 308388b

Please sign in to comment.