Skip to content

Commit

Permalink
Merge pull request #3 from Aymane11/fix-double-log
Browse files Browse the repository at this point in the history
Fix double logging issue
  • Loading branch information
Aymane11 authored Apr 11, 2024
2 parents ade84a5 + 02d391a commit 3e6aa16
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
9 changes: 0 additions & 9 deletions anonymize/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import sys
from anonymize import load_config, Config

from loguru import logger
Expand All @@ -9,21 +8,13 @@
def main(config: Config):
dfs: list[pl.LazyFrame] = []
for data in config.source:
if len(dfs) > 0:
# In case of database, no need to log every time
logger.remove()
for rule in config.rules:
if rule.column not in data.columns:
logger.warning(f"Column {rule.column} not found in the dataset. Skipping.")
continue
data = rule.apply(data)
dfs.append(data)

logger.add(
sys.stdout,
colorize=True,
format="<green>{time:YYYY-MM-DD HH:mm:ss}</green> | <level>{level}</level> | <level>{message}</level>",
)
config.output.write_data(pl.concat(dfs))


Expand Down
7 changes: 7 additions & 0 deletions anonymize/models/sources.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
from typing import Literal, Union
from pydantic import BaseModel, Field

Expand Down Expand Up @@ -62,6 +63,12 @@ def __iter__(self):
def __next__(self):
data = self.read_data()
if data.first().collect().is_empty():
# Bring back the logger
logger.add(
sys.stdout,
colorize=True,
format="<green>{time:YYYY-MM-DD HH:mm:ss}</green> | <level>{level}</level> | <level>{message}</level>",
)
raise StopIteration
return data

Expand Down

0 comments on commit 3e6aa16

Please sign in to comment.