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.
Files changed (155) hide show
  1. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/PKG-INFO +1 -1
  2. cellpy-0.4.2.post6/cellpy/_version.py +1 -0
  3. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/log.py +141 -141
  4. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/arbin_res.py +1483 -1483
  5. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy.egg-info/PKG-INFO +1 -1
  6. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy.egg-info/SOURCES.txt +17 -9
  7. cellpy-0.4.2.post6/docs/_build/.doctrees/nbsphinx/examples_and_tutorials_notebooks_tutorial_simple_plot_2_0.png +0 -0
  8. cellpy-0.4.2.post6/docs/_build/_images/examples_and_tutorials_notebooks_tutorial_simple_plot_2_0.png +0 -0
  9. cellpy-0.4.2.post6/docs/_build/_images/graphviz-22185705e237fa530df24e4af50cb25833165e25.png +0 -0
  10. cellpy-0.4.2.post6/docs/_build/_images/graphviz-246f2486cd940f2ea40a07f847c86c22b2607ca8.png +0 -0
  11. cellpy-0.4.2.post6/docs/_build/_images/graphviz-42e9bc826d476a3d361a7f410e989ed34dc1aa85.png +0 -0
  12. cellpy-0.4.2.post6/docs/_build/_images/graphviz-619216a42370fd49669c083549129b8470c8fae1.png +0 -0
  13. cellpy-0.4.2.post6/docs/_build/_images/graphviz-6deb64a460668e8ef9bf0ca653314119adeeae66.png +0 -0
  14. cellpy-0.4.2.post6/docs/_build/_images/graphviz-83b62e03ef369ff0a30f027892dba95b91ea8b6c.png +0 -0
  15. cellpy-0.4.2.post6/docs/_build/_images/graphviz-ce8a9fe2ba01194aed847e0248d749db4093aca1.png +0 -0
  16. cellpy-0.4.2.post6/docs/_build/_images/graphviz-e94a5352318e02fcc5ef1f813e02a526c39af791.png +0 -0
  17. cellpy-0.4.2.post6/docs/adapted_readme.rst +57 -0
  18. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/conf.py +332 -327
  19. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/index.rst +51 -51
  20. cellpy-0.4.2.post5/cellpy/_version.py +0 -1
  21. cellpy-0.4.2.post5/docs/_build/.doctrees/nbsphinx/notebooks_tutorial_simple_plot_2_0.png +0 -0
  22. cellpy-0.4.2.post5/docs/_build/_images/notebooks_tutorial_simple_plot_2_0.png +0 -0
  23. cellpy-0.4.2.post5/docs/readme.rst +0 -1
  24. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/AUTHORS.rst +0 -0
  25. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/CONTRIBUTING.rst +0 -0
  26. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/HISTORY.rst +0 -0
  27. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/LICENSE +0 -0
  28. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/MANIFEST.in +0 -0
  29. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/README.rst +0 -0
  30. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/__init__.py +0 -0
  31. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/cli.py +0 -0
  32. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/exceptions.py +0 -0
  33. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/logging.json +0 -0
  34. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/parameters/.cellpy_prms_default.conf +0 -0
  35. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/parameters/__init__.py +0 -0
  36. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/parameters/internal_settings.py +0 -0
  37. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/parameters/internal_settings_old.py +0 -0
  38. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/parameters/legacy/__init__.py +0 -0
  39. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/parameters/legacy/internal_settings.py +0 -0
  40. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/parameters/prmreader.py +0 -0
  41. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/parameters/prms.py +0 -0
  42. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/__init__.py +0 -0
  43. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/cellreader.py +0 -0
  44. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/core.py +0 -0
  45. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/dbreader.py +0 -0
  46. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/filefinder.py +0 -0
  47. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/__init__.py +0 -0
  48. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/arbin_sql.py +0 -0
  49. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/arbin_sql_csv.py +0 -0
  50. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/arbin_sql_xlsx.py +0 -0
  51. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/backup_arbin.py +0 -0
  52. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/base.py +0 -0
  53. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/biologics_mpr.py +0 -0
  54. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/configurations/__init__.py +0 -0
  55. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/configurations/maccor_txt_four.py +0 -0
  56. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/configurations/maccor_txt_one.py +0 -0
  57. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/configurations/maccor_txt_three.py +0 -0
  58. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/configurations/maccor_txt_two.py +0 -0
  59. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/configurations/maccor_txt_zero.py +0 -0
  60. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/custom.py +0 -0
  61. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/delete_these_in_february2022/__init__.py +0 -0
  62. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/delete_these_in_february2022/_testing_txt.py +0 -0
  63. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/delete_these_in_february2022/maccor_txt_old.py +0 -0
  64. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/ext_nda_reader.py +0 -0
  65. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/loader_specific_modules/__init__.py +0 -0
  66. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/loader_specific_modules/biologic_file_format.py +0 -0
  67. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/local_instrument.py +0 -0
  68. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/maccor_txt.py +0 -0
  69. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/old_custom.py +0 -0
  70. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/pec_csv.py +0 -0
  71. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/processors/__init__.py +0 -0
  72. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/processors/post_processors.py +0 -0
  73. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/readers/instruments/processors/pre_processors.py +0 -0
  74. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/__init__.py +0 -0
  75. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/batch.py +0 -0
  76. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/batch_tools/__init__.py +0 -0
  77. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/batch_tools/batch_analyzers.py +0 -0
  78. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/batch_tools/batch_core.py +0 -0
  79. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/batch_tools/batch_experiments.py +0 -0
  80. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/batch_tools/batch_exporters.py +0 -0
  81. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/batch_tools/batch_helpers.py +0 -0
  82. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/batch_tools/batch_journals.py +0 -0
  83. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/batch_tools/batch_plotters.py +0 -0
  84. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/batch_tools/batch_reporters.py +0 -0
  85. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/batch_tools/dumpers.py +0 -0
  86. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/batch_tools/engines.py +0 -0
  87. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/data/20160805_test001_45_cc.h5 +0 -0
  88. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/data/raw/20160805_test001_45_cc_01.res +0 -0
  89. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/diagnostics.py +0 -0
  90. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/easyplot.py +0 -0
  91. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/example_data.py +0 -0
  92. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/helpers.py +0 -0
  93. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/ica.py +0 -0
  94. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/live.py +0 -0
  95. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/ocv_rlx.py +0 -0
  96. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy/utils/plotutils.py +0 -0
  97. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy.egg-info/dependency_links.txt +0 -0
  98. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy.egg-info/entry_points.txt +0 -0
  99. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy.egg-info/not-zip-safe +0 -0
  100. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy.egg-info/requires.txt +0 -0
  101. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/cellpy.egg-info/top_level.txt +0 -0
  102. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/Makefile +0 -0
  103. /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
  104. /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
  105. /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
  106. /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
  107. /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
  108. /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
  109. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/_build/_images/templates_jupyterlab_001.png +0 -0
  110. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/_build/_images/tutorials_utils_plotting_fig1.png +0 -0
  111. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/_build/_images/tutorials_utils_plotting_fig2.png +0 -0
  112. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/_build/_static/file.png +0 -0
  113. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/_build/_static/minus.png +0 -0
  114. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/_build/_static/plus.png +0 -0
  115. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/authors.rst +0 -0
  116. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/basics.rst +0 -0
  117. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/contributing.rst +0 -0
  118. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/developers/dev_cellpy_data_structure.rst +0 -0
  119. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/developers/dev_cellpy_folder_structure.rst +0 -0
  120. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/developers/dev_various.rst +0 -0
  121. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/developers_guide.rst +0 -0
  122. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/examples.rst +0 -0
  123. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/formats.rst +0 -0
  124. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/history.rst +0 -0
  125. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/installation.rst +0 -0
  126. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/make.bat +0 -0
  127. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/notebooks.rst +0 -0
  128. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/source/cellpy.parameters.rst +0 -0
  129. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/source/cellpy.readers.instruments.rst +0 -0
  130. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/source/cellpy.readers.rst +0 -0
  131. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/source/cellpy.rst +0 -0
  132. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/source/cellpy.utils.batch_tools.rst +0 -0
  133. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/source/cellpy.utils.rst +0 -0
  134. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/source/modules.rst +0 -0
  135. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/tips_and_tricks.rst +0 -0
  136. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/tutorials/basic_interaction.rst +0 -0
  137. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/tutorials/configuring.rst +0 -0
  138. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/tutorials/data_mining.rst +0 -0
  139. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/tutorials/getting_started_tutorial.rst +0 -0
  140. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/tutorials/pandas.rst +0 -0
  141. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/tutorials/the_cellpy_cmd.rst +0 -0
  142. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/usage.rst +0 -0
  143. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/utils/batch.rst +0 -0
  144. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/utils/custom_file_loader.rst +0 -0
  145. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/utils/easyplot.rst +0 -0
  146. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/utils/figures/tutorials_utils_plotting_fig1.png +0 -0
  147. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/utils/figures/tutorials_utils_plotting_fig2.png +0 -0
  148. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/utils/ica.rst +0 -0
  149. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/utils/plotting.rst +0 -0
  150. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/utils/templates.rst +0 -0
  151. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/utils/tut_ocv_rlx.rst +0 -0
  152. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/docs/utils.rst +0 -0
  153. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/pyproject.toml +0 -0
  154. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/setup.cfg +0 -0
  155. {cellpy-0.4.2.post5 → cellpy-0.4.2.post6}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cellpy
3
- Version: 0.4.2.post5
3
+ Version: 0.4.2.post6
4
4
  Summary: Extract and manipulate data from battery cell testers.
5
5
  Home-page: https://github.com/jepegit/cellpy
6
6
  Author: Jan Petter Maehlen
@@ -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()