{"id":15528501,"url":"https://github.com/madkote/janus-logging","last_synced_at":"2025-04-23T12:33:29.938Z","repository":{"id":62572120,"uuid":"211309908","full_name":"madkote/janus-logging","owner":"madkote","description":"sync and async logging within one logger instance","archived":false,"fork":false,"pushed_at":"2020-11-25T21:06:03.000Z","size":41,"stargazers_count":4,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-12T09:14:40.829Z","etag":null,"topics":["async","json","logging","python3"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/madkote.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":"2019-09-27T12:03:51.000Z","updated_at":"2024-06-21T12:26:10.000Z","dependencies_parsed_at":"2022-11-03T18:26:12.576Z","dependency_job_id":null,"html_url":"https://github.com/madkote/janus-logging","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madkote%2Fjanus-logging","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madkote%2Fjanus-logging/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madkote%2Fjanus-logging/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/madkote%2Fjanus-logging/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/madkote","download_url":"https://codeload.github.com/madkote/janus-logging/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250435398,"owners_count":21430278,"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":["async","json","logging","python3"],"created_at":"2024-10-02T11:14:03.440Z","updated_at":"2025-04-23T12:33:29.843Z","avatar_url":"https://github.com/madkote.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"janus-logging\n=============\n.. image:: https://travis-ci.com/madkote/janus_logging.svg?branch=master\n    :target: https://travis-ci.com/madkote/janus-logging\n.. image:: https://codecov.io/gh/madkote/janus-logging/branch/master/graph/badge.svg\n    :target: https://codecov.io/gh/madkote/janus-logging\n.. image:: https://img.shields.io/pypi/v/janus_logging.svg\n    :target: https://pypi.python.org/pypi/janus-logging\n\nsync and async logging within one logger instance.\n\nInstallation\n------------\n\n.. code:: sh\n\n    pip install janus-logging\n\nUsage\n-----\n\nDefault\n~~~~~~~\n\n.. code:: python\n\n    import asyncio\n    import logging\n    import sys\n\n    import janus_logging\n\n    def threaded(sync_log, counter: int):\n        for i in range(counter):\n            sync_log.info('s-Hello #%s' % i)\n            sync_log.info('s-Finished #%s' % counter)\n\n    async def async_coro(async_log, counter: int):\n        for i in range(counter):\n            await async_log.info('aio-Hello #%s' % i)\n            await async_log.info('aio-Finished #%s' % counter)\n\n    #\n    counter = 4\n    name = 'my_janus_logger'\n    level = logging.DEBUG\n    stream = sys.stdout\n    loop = asyncio.get_event_loop()\n    #\n    logger = janus_logging.JanusLogger(name=name, level=level, loop=loop, stream=stream)\n    loop.run_until_complete(\n        asyncio.gather(\n        loop.run_in_executor(\n            None,\n            threaded,\n            logger.logger_sync(),\n            counter\n        ),\n        async_coro(\n            logger.logger_async(),\n            counter\n        )\n        )\n    )\n    logger.shutdown()\n    #\n    #\n    loop.close()\n\nThe output of above will look like:\n\n.. code:: sh\n\n    s-Hello #0\n    s-Hello #1\n    s-Hello #2\n    aio-Hello #0\n    s-Hello #3\n    s-Finished #4\n    aio-Hello #1\n    aio-Hello #2\n    aio-Hello #3\n    aio-Finished #4\n\nPlease note, that the output might be different on your instance.\n\nJSON\n~~~~\n\nSimply use *fixtures*.\n\n.. code:: python\n\n    import asyncio\n    import logging\n    import sys\n\n    import janus_logging\n\n    def threaded(sync_log, counter: int):\n        for i in range(counter):\n            sync_log.info(\n                's-Hello #%s' % i,\n                extra=dict(counter=i, log_type='sync', log_status='in progress')\n            )\n        sync_log.info(\n            's-Finished #%s' % counter,\n            extra=dict(total=counter, log_type='sync', log_status='finished')\n        )\n\n\n    async def async_coro(async_log, counter: int):\n        for i in range(counter):\n            await async_log.info(\n                'aio-Hello #%s' % i,\n                extra=dict(counter=i, log_type='async', log_status='in progress')\n            )\n        await async_log.info(\n            'aio-Finished #%s' % counter,\n            extra=dict(total=counter, log_type='async', log_status='finished')\n        )\n\n    #\n    counter = 4\n    name = 'my_janus_logger'\n    level = logging.DEBUG\n    stream = sys.stdout\n    loop = asyncio.get_event_loop()\n    #\n    logger = janus_logging.JanusLogger(\n        name=name,\n        level=level,\n        loop=loop,\n        fixture=janus_logging.fixture_json,\n        stream=stream,\n        extra=dict(bla='blabla')\n    )\n    loop.run_until_complete(\n        asyncio.gather(\n            loop.run_in_executor(\n                None,\n                threaded,\n                logger.logger_sync(logger_name='logger_sync'),\n                counter\n            ),\n            async_coro(\n                logger.logger_async(logger_name='logger_async'),\n                counter\n            )\n        )\n    )\n    logger.shutdown()\n    #\n    #\n    loop.close()\n\nThe output of above will look like:\n\n.. code:: sh\n\n    {\"level\": \"INFO\", \"msg\": \"s-Hello #0\", \"log_type\": \"sync\", \"bla\": \"blabla\", \"logger_name\": \"logger_sync\", \"counter\": 0, \"log_status\": \"in progress\", \"logged_at\": \"2019-09-27T12:00:02.517101+02:00\", \"line_numer\": 35, \"function\": \"threaded\", \"file_path\": \"demo_janus_log.py\"}\n    {\"level\": \"INFO\", \"msg\": \"aio-Hello #1\", \"log_type\": \"async\", \"logged_at\": \"2019-09-27T12:00:02.518000+02:00\", \"line_number\": 60, \"function\": \"info\", \"file_path\": \"/home/madkote/janus-logging/janus_logging/__init__.py\", \"bla\": \"blabla\", \"logger_name\": \"logger_async\", \"counter\": 1, \"log_status\": \"in progress\"}\n    ...\n\nCustom\n~~~~~~\n\nIf a custom logger, formatter, handler are required, then create custom\n*fixtures* and pass them to the ``JanusLogger``.\n\n.. code:: python\n\n    def fixture_custom(\n    \t\tname: str,\n    \t\tlevel: int,\n    \t\tloop: loop: asyncio.AbstractEventLoop,\n    \t\t**kwargs\n    \t\t) -\u003e logging.Logger:\n        ...\n        return ...\n\n    logger = janus_logging.JanusLogger(\n        ...,\n        fixture=fixture_custom,\n        ...\n    )\n\nDevelopment\n-----------\n\nIssues and suggestions are welcome through *issues*\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmadkote%2Fjanus-logging","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmadkote%2Fjanus-logging","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmadkote%2Fjanus-logging/lists"}