alog


Namealog JSON
Version 1.2.0 PyPI version JSON
download
home_pagehttps://github.com/keitheis/alog
SummaryYour goto Python logging without panic on context swtich
upload_time2021-08-09 16:31:48
maintainer
docs_urlNone
authorKeith Yang
requires_python
licenseApache 2.0
keywords simple basic application logging print
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            Alog
====

.. image:: https://travis-ci.com/keitheis/alog.svg?branch=master
  :target: https://travis-ci.com/keitheis/alog

.. image:: https://codecov.io/gh/keitheis/alog/branch/master/graph/badge.svg
  :target: https://codecov.io/gh/keitheis/alog

.. image:: http://img.shields.io/pypi/v/alog.svg?style=flat
   :target: https://pypi.org/pypi/alog

Your goto Python logging without panic on context swtich.

**Warning:** No more ``logger = logging.getLogger(__name__)`` in your every file.

.. code-block:: python

  >>> import alog
  >>> alog.info("Hi.")
  2016-12-18 20:44:30 INFO  <stdin> Hi.
  >>> def test():
  ...     alog.info("Test 1")
  ...     alog.error("Test 2")
  ...
  >>> test()
  2016-12-18 20:45:19 INFO  <stdin:2> Test 1
  2016-12-18 20:45:19 ERROR <stdin:3> Test 2
  >>> alog.set_level("ERROR")
  >>> test()
  2016-12-18 20:45:41 ERROR <stdin:3> Test 2

If you're new to logging, see `Why should you use logging instead of print`_.

Installation
------------

.. code-block::

  pip install alog

Features 
--------

- Instant logging with expected defaults.

  You can do logging instantly by reading a small piece of README.
  Alog comes with useful defaults:

  - A default logger.
  - Logging level: ``logging.INFO``
  - Logging format::

    "%(asctime)s %(levelname)-5.5s [parent_module.current_module:%(lineno)s]%(message)s",
    "%Y-%m-%d %H:%M:%S"

- No more **__name__** whenever you start to do logging in a module.

  Alog builds the default module names on the fly. 

- Compatible with default Python ``logging`` module.

  Alog is built upon default Python logging module. You can configure it by
  the same way of default Python logging module when it's needed.


Comparing ``alog`` with Python default ``logging`` module
---------------------------------------------------------

Comparing ``alog`` :

.. code-block:: python

    In [1]: import alog

    In [2]: alog.info("Hello alog!")
    2016-11-23 12:20:34 INFO  <IPython> Hello alog!

with ``logging`` module:

.. code-block:: python

    In [1]: import logging

    In [2]: logging.basicConfig(
       ...:     level=logging.INFO,
       ...:     format="%(asctime)s %(levelname)-5.5s "
       ...:            "[%(name)s:%(lineno)s] %(message)s")

    In [3]: # In every file you want to do log, otherwise %(names)s won't work.
    In [4]: logger = logging.getLogger(__name__)

    In [5]: logger.info("Hello log!")
    2016-11-23 12:16:30 INFO  [__main__:1] Hello log!


Tips
----

.. code-block:: python

    import alog

    a_complex_json_dict = {...}  # or a_complex_dict
    alog.info(alog.pformat(a_complex_dict))

    restaurant = Restaurant(...)
    alog.info(alog.pdir(restaurant))
    # or just skip attributes starts with "__":
    alog.info(alog.pdir(restaurant, str_not_startswith="__"))
    # instead of
    alog.info([attr for attr in dir(restaurant) if attr.startswith("_")])

    # Play threads?
    alog.turn_logging_thread_name(on=True)
    # Processes?
    alog.turn_logging_process_id(on=True)
    # No datetime wanted?
    alog.turn_logging_datetime(on=False)

Why should you use logging instead of print
-------------------------------------------

The main goal of logging is to figure out what was going on and to get the
insight. ``print``, by default, does simply pure string output. No timestamp,
no module hint, and no level control, comparing to a pretty logging record.

Lets start with ``aproject/models/user.py`` :

.. code-block:: python

  class User:
      def __init__(self, user_id, username):
          ...
          print(username)
          ...

What you got output of ``print`` :

.. code-block:: python

  >>> admin = User(1, "admin")
  "admin"


Now use ``alog`` :

.. code-block:: python

  import alog

  class User:
      def __init__(self, user_id, username):
          ...
          alog.info(username)
          ...

What you got output of ``alog.info`` :

.. code-block:: python

  >>> admin = User(1, "admin")
  2016-11-23 11:32:58 INFO  [models.user:6] admin

In the output of hundreds of lines, it helps (a lot).

What if you have used ``print`` a log? That's as easy:

.. code-block:: python

  import alog

  print = alog.info

  ... # A lot of print code no needed to change

1.2.0 (2021-08-09)
==================

 - Support Python 3.9
 - Remove Python 3.4 and 3.5 support.

1.1.0 (2020-02-10)
==================

 - Support Python 3.8
 - Fix broken ``set_format`` function when formatter argument is given.

