Skip to content

Commit 5ea754d

Browse files
author
Kevin Armengol
committed
More tweaks to new logging implementation.
1 parent 8aa68ed commit 5ea754d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+339
-2213
lines changed

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
/dist/
1010
/docs
1111
/notebooks/.ipynb_checkpoints
12+
/notebooks/logger.log
1213
__pycache__/
13-
/ddcuimap/**/logging.txt
14-
/logging.txt
14+
/ddcuimap/**/logger.log
15+
/ddcuimap-workspace.code-workspace
16+
/.vscode

ddcuimap/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
# from get_version import get_version
22
# __version__ = get_version(__file__)
3-
4-
# import logging.config
5-
# logging.config.fileConfig('/configs/logging/logging.yaml')

ddcuimap/curation/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import logging
2-
from ddcuimap.utils.setup_logging import log_setup
3-
2+
from ddcuimap.utils.logger.config_logging import setup_log, log, copy_log
43

54
# CREATE LOGGER
6-
log_setup()
7-
logger = logging.getLogger("curation_logger")
8-
logger.propagate = False
5+
setup_log()
6+
cur_logger = logging.getLogger("curation_logger")
7+
# logger.propagate = False
8+
cur_logger.info("Initiating ddcuimap.curation logger.")

ddcuimap/curation/check_cuis.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
import numpy as np
99

1010
from ddcuimap.utils import helper as helper
11-
from ddcuimap.utils.decorators import log
12-
from ddcuimap.curation import logger
11+
from ddcuimap.curation import cur_logger, log, copy_log
1312
from ddcuimap.curation.utils import dictionary_functions as dd
1413

1514

@@ -95,12 +94,13 @@ def check_cuis(cfg):
9594
df_multi_cui = df_multi_cui.add_suffix("_multi_cui")
9695
df_check = df_check.join(df_multi_cui, how="outer")
9796

98-
logger.info("Done checking CUIs for " + check)
97+
cur_logger.info("Done checking CUIs for " + check)
9998

100-
# Save file
99+
# SAVE FILE AND MOVE LOG
101100
fp_check = os.path.join(dir_check, "dictionary-import-file-check.csv")
102101
df_check.to_csv(fp_check, index=False)
103-
logger.info("Saved file to " + fp_check)
102+
cur_logger.info("Saved file to " + fp_check)
103+
copy_log(cur_logger, dir_check, "dictionary-import-file-check.log")
104104

105105
return df_check
106106

ddcuimap/curation/create_dictionary_import_file.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
from pathlib import Path
88

99
from ddcuimap.utils import helper as helper
10-
from ddcuimap.utils.decorators import log
11-
from ddcuimap.curation import logger
10+
from ddcuimap.curation import cur_logger, log, copy_log
1211
from ddcuimap.curation.utils import curation_functions as cur
1312

1413

@@ -70,12 +69,15 @@ def create_dd_file(cfg):
7069
.pipe(cur.override_cols, cfg.custom.create_dictionary_import_settings.override)
7170
)
7271

73-
# SAVE FINALIZED IMPORT TEMPLATE
72+
# SAVE FINALIZED IMPORT
7473
fp_step2 = f"{dir_step2}/{cfg.custom.curation_settings.file_settings.file_prefix}_Step-2_dictionary-import-file.csv"
7574
cfg.custom.create_dictionary_import_settings.dict_file_path = fp_step2
7675
df_final.to_csv(fp_step2, index=False) # output df_final dataframe to csv
77-
logger.info(f"Saved {fp_step2}")
76+
cur_logger.info(f"Saved {fp_step2}")
77+
78+
# SAVE CONFIG AND MOVE LOG
7879
helper.save_config(cfg, dir_step2)
80+
copy_log(cur_logger, dir_step2, "cur_logger.log")
7981

8082
return df_final
8183

ddcuimap/curation/utils/curation_functions.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99
import numpy as np
1010
import pandas as pd
1111

12+
from ddcuimap.curation import cur_logger, log, copy_log
1213
from ddcuimap.utils import helper as helper
13-
from ddcuimap.utils.decorators import log
14-
from ddcuimap.curation import logger
1514
from ddcuimap.curation.utils import xlsx_formatting as xlsx
1615

1716

@@ -166,7 +165,7 @@ def filter_keep_col(df):
166165
def order_keep_col(df):
167166
"""Orders rows in keep column by number and letter e.g., 1a, 1b, 2a, 2b, 3a, 3b"""
168167

