.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/fundamentals/example5_logging.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_fundamentals_example5_logging.py: Logging ======================== We illustrate basic ``dman`` logging functionality. .. GENERATED FROM PYTHON SOURCE LINES 9-11 When using ``dman`` you might have seen certain warning messages pop up, originating from the logger. This logger can be configured using :func:`dman.log.config`. .. GENERATED FROM PYTHON SOURCE LINES 11-17 .. code-block:: default import dman dman.log.config(level=dman.log.INFO) dman.log.info("This is some info.") .. rst-class:: sphx-glr-script-out .. code-block:: none [01/04/23 10:12:24] INFO This is some info. example5_logging.py:15 .. GENERATED FROM PYTHON SOURCE LINES 18-25 The syntax is similar to that of :func:`logging.basicConfig`. .. autofunction:: dman.log.config :noindex: By default we use the :class:`RichHandler` from :class:`rich`. If you want to use more standard logging you can use the following configuration .. GENERATED FROM PYTHON SOURCE LINES 25-31 .. code-block:: default dman.log.config( level=dman.log.INFO, use_rich=False, datefmt="%Y-%m-%d %H:%M:%S", force=True ) dman.log.backend.basicConfig dman.log.info("This is some info.") .. rst-class:: sphx-glr-script-out .. code-block:: none 2023-01-04 10:12:24 INFO: This is some info. .. GENERATED FROM PYTHON SOURCE LINES 32-33 The ``dman`` logger also supports some additional functionality. .. GENERATED FROM PYTHON SOURCE LINES 33-39 .. code-block:: default dman.log.config(level=dman.log.INFO, force=True, show_path=False) with dman.log.layer("example", "layer", prefix="owner"): dman.log.info("Indented", label="example") dman.log.io("This is an io command", label="example") dman.log.emphasize("This is an emphasized command", label="example") .. rst-class:: sphx-glr-script-out .. code-block:: none [01/04/23 10:12:24] INFO INFO [example]: Indented INFO [example]: This is an io command INFO [example]: This is an emphasized command INFO .. GENERATED FROM PYTHON SOURCE LINES 40-41 It is also used extensively during saving, loading and other internal functionality. .. GENERATED FROM PYTHON SOURCE LINES 41-43 .. code-block:: default _ = dman.save("person", {"name": "Adam", "age": 25, "position": [23, 12]}) .. rst-class:: sphx-glr-script-out .. code-block:: none INFO INFO [mount]: Creating empty directory ".dman/cache/examples:fundamentals:example5_logging /person". INFO [save]: saving dict with key "person" to ".dman/cache/examples:fundamentals:example5_logging /person/person.json". INFO INFO INFO INFO INFO [save]: finished saving dict with key "person" to ".dman/cache/examples:fundamentals:example5_logging /person/person.json". INFO .. GENERATED FROM PYTHON SOURCE LINES 44-47 Since these logs can be quite verbose when you set the level to ``INFO``, it can be useful to save the file somewhere. In fact you can do so within the ``dman`` file tree. .. GENERATED FROM PYTHON SOURCE LINES 47-68 .. code-block:: default @dman.modelclass class Experiment: value: int log: dman.FileTarget = dman.recordfield( name="dman.log", default_factory=dman.FileTarget ) exp = Experiment(25) dman.log.config( level=dman.log.INFO, stream=exp.log, force=True, console_style={"width": 160} ) dman.clean("experiment", generator="") dman.save("experiment", exp, generator="") dman.tui.walk_directory( dman.mount("experiment", generator=""), show_content=True, console=dman.tui.Console(width=180), ) .. rst-class:: sphx-glr-script-out .. code-block:: none 📂 .dman/experiment ┣━━ 📄 dman.log (2.4 kB) ┃ ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── ┃ [01/04/23 10:12:24] INFO repository.py:294 ┃ INFO [load]: file not available at ".dman/experiment/experiment.json", using default repository.py:296 ┃ INFO repository.py:294 ┃ INFO repository.py:217 ┃ INFO [mount]: Creating empty directory ".dman/experiment". path.py:418 ┃ INFO [save]: saving Experiment with key "experiment" to ".dman/experiment/experiment.json". repository.py:220 ┃ INFO serializables.py:626 ┃ INFO [modelclass]: serializing modelclass with fields ['value', 'log']. modelclasses.py:499 ┃ INFO [modelclass]: serializing value of type: "int" modelclasses.py:521 ┃ INFO [modelclass]: serializing log of type: "Record" modelclasses.py:521 ┃ INFO serializables.py:626 ┃ INFO serializables.py:626 ┃ INFO serializables.py:626 ┃ INFO [save]: finished saving Experiment with key "experiment" to ".dman/experiment/experiment.json". repository.py:227 ┃ INFO repository.py:217 ┃ ┃ ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── ┗━━ 📄 experiment.json (285 bytes) ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── { "_ser__type": "Experiment", "_ser__content": { "value": 25, "log": { "_ser__type": "_ser__record", "_ser__content": { "target": "dman.log", "sto_type": "_storable__stream" } } } } ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.056 seconds) .. _sphx_glr_download_gallery_fundamentals_example5_logging.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example5_logging.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example5_logging.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_