1.0.0 (2019-04-03)
==================

 - Renamed:

   - ``turn_logging_datetime(on=True)``
   - ``turn_logging_thread_name(on=False)``
   - ``turn_logging_process_id(on=False)``

 - Support most same APIs between alog and Alogger.
 - Add ``alog.pdir()`` for handy replacing ``[attr for attr in dir(obj)
   if not attr.startswith("_")]``.

0.9.13 (2017-06-18)
===================

 - Fix not able to ``turn_log_datetime(on=False)``.

0.9.12 (2017-06-16)
===================

 - Support not showing_log_datetime by ``turn_log_datetime(on=False)``.

0.9.11 (2017-04-07)
===================

 - Add ``alog.getLogger()`` for handy replacing ``logging.getLogger``.

0.9.10 (2017-03-27)
===================

 - Default logging format asctime to "%Y-%m-%d %H:%M:%S" instead of
   "%Y-%m-%d,%H:%M:%S.%f".
 - Update package info and usage (setup.py, README, ...).

0.9.9 (2016-08-28)
==================

 - Update to turn_thread_name and turn_process_id.

0.9.8 (2016-08-27)
==================

 - Support showing_thread_name and showing_process_id.
 - Support global reset.

0.9.7 (2016-08-17)
==================

 - Better paths log for None default root name.

