cellpy 0.4.2.post5__tar.gz → 0.4.2.post6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/PKG-INFO +1 -1
- cellpy-0.4.2.post6/cellpy/_version.py +1 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/log.py +141 -141
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/arbin_res.py +1483 -1483
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy.egg-info/PKG-INFO +1 -1
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy.egg-info/SOURCES.txt +17 -9
- cellpy-0.4.2.post6/docs/_build/.doctrees/nbsphinx/examples_and_tutorials_notebooks_tutorial_simple_plot_2_0.png +0 -0
- cellpy-0.4.2.post6/docs/_build/_images/examples_and_tutorials_notebooks_tutorial_simple_plot_2_0.png +0 -0
- cellpy-0.4.2.post6/docs/_build/_images/graphviz-22185705e237fa530df24e4af50cb25833165e25.png +0 -0
- cellpy-0.4.2.post6/docs/_build/_images/graphviz-246f2486cd940f2ea40a07f847c86c22b2607ca8.png +0 -0
- cellpy-0.4.2.post6/docs/_build/_images/graphviz-42e9bc826d476a3d361a7f410e989ed34dc1aa85.png +0 -0
- cellpy-0.4.2.post6/docs/_build/_images/graphviz-619216a42370fd49669c083549129b8470c8fae1.png +0 -0
- cellpy-0.4.2.post6/docs/_build/_images/graphviz-6deb64a460668e8ef9bf0ca653314119adeeae66.png +0 -0
- cellpy-0.4.2.post6/docs/_build/_images/graphviz-83b62e03ef369ff0a30f027892dba95b91ea8b6c.png +0 -0
- cellpy-0.4.2.post6/docs/_build/_images/graphviz-ce8a9fe2ba01194aed847e0248d749db4093aca1.png +0 -0
- cellpy-0.4.2.post6/docs/_build/_images/graphviz-e94a5352318e02fcc5ef1f813e02a526c39af791.png +0 -0
- cellpy-0.4.2.post6/docs/adapted_readme.rst +57 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/conf.py +332 -327
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/index.rst +51 -51
- cellpy-0.4.2.post5/cellpy/_version.py +0 -1
- cellpy-0.4.2.post5/docs/_build/.doctrees/nbsphinx/notebooks_tutorial_simple_plot_2_0.png +0 -0
- cellpy-0.4.2.post5/docs/_build/_images/notebooks_tutorial_simple_plot_2_0.png +0 -0
- cellpy-0.4.2.post5/docs/readme.rst +0 -1
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/AUTHORS.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/CONTRIBUTING.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/HISTORY.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/LICENSE +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/MANIFEST.in +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/README.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/__init__.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/cli.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/exceptions.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/logging.json +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/parameters/.cellpy_prms_default.conf +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/parameters/__init__.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/parameters/internal_settings.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/parameters/internal_settings_old.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/parameters/legacy/__init__.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/parameters/legacy/internal_settings.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/parameters/prmreader.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/parameters/prms.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/__init__.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/cellreader.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/core.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/dbreader.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/filefinder.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/__init__.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/arbin_sql.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/arbin_sql_csv.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/arbin_sql_xlsx.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/backup_arbin.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/base.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/biologics_mpr.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/configurations/__init__.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/configurations/maccor_txt_four.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/configurations/maccor_txt_one.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/configurations/maccor_txt_three.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/configurations/maccor_txt_two.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/configurations/maccor_txt_zero.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/custom.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/delete_these_in_february2022/__init__.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/delete_these_in_february2022/_testing_txt.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/delete_these_in_february2022/maccor_txt_old.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/ext_nda_reader.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/loader_specific_modules/__init__.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/loader_specific_modules/biologic_file_format.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/local_instrument.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/maccor_txt.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/old_custom.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/pec_csv.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/processors/__init__.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/processors/post_processors.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/processors/pre_processors.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/__init__.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/batch.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/batch_tools/__init__.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/batch_tools/batch_analyzers.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/batch_tools/batch_core.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/batch_tools/batch_experiments.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/batch_tools/batch_exporters.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/batch_tools/batch_helpers.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/batch_tools/batch_journals.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/batch_tools/batch_plotters.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/batch_tools/batch_reporters.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/batch_tools/dumpers.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/batch_tools/engines.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/data/20160805_test001_45_cc.h5 +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/data/raw/20160805_test001_45_cc_01.res +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/diagnostics.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/easyplot.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/example_data.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/helpers.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/ica.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/live.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/ocv_rlx.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/plotutils.py +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy.egg-info/dependency_links.txt +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy.egg-info/entry_points.txt +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy.egg-info/not-zip-safe +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy.egg-info/requires.txt +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy.egg-info/top_level.txt +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/Makefile +0 -0
- /cellpy-0.4.2.post5/docs/_build/.doctrees/nbsphinx/notebooks_tutorial_get_cap_6_0.png → /cellpy-0.4.2.post6/docs/_build/.doctrees/nbsphinx/examples_and_tutorials_notebooks_tutorial_get_cap_6_0.png +0 -0
- /cellpy-0.4.2.post5/docs/_build/.doctrees/nbsphinx/notebooks_tutorial_get_cap_7_0.png → /cellpy-0.4.2.post6/docs/_build/.doctrees/nbsphinx/examples_and_tutorials_notebooks_tutorial_get_cap_7_0.png +0 -0
- /cellpy-0.4.2.post5/docs/_build/.doctrees/nbsphinx/notebooks_tutorial_get_cap_8_0.png → /cellpy-0.4.2.post6/docs/_build/.doctrees/nbsphinx/examples_and_tutorials_notebooks_tutorial_get_cap_8_0.png +0 -0
- /cellpy-0.4.2.post5/docs/_build/_images/notebooks_tutorial_get_cap_6_0.png → /cellpy-0.4.2.post6/docs/_build/_images/examples_and_tutorials_notebooks_tutorial_get_cap_6_0.png +0 -0
- /cellpy-0.4.2.post5/docs/_build/_images/notebooks_tutorial_get_cap_7_0.png → /cellpy-0.4.2.post6/docs/_build/_images/examples_and_tutorials_notebooks_tutorial_get_cap_7_0.png +0 -0
- /cellpy-0.4.2.post5/docs/_build/_images/notebooks_tutorial_get_cap_8_0.png → /cellpy-0.4.2.post6/docs/_build/_images/examples_and_tutorials_notebooks_tutorial_get_cap_8_0.png +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/_build/_images/templates_jupyterlab_001.png +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/_build/_images/tutorials_utils_plotting_fig1.png +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/_build/_images/tutorials_utils_plotting_fig2.png +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/_build/_static/file.png +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/_build/_static/minus.png +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/_build/_static/plus.png +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/authors.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/basics.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/contributing.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/developers/dev_cellpy_data_structure.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/developers/dev_cellpy_folder_structure.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/developers/dev_various.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/developers_guide.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/examples.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/formats.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/history.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/installation.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/make.bat +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/notebooks.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/source/cellpy.parameters.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/source/cellpy.readers.instruments.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/source/cellpy.readers.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/source/cellpy.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/source/cellpy.utils.batch_tools.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/source/cellpy.utils.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/source/modules.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/tips_and_tricks.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/tutorials/basic_interaction.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/tutorials/configuring.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/tutorials/data_mining.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/tutorials/getting_started_tutorial.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/tutorials/pandas.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/tutorials/the_cellpy_cmd.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/usage.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/utils/batch.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/utils/custom_file_loader.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/utils/easyplot.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/utils/figures/tutorials_utils_plotting_fig1.png +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/utils/figures/tutorials_utils_plotting_fig2.png +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/utils/ica.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/utils/plotting.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/utils/templates.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/utils/tut_ocv_rlx.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/utils.rst +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/pyproject.toml +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/setup.cfg +0 -0
- {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/setup.py +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.4.2post6"
|
|
@@ -1,141 +1,141 @@
|
|
|
1
|
-
"""Set up logger instance"""
|
|
2
|
-
|
|
3
|
-
import datetime
|
|
4
|
-
import json
|
|
5
|
-
import logging
|
|
6
|
-
import logging.config
|
|
7
|
-
import os
|
|
8
|
-
import pathlib
|
|
9
|
-
import shutil
|
|
10
|
-
import tempfile
|
|
11
|
-
import warnings
|
|
12
|
-
|
|
13
|
-
from cellpy import prms
|
|
14
|
-
|
|
15
|
-
logging.raiseExceptions = False
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def setup_logging(
|
|
19
|
-
default_json_path=None,
|
|
20
|
-
default_level=None,
|
|
21
|
-
env_key="LOG_CFG",
|
|
22
|
-
custom_log_dir=None,
|
|
23
|
-
reset_big_log=False,
|
|
24
|
-
max_size=5_000_000,
|
|
25
|
-
testing=False,
|
|
26
|
-
):
|
|
27
|
-
"""Setup logging configuration.
|
|
28
|
-
|
|
29
|
-
Args:
|
|
30
|
-
default_level: default log-level to screen (std.out).
|
|
31
|
-
default_json_path: path to config file for setting up logging.
|
|
32
|
-
env_key (str): use this environment prm to try to get default_json_path.
|
|
33
|
-
custom_log_dir: path for saving logs.
|
|
34
|
-
reset_big_log (bool): reset log if too big (max_size).
|
|
35
|
-
max_size (int): if reset_log, this is the max limit.
|
|
36
|
-
testing (bool): set as True if testing, and you don't want to create any .log files
|
|
37
|
-
|
|
38
|
-
"""
|
|
39
|
-
|
|
40
|
-
if not default_json_path:
|
|
41
|
-
default_json_path = os.path.join(
|
|
42
|
-
os.path.dirname(os.path.realpath(__file__)), "logging.json"
|
|
43
|
-
)
|
|
44
|
-
path = default_json_path
|
|
45
|
-
value = os.getenv(env_key, None)
|
|
46
|
-
if value:
|
|
47
|
-
path = value
|
|
48
|
-
|
|
49
|
-
if default_level is None:
|
|
50
|
-
default_level = "CRITICAL"
|
|
51
|
-
|
|
52
|
-
# loading logging configs
|
|
53
|
-
if os.path.exists(path):
|
|
54
|
-
with open(path, "rt") as f:
|
|
55
|
-
config = json.load(f)
|
|
56
|
-
|
|
57
|
-
if testing:
|
|
58
|
-
log_dir = tempfile.mkdtemp()
|
|
59
|
-
elif custom_log_dir:
|
|
60
|
-
log_dir = custom_log_dir
|
|
61
|
-
else:
|
|
62
|
-
log_dir = os.path.abspath(prms.Paths.filelogdir)
|
|
63
|
-
|
|
64
|
-
if not os.path.isdir(log_dir):
|
|
65
|
-
warning_txt = (
|
|
66
|
-
"\nCould not set custom log-dir - "
|
|
67
|
-
"non-existing directory"
|
|
68
|
-
f"\nDir: {log_dir}"
|
|
69
|
-
"\nUsing current directory instead: "
|
|
70
|
-
f"{os.getcwd()}"
|
|
71
|
-
)
|
|
72
|
-
logging.warning(warning_txt)
|
|
73
|
-
log_dir = os.getcwd()
|
|
74
|
-
|
|
75
|
-
for file_handler in [
|
|
76
|
-
"error_file_handler",
|
|
77
|
-
"info_file_handler",
|
|
78
|
-
"debug_file_handler",
|
|
79
|
-
]:
|
|
80
|
-
try:
|
|
81
|
-
file_name = config["handlers"][file_handler]["filename"]
|
|
82
|
-
logging.debug("Setting file handlers for logging.")
|
|
83
|
-
logging.debug(f"Filename: {file_name}")
|
|
84
|
-
logging.debug(f"Full path: {os.path.join(log_dir,file_name)}")
|
|
85
|
-
# print(f"Filename: {file_name}")
|
|
86
|
-
# print(f"Full path: {os.path.join(log_dir,file_name)}")
|
|
87
|
-
config["handlers"][file_handler]["filename"] = os.path.join(
|
|
88
|
-
log_dir, file_name
|
|
89
|
-
)
|
|
90
|
-
|
|
91
|
-
if reset_big_log:
|
|
92
|
-
full_log_file_path = pathlib.Path(log_dir) / file_name
|
|
93
|
-
if full_log_file_path.is_file():
|
|
94
|
-
file_size = full_log_file_path.lstat().st_size
|
|
95
|
-
if file_size > max_size:
|
|
96
|
-
d_str = datetime.datetime.now().strftime("%Y_%m_%d_%H_%M")
|
|
97
|
-
new_file_name = "_".join([d_str, file_name])
|
|
98
|
-
new_full_log_file_path = (
|
|
99
|
-
pathlib.Path(log_dir) / new_file_name
|
|
100
|
-
)
|
|
101
|
-
shutil.copy(full_log_file_path, new_full_log_file_path)
|
|
102
|
-
else:
|
|
103
|
-
logging.debug(
|
|
104
|
-
"Could not reset big log: could not find the file"
|
|
105
|
-
)
|
|
106
|
-
|
|
107
|
-
except Exception as e:
|
|
108
|
-
warnings.warn("\nCould not set custom log-dir" + str(e))
|
|
109
|
-
|
|
110
|
-
if default_level:
|
|
111
|
-
w_txt = "\nCould not set custom default level for logger"
|
|
112
|
-
if default_level not in [
|
|
113
|
-
"INFO",
|
|
114
|
-
"DEBUG",
|
|
115
|
-
"CRITICAL",
|
|
116
|
-
logging.INFO,
|
|
117
|
-
logging.DEBUG,
|
|
118
|
-
logging.CRITICAL,
|
|
119
|
-
]:
|
|
120
|
-
_txt = "\nonly 'INFO', 'DEBUG' and 'CRITICAL' is supported"
|
|
121
|
-
_txt += " as default_level"
|
|
122
|
-
warnings.warn(w_txt + _txt)
|
|
123
|
-
|
|
124
|
-
else:
|
|
125
|
-
try:
|
|
126
|
-
config["handlers"]["console"]["level"] = default_level
|
|
127
|
-
if default_level in ["DEBUG", logging.DEBUG]:
|
|
128
|
-
config["handlers"]["console"]["formatter"] = "stamped"
|
|
129
|
-
|
|
130
|
-
except Exception as e:
|
|
131
|
-
warnings.warn(w_txt + "\n" + str(e))
|
|
132
|
-
|
|
133
|
-
logging.config.dictConfig(config)
|
|
134
|
-
else:
|
|
135
|
-
if not default_level:
|
|
136
|
-
default_level = logging.CRITICAL
|
|
137
|
-
logging.basicConfig(level=default_level)
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
if __name__ == "__main__":
|
|
141
|
-
setup_logging()
|
|
1
|
+
"""Set up logger instance"""
|
|
2
|
+
|
|
3
|
+
import datetime
|
|
4
|
+
import json
|
|
5
|
+
import logging
|
|
6
|
+
import logging.config
|
|
7
|
+
import os
|
|
8
|
+
import pathlib
|
|
9
|
+
import shutil
|
|
10
|
+
import tempfile
|
|
11
|
+
import warnings
|
|
12
|
+
|
|
13
|
+
from cellpy import prms
|
|
14
|
+
|
|
15
|
+
logging.raiseExceptions = False
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def setup_logging(
|
|
19
|
+
default_json_path=None,
|
|
20
|
+
default_level=None,
|
|
21
|
+
env_key="LOG_CFG",
|
|
22
|
+
custom_log_dir=None,
|
|
23
|
+
reset_big_log=False,
|
|
24
|
+
max_size=5_000_000,
|
|
25
|
+
testing=False,
|
|
26
|
+
):
|
|
27
|
+
"""Setup logging configuration.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
default_level: default log-level to screen (std.out).
|
|
31
|
+
default_json_path: path to config file for setting up logging.
|
|
32
|
+
env_key (str): use this environment prm to try to get default_json_path.
|
|
33
|
+
custom_log_dir: path for saving logs.
|
|
34
|
+
reset_big_log (bool): reset log if too big (max_size).
|
|
35
|
+
max_size (int): if reset_log, this is the max limit.
|
|
36
|
+
testing (bool): set as True if testing, and you don't want to create any .log files
|
|
37
|
+
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
if not default_json_path:
|
|
41
|
+
default_json_path = os.path.join(
|
|
42
|
+
os.path.dirname(os.path.realpath(__file__)), "logging.json"
|
|
43
|
+
)
|
|
44
|
+
path = default_json_path
|
|
45
|
+
value = os.getenv(env_key, None)
|
|
46
|
+
if value:
|
|
47
|
+
path = value
|
|
48
|
+
|
|
49
|
+
if default_level is None:
|
|
50
|
+
default_level = "CRITICAL"
|
|
51
|
+
|
|
52
|
+
# loading logging configs
|
|
53
|
+
if os.path.exists(path):
|
|
54
|
+
with open(path, "rt") as f:
|
|
55
|
+
config = json.load(f)
|
|
56
|
+
|
|
57
|
+
if testing:
|
|
58
|
+
log_dir = tempfile.mkdtemp()
|
|
59
|
+
elif custom_log_dir:
|
|
60
|
+
log_dir = custom_log_dir
|
|
61
|
+
else:
|
|
62
|
+
log_dir = os.path.abspath(prms.Paths.filelogdir)
|
|
63
|
+
|
|
64
|
+
if not os.path.isdir(log_dir):
|
|
65
|
+
warning_txt = (
|
|
66
|
+
"\nCould not set custom log-dir - "
|
|
67
|
+
"non-existing directory"
|
|
68
|
+
f"\nDir: {log_dir}"
|
|
69
|
+
"\nUsing current directory instead: "
|
|
70
|
+
f"{os.getcwd()}"
|
|
71
|
+
)
|
|
72
|
+
logging.warning(warning_txt)
|
|
73
|
+
log_dir = os.getcwd()
|
|
74
|
+
|
|
75
|
+
for file_handler in [
|
|
76
|
+
"error_file_handler",
|
|
77
|
+
"info_file_handler",
|
|
78
|
+
"debug_file_handler",
|
|
79
|
+
]:
|
|
80
|
+
try:
|
|
81
|
+
file_name = config["handlers"][file_handler]["filename"]
|
|
82
|
+
logging.debug("Setting file handlers for logging.")
|
|
83
|
+
logging.debug(f"Filename: {file_name}")
|
|
84
|
+
logging.debug(f"Full path: {os.path.join(log_dir,file_name)}")
|
|
85
|
+
# print(f"Filename: {file_name}")
|
|
86
|
+
# print(f"Full path: {os.path.join(log_dir,file_name)}")
|
|
87
|
+
config["handlers"][file_handler]["filename"] = os.path.join(
|
|
88
|
+
log_dir, file_name
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
if reset_big_log:
|
|
92
|
+
full_log_file_path = pathlib.Path(log_dir) / file_name
|
|
93
|
+
if full_log_file_path.is_file():
|
|
94
|
+
file_size = full_log_file_path.lstat().st_size
|
|
95
|
+
if file_size > max_size:
|
|
96
|
+
d_str = datetime.datetime.now().strftime("%Y_%m_%d_%H_%M")
|
|
97
|
+
new_file_name = "_".join([d_str, file_name])
|
|
98
|
+
new_full_log_file_path = (
|
|
99
|
+
pathlib.Path(log_dir) / new_file_name
|
|
100
|
+
)
|
|
101
|
+
shutil.copy(full_log_file_path, new_full_log_file_path)
|
|
102
|
+
else:
|
|
103
|
+
logging.debug(
|
|
104
|
+
"Could not reset big log: could not find the file"
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
except Exception as e:
|
|
108
|
+
warnings.warn("\nCould not set custom log-dir" + str(e))
|
|
109
|
+
|
|
110
|
+
if default_level:
|
|
111
|
+
w_txt = "\nCould not set custom default level for logger"
|
|
112
|
+
if default_level not in [
|
|
113
|
+
"INFO",
|
|
114
|
+
"DEBUG",
|
|
115
|
+
"CRITICAL",
|
|
116
|
+
logging.INFO,
|
|
117
|
+
logging.DEBUG,
|
|
118
|
+
logging.CRITICAL,
|
|
119
|
+
]:
|
|
120
|
+
_txt = "\nonly 'INFO', 'DEBUG' and 'CRITICAL' is supported"
|
|
121
|
+
_txt += " as default_level"
|
|
122
|
+
warnings.warn(w_txt + _txt)
|
|
123
|
+
|
|
124
|
+
else:
|
|
125
|
+
try:
|
|
126
|
+
config["handlers"]["console"]["level"] = default_level
|
|
127
|
+
if default_level in ["DEBUG", logging.DEBUG]:
|
|
128
|
+
config["handlers"]["console"]["formatter"] = "stamped"
|
|
129
|
+
|
|
130
|
+
except Exception as e:
|
|
131
|
+
warnings.warn(w_txt + "\n" + str(e))
|
|
132
|
+
|
|
133
|
+
logging.config.dictConfig(config)
|
|
134
|
+
else:
|
|
135
|
+
if not default_level:
|
|
136
|
+
default_level = logging.CRITICAL
|
|
137
|
+
logging.basicConfig(level=default_level)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
if __name__ == "__main__":
|
|
141
|
+
setup_logging()
|