--- title: Logging keywords: fastai sidebar: home_sidebar summary: "A logging utility module." description: "A logging utility module." nb_path: "nbs/utils/logging.ipynb" ---
{% raw %}
{% endraw %}

Open In Colab

{% raw %}
{% endraw %} {% raw %}

set_logger[source]

set_logger(log_path)

A Python module.

Args: log_path (str): Path where you want to save the log file

Examples:

```python
set_logger('./model_a.log')
logging.info('Model A Logging Test Success')
```
{% endraw %} {% raw %}
{% endraw %}

{% raw %}
import unittest


class TestLogger(unittest.TestCase):
    def setUp(self):
        set_logger('./model_a.log')
        logging.info('Model A Logging Test Success')

    def testLogger(self):
        self.assertTrue(Path('./model_a.log').resolve().is_file())

    def test2(self):
        self.assertFalse(os.path.getsize('./model_a.log')==0)


unittest.main(argv=[''], verbosity=2, exit=False)
test2 (__main__.TestLogger) ... 2021-12-05 09:34:23,519 P61 INFO Model A Logging Test Success
ok
testLogger (__main__.TestLogger) ... 2021-12-05 09:34:23,526 P61 INFO Model A Logging Test Success
ok

----------------------------------------------------------------------
Ran 2 tests in 0.013s

OK
<unittest.main.TestProgram at 0x7ff784310e10>
{% endraw %}

{% raw %}
Author: Sparsh A.

Last updated: 2021-12-05 09:34:45

Compiler    : GCC 7.5.0
OS          : Linux
Release     : 5.4.104+
Machine     : x86_64
Processor   : x86_64
CPU cores   : 2
Architecture: 64bit

logging: 0.5.1.2
IPython: 5.5.0

{% endraw %}