169-
# TODO: need to fix issue where 1a,1b,2,2c puts 2 first.
168+
# TODO: need to fix issue where 1a,1b,2,2c puts 2 first and also treats 2 and 2b as separate (2|2b instead of 2/2b)
170169
df["keep"] = df["keep"].astype(str)
171170
df["keep_num"] = [x[0] for x in df["keep"]]
172171
df["keep_letter"] = [x[1:] if len(x) > 1 else "" for x in df["keep"]]
@@ -241,7 +240,7 @@ def keep_existing_cols(df_cols, cols_to_check: list):
241240
) # TODO: check why I wrote this
242241
cols_excl = list(set(cols_to_check).difference(df_cols))
243242
cols = [x for x in df_cols if x not in cols_excl]
244-
logger.warning(
243+
cur_logger.warning(
245244
f"The following columns were not found and will be excluded: {cols_excl}"
246245
)
247246
return cols

ddcuimap/curation/utils/process_data_dictionary.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
55
"""
66

7-
87
import pandas as pd
98

9+
from ddcuimap.curation import cur_logger, log, copy_log
1010
from ddcuimap.utils import helper as helper
11-
from ddcuimap.utils.decorators import log
12-
from ddcuimap.curation import logger
1311
from ddcuimap.curation.utils import text_processing as tp
1412

1513

@@ -20,13 +18,13 @@ def load_data_dictionary(cfg):
2018
if not cfg.custom.data_dictionary_settings.filepath:
2119
fp_dd = helper.choose_file("Select data dictionary csv input file")
2220
df_dd = pd.read_csv(fp_dd)
23-
logger.info(f"Data Dictionary shape is: {df_dd.shape}")
21+
cur_logger.info(f"Data Dictionary shape is: {df_dd.shape}")
2422
cfg.custom.data_dictionary_settings.filepath = fp_dd
2523
else:
2624
fp_dd = cfg.custom.data_dictionary_settings.filepath
27-
logger.warning(f"Loading data dictionary from filepath in configs.")
25+
cur_logger.warning(f"Loading data dictionary from filepath in configs.")
2826
df_dd = pd.read_csv(fp_dd)
29-
logger.info(f"Data Dictionary shape is: {df_dd.shape}")
27+
cur_logger.info(f"Data Dictionary shape is: {df_dd.shape}")
3028
return df_dd, fp_dd
3129

3230

@@ -75,5 +73,5 @@ def process_data_dictionary(df_dd, cfg):
7573
tp.remove_stopwords_cols, cols_extracted, cfg.custom.preprocessing_settings
7674
)
7775
)
78-
logger.info(f"Processed Data Dictionary shape is: {df_dd_preprocessed.shape}")
76+
cur_logger.info(f"Processed Data Dictionary shape is: {df_dd_preprocessed.shape}")
7977
return df_dd_preprocessed

ddcuimap/curation/utils/text_processing.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
# import cchardet # TODO: may be useful in future
1515

1616
from ddcuimap.utils import helper
17-
from ddcuimap.utils.decorators import log
18-
from ddcuimap.curation import logger
17+
from ddcuimap.curation import cur_logger, log, copy_log
1918

2019

2120
# TEXT PROCESSING FUNCTIONS
@@ -74,10 +73,10 @@ def remove_stopwords_cols(df, columns, preprocessing_settings):
7473
cols_query_terms = []
7574
if preprocessing_settings.remove_stopwords:
7675
if preprocessing_settings.stopwords_filepath:
77-
logger.warning("Loading stopwords file from configs")
76+
cur_logger.warning("Loading stopwords file from configs")
7877
fp_stopwords = preprocessing_settings.stopwords_filepath
7978
else:
80-
logger.warning("Opening dialog box to choose stopwords file")
79+
cur_logger.warning("Opening dialog box to choose stopwords file")
8180
fp_stopwords = helper.choose_file("Select Stopwords csv file")
8281
df_stopwords = pd.read_csv(fp_stopwords)
8382
ls_stopwords = list(
@@ -106,18 +105,18 @@ def remove_vars_cheatsheet(df, preprocessing_settings): # TODO: not yet impleme
106105

107106
if preprocessing_settings.use_cheatsheet:
108107
if preprocessing_settings.cheatsheet_filepath:
109-
logger.warning("Loading cheatsheet file from configs")
108+
cur_logger.warning("Loading cheatsheet file from configs")
110109
fp_cheatsheet = preprocessing_settings.cheatsheet_filepath
111110
else:
112-
logger.warning("Opening dialog box to choose cheatsheet file")
111+
cur_logger.warning("Opening dialog box to choose cheatsheet file")
113112
fp_cheatsheet = helper.choose_file(title="Select Cheatsheet csv file")
114113
df_cheatsheet = pd.read_csv(fp_cheatsheet)
115114
curated_vars = df_cheatsheet[
116115
"variable name"
117116
] # TODO: need to add consistent formatting for use of a cheatsheet
118117
df = df[~df["variable name"].isin(curated_vars)]
119118
else:
120-
logger.warning("Cheatsheet not used")
119+
cur_logger.warning("Cheatsheet not used")
121120
pass
122121
return df
123122

ddcuimap/curation/utils/xlsx_formatting.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
"""
2+
3+
Functions for formatting Excel curation file.
4+
5+
"""
6+
17
from openpyxl.utils import get_column_letter
28

3-
from ddcuimap.utils.decorators import log
9+
from ddcuimap.curation import log
410

511

612
# EXCEL FORMATTING

ddcuimap/hydra_search/__init__.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import logging
2-
from ddcuimap.utils.setup_logging import log_setup
3-
2+
from ddcuimap.utils.logger.config_logging import setup_log, log, copy_log
43

54
# CREATE LOGGER
6-
log_setup()
7-
logger = logging.getLogger("hydra_search_logger")
8-
logger.propagate = False
9-
logger.info("Initiating ddcuimap.hydra_search logging.")
5+
setup_log()
6+
hydra_logger = logging.getLogger("hydra_search_logger")
7+
hydra_logger.info("Initiating ddcuimap.hydra_search logger.")

0 commit comments

Comments
 (0)