0.9.6 (2016-08-16)
==================

 - First public release.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/keitheis/alog",
    "name": "alog",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "simple basic application logging print",
    "author": "Keith Yang",
    "author_email": "yang@keitheis.org",
    "download_url": "https://files.pythonhosted.org/packages/13/fb/4fbdc1f58db31e98a52c4e05c6aca423f4b41086cd40db086a04d149b82d/alog-1.2.0.tar.gz",
    "platform": "",
    "description": "Alog\n====\n\n.. image:: https://travis-ci.com/keitheis/alog.svg?branch=master\n  :target: https://travis-ci.com/keitheis/alog\n\n.. image:: https://codecov.io/gh/keitheis/alog/branch/master/graph/badge.svg\n  :target: https://codecov.io/gh/keitheis/alog\n\n.. image:: http://img.shields.io/pypi/v/alog.svg?style=flat\n   :target: https://pypi.org/pypi/alog\n\nYour goto Python logging without panic on context swtich.\n\n**Warning:** No more ``logger = logging.getLogger(__name__)`` in your every file.\n\n.. code-block:: python\n\n  >>> import alog\n  >>> alog.info(\"Hi.\")\n  2016-12-18 20:44:30 INFO  <stdin> Hi.\n  >>> def test():\n  ...     alog.info(\"Test 1\")\n  ...     alog.error(\"Test 2\")\n  ...\n  >>> test()\n  2016-12-18 20:45:19 INFO  <stdin:2> Test 1\n  2016-12-18 20:45:19 ERROR <stdin:3> Test 2\n  >>> alog.set_level(\"ERROR\")\n  >>> test()\n  2016-12-18 20:45:41 ERROR <stdin:3> Test 2\n\nIf you're new to logging, see `Why should you use logging instead of print`_.\n\nInstallation\n------------\n\n.. code-block::\n\n  pip install alog\n\nFeatures \n--------\n\n- Instant logging with expected defaults.\n\n  You can do logging instantly by reading a small piece of README.\n  Alog comes with useful defaults:\n\n  - A default logger.\n  - Logging level: ``logging.INFO``\n  - Logging format::\n\n    \"%(asctime)s %(levelname)-5.5s [parent_module.current_module:%(lineno)s]%(message)s\",\n    \"%Y-%m-%d %H:%M:%S\"\n\n- No more **__name__** whenever you start to do logging in a module.\n\n  Alog builds the default module names on the fly. \n\n- Compatible with default Python ``logging`` module.\n\n  Alog is built upon default Python logging module. You can configure it by\n  the same way of default Python logging module when it's needed.\n\n\nComparing ``alog`` with Python default ``logging`` module\n---------------------------------------------------------\n\nComparing ``alog`` :\n\n.. code-block:: python\n\n    In [1]: import alog\n\n    In [2]: alog.info(\"Hello alog!\")\n    2016-11-23 12:20:34 INFO  <IPython> Hello alog!\n\nwith ``logging`` module:\n\n.. code-block:: python\n\n    In [1]: import logging\n\n    In [2]: logging.basicConfig(\n       ...:     level=logging.INFO,\n       ...:     format=\"%(asctime)s %(levelname)-5.5s \"\n       ...:            \"[%(name)s:%(lineno)s] %(message)s\")\n\n    In [3]: # In every file you want to do log, otherwise %(names)s won't work.\n    In [4]: logger = logging.getLogger(__name__)\n\n    In [5]: logger.info(\"Hello log!\")\n    2016-11-23 12:16:30 INFO  [__main__:1] Hello log!\n\n\nTips\n----\n\n.. code-block:: python\n\n    import alog\n\n    a_complex_json_dict = {...}  # or a_complex_dict\n    alog.info(alog.pformat(a_complex_dict))\n\n    restaurant = Restaurant(...)\n    alog.info(alog.pdir(restaurant))\n    # or just skip attributes starts with \"__\":\n    alog.info(alog.pdir(restaurant, str_not_startswith=\"__\"))\n    # instead of\n    alog.info([attr for attr in dir(restaurant) if attr.startswith(\"_\")])\n\n    # Play threads?\n    alog.turn_logging_thread_name(on=True)\n    # Processes?\n    alog.turn_logging_process_id(on=True)\n    # No datetime wanted?\n    alog.turn_logging_datetime(on=False)\n\nWhy should you use logging instead of print\n-------------------------------------------\n\nThe main goal of logging is to figure out what was going on and to get the\ninsight. ``print``, by default, does simply pure string output. No timestamp,\nno module hint, and no level control, comparing to a pretty logging record.\n\nLets start with ``aproject/models/user.py`` :\n\n.. code-block:: python\n\n  class User:\n      def __init__(self, user_id, username):\n          ...\n          print(username)\n          ...\n\nWhat you got output of ``print`` :\n\n.. code-block:: python\n\n  >>> admin = User(1, \"admin\")\n  \"admin\"\n\n\nNow use ``alog`` :\n\n.. code-block:: python\n\n  import alog\n\n  class User:\n      def __init__(self, user_id, username):\n          ...\n          alog.info(username)\n          ...\n\nWhat you got output of ``alog.info`` :\n\n.. code-block:: python\n\n  >>> admin = User(1, \"admin\")\n  2016-11-23 11:32:58 INFO  [models.user:6] admin\n\nIn the output of hundreds of lines, it helps (a lot).\n\nWhat if you have used ``print`` a log? That's as easy:\n\n.. code-block:: python\n\n  import alog\n\n  print = alog.info\n\n  ... # A lot of print code no needed to change\n\n1.2.0 (2021-08-09)\n==================\n\n - Support Python 3.9\n - Remove Python 3.4 and 3.5 support.\n\n1.1.0 (2020-02-10)\n==================\n\n - Support Python 3.8\n - Fix broken ``set_format`` function when formatter argument is given.\n\n1.0.0 (2019-04-03)\n==================\n\n - Renamed:\n\n   - ``turn_logging_datetime(on=True)``\n   - ``turn_logging_thread_name(on=False)``\n   - ``turn_logging_process_id(on=False)``\n\n - Support most same APIs between alog and Alogger.\n - Add ``alog.pdir()`` for handy replacing ``[attr for attr in dir(obj)\n   if not attr.startswith(\"_\")]``.\n\n0.9.13 (2017-06-18)\n===================\n\n - Fix not able to ``turn_log_datetime(on=False)``.\n\n0.9.12 (2017-06-16)\n===================\n\n - Support not showing_log_datetime by ``turn_log_datetime(on=False)``.\n\n0.9.11 (2017-04-07)\n===================\n\n - Add ``alog.getLogger()`` for handy replacing ``logging.getLogger``.\n\n0.9.10 (2017-03-27)\n===================\n\n - Default logging format asctime to \"%Y-%m-%d %H:%M:%S\" instead of\n   \"%Y-%m-%d,%H:%M:%S.%f\".\n - Update package info and usage (setup.py, README, ...).\n\n0.9.9 (2016-08-28)\n==================\n\n - Update to turn_thread_name and turn_process_id.\n\n0.9.8 (2016-08-27)\n==================\n\n - Support showing_thread_name and showing_process_id.\n - Support global reset.\n\n0.9.7 (2016-08-17)\n==================\n\n - Better paths log for None default root name.\n\n0.9.6 (2016-08-16)\n==================\n\n - First public release.\n\n\n",
    "bugtrack_url": null,
    "license": "Apache 2.0",
    "summary": "Your goto Python logging without panic on context swtich",
    "version": "1.2.0",
    "split_keywords": [
        "simple",
        "basic",
        "application",
        "logging",
        "print"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "76937b4a0e43899f8776e372298f68e4",
                "sha256": "8c1ad957531f7b78e6f881a078116c3966300a96d03d55b4d0e90cc8a2b0fe8d"
            },
            "downloads": -1,
            "filename": "alog-1.2.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "76937b4a0e43899f8776e372298f68e4",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 6706,
            "upload_time": "2021-08-09T16:31:46",
            "upload_time_iso_8601": "2021-08-09T16:31:46.693270Z",
            "url": "https://files.pythonhosted.org/packages/45/dd/9778ad06c608fd73a1d6e2238b5a28e5119824876a404465b1414bf7327c/alog-1.2.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "ada1f84931af92ef9fd0b99cdbded32e",
                "sha256": "c389a511f0a61137f01eb06a7646be338313a49a11384cf86d059bc0d76e6a91"
            },
            "downloads": -1,
            "filename": "alog-1.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "ada1f84931af92ef9fd0b99cdbded32e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 6712,
            "upload_time": "2021-08-09T16:31:48",
            "upload_time_iso_8601": "2021-08-09T16:31:48.482781Z",
            "url": "https://files.pythonhosted.org/packages/13/fb/4fbdc1f58db31e98a52c4e05c6aca423f4b41086cd40db086a04d149b82d/alog-1.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-08-09 16:31:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "keitheis",
    "github_project": "alog",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "alog"
}
        
Elapsed time: 0.03206s