{"id":13821049,"url":"https://github.com/ELHoussineT/qlogging","last_synced_at":"2025-05-16T12:32:22.183Z","repository":{"id":57458996,"uuid":"368434095","full_name":"ELHoussineT/qlogging","owner":"ELHoussineT","description":"Beautifully colored, quick and simple Python logging","archived":true,"fork":false,"pushed_at":"2021-05-22T14:05:05.000Z","size":202,"stargazers_count":42,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-09T15:18:38.001Z","etag":null,"topics":["colored-log","colored-logging","file-logging","jupyter","jupyter-lab","jupyter-notebook","lab","logging","logging-file","notebook","python","python3"],"latest_commit_sha":null,"homepage":"","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/ELHoussineT.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2021-05-18T07:08:56.000Z","updated_at":"2024-12-11T16:24:48.000Z","dependencies_parsed_at":"2022-09-10T05:50:46.533Z","dependency_job_id":null,"html_url":"https://github.com/ELHoussineT/qlogging","commit_stats":null,"previous_names":["sinkingtitanic/qlogging"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ELHoussineT%2Fqlogging","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ELHoussineT%2Fqlogging/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ELHoussineT%2Fqlogging/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ELHoussineT%2Fqlogging/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ELHoussineT","download_url":"https://codeload.github.com/ELHoussineT/qlogging/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254530370,"owners_count":22086600,"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":["colored-log","colored-logging","file-logging","jupyter","jupyter-lab","jupyter-notebook","lab","logging","logging-file","notebook","python","python3"],"created_at":"2024-08-04T08:01:14.358Z","updated_at":"2025-05-16T12:32:17.165Z","avatar_url":"https://github.com/ELHoussineT.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Python Quick Logging | QLogging\n\nBeautifully colored, quick and simple Python logging. This logger is based on [Python logging package](https://docs.python.org/3/library/logging.html) \n\n[![version](https://img.shields.io/badge/Version-1.2.8-lightgrey)](https://github.com/sinkingtitanic/qlogging)\n[![build](https://img.shields.io/badge/Pypi%20Build-Stable-blue)](https://pypi.org/project/qlogging/)\n[![python-version](https://img.shields.io/badge/Python-3^-success)](https://www.python.org/downloads/)\n[![coverage](https://img.shields.io/badge/coverage-%25100-success)](https://pypi.org/project/qlogging/)\n\n## Screenshots: \n\n### Terminal/CMD\n![Preview](https://raw.githubusercontent.com/sinkingtitanic/qlogging/main/screenshots/terminal.png)\n### Notebooks: \n![Preview](https://raw.githubusercontent.com/sinkingtitanic/qlogging/main/screenshots/notebook.png)\n### Windows: \n![Preview](https://raw.githubusercontent.com/sinkingtitanic/qlogging/main/screenshots/windows.png)\n\n\n## Features\n\n* Color logging in Terminal and CMD  \n* Color logging in Jupyter Notebook and Jupyter Lab\n* Color logging in Kaggle Notebook \n* Color logging in Google Colab Notebook \n* Know which function the logger was called from \n* Know while line number the logger was called from \n* Support logging to a file \n* Simple and clean one-liner\n* Customizable \n\n\n## Installation\n\n```\n$ pip install qlogging\n```\n\n## Examples\n\n### Logging only to console/notebook: \n\n```\nimport qlogging\nlogger = qlogging.get_logger(level='debug')\n\nlogger.debug(\"This is debug\") \nlogger.info(\"This is info\")\nlogger.warning(\"This is warning\")\nlogger.error(\"This is an error\")\nlogger.critical(\"This is a critical\")\n```\n\nOutput (output format: `\u003ctime\u003e \u003cfunction_name\u003e,\u003cline#\u003e| \u003clog_message\u003e`): \n```\n12:21:37 foo(),3| This is debug \n12:21:37 foo(),4| This is info \n12:21:37 foo(),5| This is warning \n12:21:37 foo(),6| This is an error \n12:21:37 foo(),7| This is a critical \n```\n____\n### Logging to console/terminal and a log file (append if log file exists): \n```\nimport qlogging\nlogger = qlogging.get_logger(level='debug', logfile='my_log.log')\n```\n____\n### Logging to console/terminal and a log file (overwrite if log file exists): \n```\nimport qlogging\nlogger = qlogging.get_logger(level='debug', logfile='my_log.log', logfilemode='w')\n```\n____\n### Logging with `loggingmode='long'` (default is `loggingmode='short'`): \n```\nimport qlogging\nlogger = qlogging.get_logger(level='debug', loggingmode='long')\n\nlogger.debug(\"This is debug\") \n```\nOutput (output format: `\u003cdate\u003e \u003ctime\u003e | \u003cfile_name\u003e | \u003cfunction_name\u003e,\u003cline#\u003e| \u003clog_message\u003e`): \n```\n2021-05-18 12:38:22 | \u003cmain.py\u003e | \u003cfoo()\u003e,4 | This is debug\n```\n\n\n\n\n## Easy Customization\n\nCustomize your logger based on the following `get_logger()` function parameters \n\n```\ndef get_logger(\n    level=\"info\",\n    logfile=None,\n    logfilemode=\"a\",\n    loggingmode=\"short\",\n    format_str=None,\n    file_format_str=None,\n    format_date=None,\n    colors=None,\n    logger_config=None,\n):\n    \"\"\"\n    returns Python logging based logger formatted with colors\n\n    :param level: (DEFAULT='info') str of logging level, each str option is mapped to Python logging levels, str options:\n                        'info': logging.INFO,\n                        'debug': logging.DEBUG,\n                        'warning': logging.WARNING,\n                        'error': logging.ERROR,\n                        'critical': logging.CRITICAL,\n                        'notset': logging.NOTSET\n    :param logfile: (DEFAULT=None) str path where to save log file, example: '/tmp/my_log.log'\n    :param logfilemode: (DEFAULT='a') str of log file writing mode, same as the ones documented at Python logging package. options:\n                        'a': appends to logfile\n                        'w': overwrites logfile\n    :param loggingmode: (DEFAULT='short') str logging mode to be selected. options:\n                        'short': will use short str format ('%(asctime)s %(funcName)s,%(lineno)s| %(message)s') and short date format ('%H:%M:%S')\n                        'medium': will use long str format ('%(asctime)s | %(filename)s | %(funcName)s,%(lineno)s | %(message)s') and long date format ('%Y-%m-%d %H:%M:%S')\n                        'manual': you need to set :param format_str: and :param format_date: yourself\n    :param format_str: (DEFAULT=None) str of format logging string for console, only set this if you selected :param loggingmode: as 'manual'. example (the style is always '%', see python logging module for more info):\n                        '%(asctime)s | %(filename)s | %(funcName)s,%(lineno)s | %(message)s'\n    :param file_format_str: (DEFAULT=None) str of format logging string for logfile (if you keep it None, we will use what you passed in :param format_str:), only set this if you selected :param loggingmode: as 'manual'. example (the style is always '%', see python logging module for more info):\n                        '%(asctime)s | %(filename)s | %(funcName)s,%(lineno)s | %(message)s'\n    :param date_str: (DEFAULT=None) str of date logging string, only set this if you selected :param loggingmode: as 'manual'. example:\n                        '%Y-%m-%d %H:%M:%S'\n    :param colors: (DEFAULT=None) dict of color settings, only set this if you selected :param loggingmode: as 'manual'. example:\n                        {\n                            'DEBUG': Fore.CYAN + Style.BRIGHT,\n                            'INFO': Fore.GREEN + Style.BRIGHT,\n                            'WARNING': Fore.YELLOW + Style.BRIGHT,\n                            'ERROR': Fore.RED + Style.BRIGHT,\n                            'CRITICAL': Fore.RED + Back.WHITE + Style.BRIGHT,\n                        }\n    :param logger_config: (DEFAULT=None) dict python logger config if you want to fully overwrite configs. example:\n                        {\n                            \"version\": 1,\n                            \"disable_existing_loggers\": False,\n                            \"formatters\": {\n                                \"qlog\": {\n                                    \"()\": \"qlogging.qlogging.ColoredFormatter\",\n                                    \"colors\":  {\n                                        'DEBUG': Fore.CYAN + Style.BRIGHT,\n                                        'INFO': Fore.GREEN + Style.BRIGHT,\n                                        'WARNING': Fore.YELLOW + Style.BRIGHT,\n                                        'ERROR': Fore.RED + Style.BRIGHT,\n                                        'CRITICAL': Fore.RED + Back.WHITE + Style.BRIGHT,\n                                    },\n                                    \"format\": \"%(asctime)s [%(levelname)s] %(name)s: %(message)s\",\n                                    \"datefmt\":'%H:%M:%S'\n                                },\n                            },\n                            \"handlers\": {\n                                \"console\": {\n                                    \"level\": \"DEBUG\",\n                                    \"formatter\": \"qlog\",\n                                    \"class\": \"logging.StreamHandler\",\n                                    \"stream\": \"ext://sys.stdout\",\n                                },\n                            },\n                            \"loggers\": {\n                                \"\": {\n                                    \"handlers\": [\"console\"],\n                                    \"level\": \"DEBUG\",\n                                    \"propagate\": True,\n                                },\n                            },\n                        }\n    :return: formated Python logging instance\n    \"\"\"\n```\n\n## Alternatives\n\n* [coloredlogs 15.0](https://pypi.org/project/coloredlogs/): does not support coloring in notebooks.\n* [colorlog 5.0.1](https://pypi.org/project/colorlog/): does not support coloring in notebooks.\n\n## Credit: \n* [colorama](https://github.com/tartley/colorama)\n* [joshbode](https://gist.github.com/joshbode/58fac7ababc700f51e2a9ecdebe563ad)\n\n## License\nMIT License\nCopyright (c) 2021 Github Account SinkingTitanic Owner \n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FELHoussineT%2Fqlogging","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FELHoussineT%2Fqlogging","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FELHoussineT%2Fqlogging/lists"}