{"id":19146969,"url":"https://github.com/keitheis/alog","last_synced_at":"2025-04-16T01:19:57.054Z","repository":{"id":45294027,"uuid":"65563270","full_name":"keitheis/alog","owner":"keitheis","description":"Update: use loguru instead. Simple straight logging your Python code","archived":false,"fork":false,"pushed_at":"2021-12-23T16:35:48.000Z","size":71,"stargazers_count":38,"open_issues_count":10,"forks_count":6,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-10T17:54:26.140Z","etag":null,"topics":["debug","helper","logging","print","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/keitheis.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES.rst","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-12T15:25:17.000Z","updated_at":"2022-08-16T04:06:22.000Z","dependencies_parsed_at":"2022-09-02T14:12:34.605Z","dependency_job_id":null,"html_url":"https://github.com/keitheis/alog","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keitheis%2Falog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keitheis%2Falog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keitheis%2Falog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/keitheis%2Falog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/keitheis","download_url":"https://codeload.github.com/keitheis/alog/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249129775,"owners_count":21217437,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["debug","helper","logging","print","python"],"created_at":"2024-11-09T07:48:31.031Z","updated_at":"2025-04-16T01:19:57.036Z","avatar_url":"https://github.com/keitheis.png","language":"Python","readme":"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  \u003e\u003e\u003e import alog\n  \u003e\u003e\u003e alog.info(\"Hi.\")\n  2016-12-18 20:44:30 INFO  \u003cstdin\u003e Hi.\n  \u003e\u003e\u003e def test():\n  ...     alog.info(\"Test 1\")\n  ...     alog.error(\"Test 2\")\n  ...\n  \u003e\u003e\u003e test()\n  2016-12-18 20:45:19 INFO  \u003cstdin:2\u003e Test 1\n  2016-12-18 20:45:19 ERROR \u003cstdin:3\u003e Test 2\n  \u003e\u003e\u003e alog.set_level(\"ERROR\")\n  \u003e\u003e\u003e test()\n  2016-12-18 20:45:41 ERROR \u003cstdin:3\u003e 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  \u003cIPython\u003e 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  \u003e\u003e\u003e 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  \u003e\u003e\u003e 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\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkeitheis%2Falog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkeitheis%2Falog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkeitheis%2Falog/lists"}