├── .editorconfig
├── .github
└── FUNDING.yml
├── .gitignore
├── .style.yapf
├── .yapfignore
├── LICENSE
├── README.md
├── conftest.py
├── dj_easy_log.py
├── pdm.lock
├── pyproject.toml
├── pytest.ini
└── test_easy_log.py
/.editorconfig:
--------------------------------------------------------------------------------
1 | # https://editorconfig.org/
2 |
3 | root = true
4 |
5 | [*]
6 | indent_style = space
7 | indent_size = 2
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 | end_of_line = lf
11 | charset = utf-8
12 |
13 | [*.py]
14 | max_line_length = 100
15 |
16 | [*.html]
17 | printWidth = 100
18 | indent_size = 2
19 |
20 | [*.vue]
21 | printWidth = 100
22 | indent_size = 2
23 |
24 | [*.js]
25 | printWidth = 100
26 | indent_size = 2
27 |
28 | [*.json]
29 | printWidth = 100
30 | indent_size = 2
31 |
32 | [*.less]
33 | printWidth = 100
34 | indent_size = 2
35 |
36 | [*.md]
37 | max_line_length = 100
38 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: neutron-sync
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 |
9 | # Distribution / packaging
10 | .Python
11 | build/
12 | develop-eggs/
13 | dist/
14 | downloads/
15 | eggs/
16 | .eggs/
17 | lib/
18 | lib64/
19 | parts/
20 | sdist/
21 | var/
22 | wheels/
23 | pip-wheel-metadata/
24 | share/python-wheels/
25 | *.egg-info/
26 | .installed.cfg
27 | *.egg
28 | MANIFEST
29 |
30 | # PyInstaller
31 | # Usually these files are written by a python script from a template
32 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
33 | *.manifest
34 | *.spec
35 |
36 | # Installer logs
37 | pip-log.txt
38 | pip-delete-this-directory.txt
39 |
40 | # Unit test / coverage reports
41 | htmlcov/
42 | .tox/
43 | .nox/
44 | .coverage
45 | .coverage.*
46 | .cache
47 | nosetests.xml
48 | coverage.xml
49 | *.cover
50 | *.py,cover
51 | .hypothesis/
52 | .pytest_cache/
53 |
54 | # Translations
55 | *.mo
56 | *.pot
57 |
58 | # Django stuff:
59 | *.log
60 | local_settings.py
61 | db.sqlite3
62 | db.sqlite3-journal
63 |
64 | # Flask stuff:
65 | instance/
66 | .webassets-cache
67 |
68 | # Scrapy stuff:
69 | .scrapy
70 |
71 | # Sphinx documentation
72 | docs/_build/
73 |
74 | # PyBuilder
75 | target/
76 |
77 | # Jupyter Notebook
78 | .ipynb_checkpoints
79 |
80 | # IPython
81 | profile_default/
82 | ipython_config.py
83 |
84 | # pyenv
85 | .python-version
86 |
87 | # pipenv
88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
91 | # install all needed dependencies.
92 | #Pipfile.lock
93 |
94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow
95 | __pypackages__/
96 |
97 | # Celery stuff
98 | celerybeat-schedule
99 | celerybeat.pid
100 |
101 | # SageMath parsed files
102 | *.sage.py
103 |
104 | # Environments
105 | .env
106 | .venv
107 | env/
108 | venv/
109 | ENV/
110 | env.bak/
111 | venv.bak/
112 |
113 | # Spyder project settings
114 | .spyderproject
115 | .spyproject
116 |
117 | # Rope project settings
118 | .ropeproject
119 |
120 | # mkdocs documentation
121 | /site
122 |
123 | # mypy
124 | .mypy_cache/
125 | .dmypy.json
126 | dmypy.json
127 |
128 | # Pyre type checker
129 | .pyre/
130 | .pdm.toml
131 | .pdm-python
132 |
--------------------------------------------------------------------------------
/.style.yapf:
--------------------------------------------------------------------------------
1 | [style]
2 | indent_width=2
3 | continuation_indent_width=2
4 | based_on_style = google
5 | column_limit = 100
6 |
--------------------------------------------------------------------------------
/.yapfignore:
--------------------------------------------------------------------------------
1 | __pypackages__/*
2 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 Neutron Sync
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Django Easy Logging
2 |
3 | Easy Django logging with Loguru
4 |
5 | [Loguru](https://github.com/Delgan/loguru) is an exceeding easy way to do logging in Python. django-easy-logging makes it exceedingly easy to use Loguru in Django. Once integrated you can using existings Python logging mechanisms which are then funneled into Loguru or you can use the Loguru logging methods.
6 |
7 | ## Install
8 |
9 | `pip install django-easy-logging`
10 |
11 | ## Usage
12 |
13 | In your `settings.py` towards the end of the file add:
14 |
15 | ```python
16 | from dj_easy_log import load_loguru
17 |
18 | load_loguru(globals())
19 | ```
20 |
21 | In your other files, use Loguru methods for logging.
22 |
23 | ```python
24 | from loguru import logger
25 |
26 | logger.debug("That's it, beautiful and simple logging!")
27 |
28 | logger.info("If you're using Python {}, prefer {feature} of course!", 3.6, feature="f-strings")
29 | ```
30 |
31 | **Note:** Any existing logging is funneled into loguru when using the defualt settings. Loguru is used as a sink as [outlined in the docs](https://github.com/Delgan/loguru#entirely-compatible-with-standard-logging).
32 |
33 | ## Customization
34 |
35 | ### Log Level
36 |
37 | The default log level in DEBUG is `INFO`. Otherwise the default level is `ERROR`.
38 |
39 | You can override the log level with the env `LOGLEVEL`.
40 |
41 | or
42 |
43 | pass in a log level into `load_loguru`.
44 |
45 | **Example:** `load_loguru(globals(), loglevel="WARNING")`
46 |
47 |
48 | ### Logging Config
49 |
50 | The `LOGGING` config dict is generated automatically or you can pass in your own. The default is created by [generate_logging_config](https://github.com/neutron-sync/django-easy-logging/blob/main/dj_easy_log.py#L9-L33)
51 |
52 | **Example:** `load_loguru(globals(), logging_config=MY_LOGGING_CONFIG)`
53 |
54 | ### Configuring Loguru
55 |
56 | You can pass in a function that configures Loguru.
57 |
58 | **Example:**
59 |
60 | ```python
61 | def setup_loguru(logger, settings_dict):
62 | if not settings_dict['DEBUG']:
63 | logger.add("django.log", rotation="100 MB")
64 |
65 | load_loguru(globals(), configure_func=setup_loguru)
66 | ```
67 |
68 | ### Configuring the Default Format
69 |
70 | `export LOGURU_FORMAT="{time:HH:mm:ss} | {name}:{line} | {level} - {message}"`
71 |
72 | See the [record dict documention](https://loguru.readthedocs.io/en/stable/api/logger.html#record) for other available formatting options. And see [color markups](https://loguru.readthedocs.io/en/stable/api/logger.html#color) for more info on coloring and markups.
73 |
74 | ## Shameless Plugs
75 |
76 | I built this library originally for the [NeutronSync Service](https://www.neutronsync.com/). So if you would like to support this project please support the service with a subscription to NeutronSync or a [donation](https://github.com/sponsors/neutron-sync) to the open source libraries.
77 |
--------------------------------------------------------------------------------
/conftest.py:
--------------------------------------------------------------------------------
1 | from importlib import reload
2 |
3 | import pytest
4 | import dj_easy_log
5 |
6 |
7 | @pytest.fixture
8 | def load_loguru():
9 | reload(dj_easy_log)
10 | return dj_easy_log.load_loguru
11 |
--------------------------------------------------------------------------------
/dj_easy_log.py:
--------------------------------------------------------------------------------
1 | from loguru import logger
2 |
3 | import os
4 | import logging
5 |
6 | LOGGING_LOADED = False
7 |
8 |
9 | def generate_logging_config(loglevel):
10 | return {
11 | 'version': 1,
12 | 'disable_existing_loggers': True,
13 | 'formatters': {
14 | 'simple': {
15 | 'format': '{message}',
16 | 'style': '{',
17 | },
18 | },
19 | 'filters': {},
20 | 'handlers': {
21 | 'console': {
22 | 'level': loglevel,
23 | 'class': 'logging.NullHandler',
24 | 'formatter': 'simple'
25 | }
26 | },
27 | 'loggers': {
28 | 'django': {
29 | 'handlers': ['console'],
30 | 'propagate': True,
31 | }
32 | }
33 | }
34 |
35 |
36 | class InterceptHandler(logging.Handler):
37 |
38 | def emit(self, record):
39 | # Get corresponding Loguru level if it exists
40 | try:
41 | level = logger.level(record.levelname).name
42 | except ValueError:
43 | level = record.levelno
44 |
45 | # Find caller from where originated the logged message
46 | frame, depth = logging.currentframe(), 2
47 | while frame.f_code.co_filename == logging.__file__:
48 | frame = frame.f_back
49 | depth += 1
50 |
51 | logger.opt(depth=depth, exception=record.exc_info).log(level, record.getMessage())
52 |
53 |
54 | def load_loguru(settings, configure_func=None, logging_config=None, loglevel=None, force_reload=False):
55 | global LOGGING_LOADED
56 |
57 | if loglevel is None:
58 | if settings.get('DEBUG'):
59 | loglevel = os.environ.get('LOGLEVEL', 'INFO')
60 |
61 | else:
62 | loglevel = os.environ.get('LOGLEVEL', 'ERROR')
63 |
64 | if logging_config is None:
65 | logging_config = generate_logging_config(loglevel)
66 |
67 | if not LOGGING_LOADED or force_reload:
68 | if configure_func is not None:
69 | configure_func(logger, settings)
70 |
71 | logging.basicConfig(handlers=[InterceptHandler()], level=getattr(logging, loglevel))
72 | LOGGING_LOADED = True
73 |
74 | ret = {'LOGGING': logging_config, 'LOGLEVEL': loglevel, 'LOGGER': logger}
75 | settings.update(ret)
76 | return ret
77 |
--------------------------------------------------------------------------------
/pdm.lock:
--------------------------------------------------------------------------------
1 | # This file is @generated by PDM.
2 | # It is not intended for manual editing.
3 |
4 | [metadata]
5 | groups = ["default", "dev"]
6 | strategy = ["cross_platform"]
7 | lock_version = "4.4.1"
8 | content_hash = "sha256:6bce9feb8423e7a189192c46fd8e90ca65aaa79ec69379f71c55cf6016de4110"
9 |
10 | [[package]]
11 | name = "colorama"
12 | version = "0.4.4"
13 | requires_python = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
14 | summary = "Cross-platform colored terminal text."
15 | files = [
16 | {file = "colorama-0.4.4-py2.py3-none-any.whl", hash = "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"},
17 | {file = "colorama-0.4.4.tar.gz", hash = "sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b"},
18 | ]
19 |
20 | [[package]]
21 | name = "exceptiongroup"
22 | version = "1.2.0"
23 | requires_python = ">=3.7"
24 | summary = "Backport of PEP 654 (exception groups)"
25 | files = [
26 | {file = "exceptiongroup-1.2.0-py3-none-any.whl", hash = "sha256:4bfd3996ac73b41e9b9628b04e079f193850720ea5945fc96a08633c66912f14"},
27 | {file = "exceptiongroup-1.2.0.tar.gz", hash = "sha256:91f5c769735f051a4290d52edd0858999b57e5876e9f85937691bd4c9fa3ed68"},
28 | ]
29 |
30 | [[package]]
31 | name = "importlib-metadata"
32 | version = "6.7.0"
33 | requires_python = ">=3.7"
34 | summary = "Read metadata from Python packages"
35 | dependencies = [
36 | "typing-extensions>=3.6.4; python_version < \"3.8\"",
37 | "zipp>=0.5",
38 | ]
39 | files = [
40 | {file = "importlib_metadata-6.7.0-py3-none-any.whl", hash = "sha256:cb52082e659e97afc5dac71e79de97d8681de3aa07ff18578330904a9d18e5b5"},
41 | {file = "importlib_metadata-6.7.0.tar.gz", hash = "sha256:1aaf550d4f73e5d6783e7acb77aec43d49da8017410afae93822cc9cca98c4d4"},
42 | ]
43 |
44 | [[package]]
45 | name = "iniconfig"
46 | version = "1.1.1"
47 | summary = "iniconfig: brain-dead simple config-ini parsing"
48 | files = [
49 | {file = "iniconfig-1.1.1-py2.py3-none-any.whl", hash = "sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3"},
50 | {file = "iniconfig-1.1.1.tar.gz", hash = "sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32"},
51 | ]
52 |
53 | [[package]]
54 | name = "loguru"
55 | version = "0.7.2"
56 | requires_python = ">=3.5"
57 | summary = "Python logging made (stupidly) simple"
58 | dependencies = [
59 | "colorama>=0.3.4; sys_platform == \"win32\"",
60 | "win32-setctime>=1.0.0; sys_platform == \"win32\"",
61 | ]
62 | files = [
63 | {file = "loguru-0.7.2-py3-none-any.whl", hash = "sha256:003d71e3d3ed35f0f8984898359d65b79e5b21943f78af86aa5491210429b8eb"},
64 | {file = "loguru-0.7.2.tar.gz", hash = "sha256:e671a53522515f34fd406340ee968cb9ecafbc4b36c679da03c18fd8d0bd51ac"},
65 | ]
66 |
67 | [[package]]
68 | name = "packaging"
69 | version = "21.3"
70 | requires_python = ">=3.6"
71 | summary = "Core utilities for Python packages"
72 | dependencies = [
73 | "pyparsing!=3.0.5,>=2.0.2",
74 | ]
75 | files = [
76 | {file = "packaging-21.3-py3-none-any.whl", hash = "sha256:ef103e05f519cdc783ae24ea4e2e0f508a9c99b2d4969652eed6a2e1ea5bd522"},
77 | {file = "packaging-21.3.tar.gz", hash = "sha256:dd47c42927d89ab911e606518907cc2d3a1f38bbd026385970643f9c5b8ecfeb"},
78 | ]
79 |
80 | [[package]]
81 | name = "platformdirs"
82 | version = "4.0.0"
83 | requires_python = ">=3.7"
84 | summary = "A small Python package for determining appropriate platform-specific dirs, e.g. a \"user data dir\"."
85 | dependencies = [
86 | "typing-extensions>=4.7.1; python_version < \"3.8\"",
87 | ]
88 | files = [
89 | {file = "platformdirs-4.0.0-py3-none-any.whl", hash = "sha256:118c954d7e949b35437270383a3f2531e99dd93cf7ce4dc8340d3356d30f173b"},
90 | {file = "platformdirs-4.0.0.tar.gz", hash = "sha256:cb633b2bcf10c51af60beb0ab06d2f1d69064b43abf4c185ca6b28865f3f9731"},
91 | ]
92 |
93 | [[package]]
94 | name = "pluggy"
95 | version = "1.0.0"
96 | requires_python = ">=3.6"
97 | summary = "plugin and hook calling mechanisms for python"
98 | dependencies = [
99 | "importlib-metadata>=0.12; python_version < \"3.8\"",
100 | ]
101 | files = [
102 | {file = "pluggy-1.0.0-py2.py3-none-any.whl", hash = "sha256:74134bbf457f031a36d68416e1509f34bd5ccc019f0bcc952c7b909d06b37bd3"},
103 | {file = "pluggy-1.0.0.tar.gz", hash = "sha256:4224373bacce55f955a878bf9cfa763c1e360858e330072059e10bad68531159"},
104 | ]
105 |
106 | [[package]]
107 | name = "pyparsing"
108 | version = "3.0.7"
109 | requires_python = ">=3.6"
110 | summary = "Python parsing module"
111 | files = [
112 | {file = "pyparsing-3.0.7-py3-none-any.whl", hash = "sha256:a6c06a88f252e6c322f65faf8f418b16213b51bdfaece0524c1c1bc30c63c484"},
113 | {file = "pyparsing-3.0.7.tar.gz", hash = "sha256:18ee9022775d270c55187733956460083db60b37d0d0fb357445f3094eed3eea"},
114 | ]
115 |
116 | [[package]]
117 | name = "pytest"
118 | version = "7.4.4"
119 | requires_python = ">=3.7"
120 | summary = "pytest: simple powerful testing with Python"
121 | dependencies = [
122 | "colorama; sys_platform == \"win32\"",
123 | "exceptiongroup>=1.0.0rc8; python_version < \"3.11\"",
124 | "importlib-metadata>=0.12; python_version < \"3.8\"",
125 | "iniconfig",
126 | "packaging",
127 | "pluggy<2.0,>=0.12",
128 | "tomli>=1.0.0; python_version < \"3.11\"",
129 | ]
130 | files = [
131 | {file = "pytest-7.4.4-py3-none-any.whl", hash = "sha256:b090cdf5ed60bf4c45261be03239c2c1c22df034fbffe691abe93cd80cea01d8"},
132 | {file = "pytest-7.4.4.tar.gz", hash = "sha256:2cf0005922c6ace4a3e2ec8b4080eb0d9753fdc93107415332f50ce9e7994280"},
133 | ]
134 |
135 | [[package]]
136 | name = "toml"
137 | version = "0.10.2"
138 | requires_python = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*"
139 | summary = "Python Library for Tom's Obvious, Minimal Language"
140 | files = [
141 | {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"},
142 | {file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"},
143 | ]
144 |
145 | [[package]]
146 | name = "tomli"
147 | version = "2.0.1"
148 | requires_python = ">=3.7"
149 | summary = "A lil' TOML parser"
150 | files = [
151 | {file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"},
152 | {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"},
153 | ]
154 |
155 | [[package]]
156 | name = "typing-extensions"
157 | version = "4.7.1"
158 | requires_python = ">=3.7"
159 | summary = "Backported and Experimental Type Hints for Python 3.7+"
160 | files = [
161 | {file = "typing_extensions-4.7.1-py3-none-any.whl", hash = "sha256:440d5dd3af93b060174bf433bccd69b0babc3b15b1a8dca43789fd7f61514b36"},
162 | {file = "typing_extensions-4.7.1.tar.gz", hash = "sha256:b75ddc264f0ba5615db7ba217daeb99701ad295353c45f9e95963337ceeeffb2"},
163 | ]
164 |
165 | [[package]]
166 | name = "win32-setctime"
167 | version = "1.1.0"
168 | requires_python = ">=3.5"
169 | summary = "A small Python utility to set file creation time on Windows"
170 | files = [
171 | {file = "win32_setctime-1.1.0-py3-none-any.whl", hash = "sha256:231db239e959c2fe7eb1d7dc129f11172354f98361c4fa2d6d2d7e278baa8aad"},
172 | {file = "win32_setctime-1.1.0.tar.gz", hash = "sha256:15cf5750465118d6929ae4de4eb46e8edae9a5634350c01ba582df868e932cb2"},
173 | ]
174 |
175 | [[package]]
176 | name = "yapf"
177 | version = "0.40.2"
178 | requires_python = ">=3.7"
179 | summary = "A formatter for Python code"
180 | dependencies = [
181 | "importlib-metadata>=6.6.0",
182 | "platformdirs>=3.5.1",
183 | "tomli>=2.0.1",
184 | ]
185 | files = [
186 | {file = "yapf-0.40.2-py3-none-any.whl", hash = "sha256:adc8b5dd02c0143108878c499284205adb258aad6db6634e5b869e7ee2bd548b"},
187 | {file = "yapf-0.40.2.tar.gz", hash = "sha256:4dab8a5ed7134e26d57c1647c7483afb3f136878b579062b786c9ba16b94637b"},
188 | ]
189 |
190 | [[package]]
191 | name = "zipp"
192 | version = "3.7.0"
193 | requires_python = ">=3.7"
194 | summary = "Backport of pathlib-compatible object wrapper for zip files"
195 | files = [
196 | {file = "zipp-3.7.0-py3-none-any.whl", hash = "sha256:b47250dd24f92b7dd6a0a8fc5244da14608f3ca90a5efcd37a3b1642fac9a375"},
197 | {file = "zipp-3.7.0.tar.gz", hash = "sha256:9f50f446828eb9d45b267433fd3e9da8d801f614129124863f9c51ebceafb87d"},
198 | ]
199 |
--------------------------------------------------------------------------------
/pyproject.toml:
--------------------------------------------------------------------------------
1 | [project]
2 | name = "django-easy-logging"
3 | version = "0.70"
4 | description = "Easy Django logging with Loguru"
5 | authors = [
6 | {name = "Paul Bailey", email = "paul@neutron.studio"},
7 | ]
8 | dependencies = [
9 | "loguru>=0.7.0"]
10 | requires-python = ">=3.7"
11 | license = {text = "MIT"}
12 | readme = "README.md"
13 |
14 | [project.urls]
15 | homepage = "https://github.com/neutron-sync/django-easy-logging"
16 |
17 | [project.optional-dependencies]
18 | [tool]
19 | [tool.pdm]
20 | [tool.pdm.dev-dependencies]
21 | dev = [
22 | "toml>=0.10.2",
23 | "pytest>=7.0.0",
24 | "yapf>=0.32.0",
25 | ]
26 |
27 | [build-system]
28 | requires = ["pdm-pep517"]
29 | build-backend = "pdm.pep517.api"
30 |
31 | [tool.pdm.scripts]
32 | _.env_file = ".env"
33 | publish = "pdm publish --username __token__ --password $PDM_PUBLISH_PASSWORD"
34 | format = "yapf -rpi -vv ."
35 | check_format = "yapf -rpd ."
36 | test = "pytest test_easy_log.py"
37 |
--------------------------------------------------------------------------------
/pytest.ini:
--------------------------------------------------------------------------------
1 | [pytest]
2 | log_cli=True
3 |
--------------------------------------------------------------------------------
/test_easy_log.py:
--------------------------------------------------------------------------------
1 | import os
2 | from pathlib import Path
3 |
4 |
5 | def test_easy_debug(load_loguru):
6 | ret = load_loguru({'DEBUG': True})
7 | assert ret['LOGLEVEL'] == 'INFO'
8 |
9 |
10 | def test_easy_no_debug(load_loguru):
11 | ret = load_loguru({'DEBUG': False})
12 | assert ret['LOGLEVEL'] == 'ERROR'
13 |
14 |
15 | def test_configure(load_loguru):
16 | log_path = Path(__file__).parent / 'narf.log'
17 |
18 | if log_path.exists():
19 | log_path.unlink()
20 |
21 | def setup(logger, settings):
22 | logger.add(log_path)
23 |
24 | ret = load_loguru({'DEBUG': True}, configure_func=setup)
25 | ret['LOGGER'].info('BARF')
26 |
27 | assert log_path.exists()
28 |
29 |
30 | def test_custom_config(load_loguru):
31 | ret = load_loguru({'DEBUG': False}, logging_config={})
32 | assert len(ret['LOGGING']) == 0
33 |
34 |
35 | def test_level(load_loguru):
36 | ret = load_loguru({'DEBUG': False}, loglevel="WARNING")
37 | assert ret['LOGLEVEL'] == 'WARNING'
38 |
39 |
40 | def test_double_load(load_loguru):
41 | try:
42 | ret = load_loguru({'DEBUG': False})
43 | ret = load_loguru({'DEBUG': False})
44 |
45 | except Exception as exc:
46 | assert False, f"Raised an exception {exc}"
47 |
--------------------------------------------------------------------------------