{"id":13598809,"url":"https://github.com/xolox/python-coloredlogs","last_synced_at":"2025-05-14T15:07:03.703Z","repository":{"id":8719107,"uuid":"10389547","full_name":"xolox/python-coloredlogs","owner":"xolox","description":"Colored terminal output for Python's logging module","archived":false,"fork":false,"pushed_at":"2024-06-12T18:02:58.000Z","size":945,"stargazers_count":549,"open_issues_count":36,"forks_count":45,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-05-14T04:41:42.843Z","etag":null,"topics":["ansi-colors","cron","html","logging","python","syslog","terminal"],"latest_commit_sha":null,"homepage":"https://coloredlogs.readthedocs.io","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/xolox.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-05-30T18:57:12.000Z","updated_at":"2025-05-10T03:01:02.000Z","dependencies_parsed_at":"2024-01-16T23:26:19.959Z","dependency_job_id":"1efa9d40-3805-4a4e-adfa-b24e1fbeba67","html_url":"https://github.com/xolox/python-coloredlogs","commit_stats":{"total_commits":249,"total_committers":15,"mean_commits":16.6,"dds":"0.15662650602409633","last_synced_commit":"65bdfe976ac0bf81e8c0bd9a98242b9d666b2859"},"previous_names":[],"tags_count":68,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xolox%2Fpython-coloredlogs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xolox%2Fpython-coloredlogs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xolox%2Fpython-coloredlogs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xolox%2Fpython-coloredlogs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xolox","download_url":"https://codeload.github.com/xolox/python-coloredlogs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254169507,"owners_count":22026212,"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":["ansi-colors","cron","html","logging","python","syslog","terminal"],"created_at":"2024-08-01T17:00:56.938Z","updated_at":"2025-05-14T15:07:03.660Z","avatar_url":"https://github.com/xolox.png","language":"Python","readme":"coloredlogs: Colored terminal output for Python's logging module\n================================================================\n\n.. image:: https://travis-ci.org/xolox/python-coloredlogs.svg?branch=master\n   :target: https://travis-ci.org/xolox/python-coloredlogs\n\n.. image:: https://coveralls.io/repos/github/xolox/python-coloredlogs/badge.svg?branch=master\n   :target: https://coveralls.io/github/xolox/python-coloredlogs?branch=master\n\nThe `coloredlogs` package enables colored terminal output for Python's logging_\nmodule. The ColoredFormatter_ class inherits from `logging.Formatter`_ and uses\n`ANSI escape sequences`_ to render your logging messages in color. It uses only\nstandard colors so it should work on any UNIX terminal. It's currently tested\non Python 2.7, 3.5+ and PyPy (2 and 3). On Windows `coloredlogs` automatically\ntries to enable native ANSI support (on up-to-date Windows 10 installations)\nand falls back on using colorama_ (if installed). Here is a screen shot of the\ndemo that is printed when the command ``coloredlogs --demo`` is executed:\n\n.. image:: https://coloredlogs.readthedocs.io/en/latest/_images/defaults.png\n\nNote that the screenshot above includes custom logging levels defined by my\nverboselogs_ package: if you install both `coloredlogs` and `verboselogs` it\nwill Just Work (`verboselogs` is of course not required to use\n`coloredlogs`).\n\n.. contents::\n   :local:\n\nInstallation\n------------\n\nThe `coloredlogs` package is available on PyPI_ which means installation should\nbe as simple as:\n\n.. code-block:: console\n\n   $ pip install coloredlogs\n\nThere's actually a multitude of ways to install Python packages (e.g. the `per\nuser site-packages directory`_, `virtual environments`_ or just installing\nsystem wide) and I have no intention of getting into that discussion here, so\nif this intimidates you then read up on your options before returning to these\ninstructions 😉.\n\nOptional dependencies\n~~~~~~~~~~~~~~~~~~~~~\n\nNative ANSI support on Windows requires an up-to-date Windows 10 installation.\nIf this is not working for you then consider installing the colorama_ package:\n\n.. code-block:: console\n\n   $ pip install colorama\n\nOnce colorama_ is installed it will be used automatically.\n\nUsage\n-----\n\nHere's an example of how easy it is to get started:\n\n.. code-block:: python\n\n   import coloredlogs, logging\n\n   # Create a logger object.\n   logger = logging.getLogger(__name__)\n\n   # By default the install() function installs a handler on the root logger,\n   # this means that log messages from your code and log messages from the\n   # libraries that you use will all show up on the terminal.\n   coloredlogs.install(level='DEBUG')\n\n   # If you don't want to see log messages from libraries, you can pass a\n   # specific logger object to the install() function. In this case only log\n   # messages originating from that logger will show up on the terminal.\n   coloredlogs.install(level='DEBUG', logger=logger)\n\n   # Some examples.\n   logger.debug(\"this is a debugging message\")\n   logger.info(\"this is an informational message\")\n   logger.warning(\"this is a warning message\")\n   logger.error(\"this is an error message\")\n   logger.critical(\"this is a critical message\")\n\nFormat of log messages\n----------------------\n\nThe ColoredFormatter_ class supports user defined log formats so you can use\nany log format you like. The default log format is as follows::\n\n %(asctime)s %(hostname)s %(name)s[%(process)d] %(levelname)s %(message)s\n\nThis log format results in the following output::\n\n 2015-10-23 03:32:22 peter-macbook coloredlogs.demo[30462] DEBUG message with level 'debug'\n 2015-10-23 03:32:23 peter-macbook coloredlogs.demo[30462] VERBOSE message with level 'verbose'\n 2015-10-23 03:32:24 peter-macbook coloredlogs.demo[30462] INFO message with level 'info'\n ...\n\nYou can customize the log format and styling using environment variables as\nwell as programmatically, please refer to the `online documentation`_ for\ndetails.\n\nEnabling millisecond precision\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nIf you're switching from `logging.basicConfig()`_ to `coloredlogs.install()`_\nyou may notice that timestamps no longer include milliseconds. This is because\ncoloredlogs doesn't output milliseconds in timestamps unless you explicitly\ntell it to. There are three ways to do that:\n\n1. The easy way is to pass the `milliseconds` argument to `coloredlogs.install()`_::\n\n    coloredlogs.install(milliseconds=True)\n\n   This became supported in `release 7.1`_ (due to `#16`_).\n\n2. Alternatively you can change the log format `to include 'msecs'`_::\n\n    %(asctime)s,%(msecs)03d %(hostname)s %(name)s[%(process)d] %(levelname)s %(message)s\n\n   Here's what the call to `coloredlogs.install()`_ would then look like::\n\n    coloredlogs.install(fmt='%(asctime)s,%(msecs)03d %(hostname)s %(name)s[%(process)d] %(levelname)s %(message)s')\n\n   Customizing the log format also enables you to change the delimiter that\n   separates seconds from milliseconds (the comma above). This became possible\n   in `release 3.0`_ which added support for user defined log formats.\n\n3. If the use of ``%(msecs)d`` isn't flexible enough you can instead add ``%f``\n   to the date/time format, it will be replaced by the value of ``%(msecs)03d``.\n   Support for the ``%f`` directive was added to `release 9.3`_ (due to `#45`_).\n\nCustom logging fields\n~~~~~~~~~~~~~~~~~~~~~\n\nThe following custom log format fields are supported:\n\n- ``%(hostname)s`` provides the hostname of the local system.\n- ``%(programname)s`` provides the name of the currently running program.\n- ``%(username)s`` provides the username of the currently logged in user.\n\nWhen `coloredlogs.install()`_ detects that any of these fields are used in the\nformat string the applicable logging.Filter_ subclasses are automatically\nregistered to populate the relevant log record fields.\n\nChanging text styles and colors\n-------------------------------\n\nThe online documentation contains `an example of customizing the text styles and\ncolors \u003chttps://coloredlogs.readthedocs.io/en/latest/api.html#changing-the-colors-styles\u003e`_.\n\nColored output from cron\n------------------------\n\nWhen `coloredlogs` is used in a cron_ job, the output that's e-mailed to you by\ncron won't contain any ANSI escape sequences because `coloredlogs` realizes\nthat it's not attached to an interactive terminal. If you'd like to have colors\ne-mailed to you by cron there are two ways to make it happen:\n\n.. contents::\n   :local:\n\nModifying your crontab\n~~~~~~~~~~~~~~~~~~~~~~\n\nHere's an example of a minimal crontab::\n\n    MAILTO=\"your-email-address@here\"\n    CONTENT_TYPE=\"text/html\"\n    * * * * * root coloredlogs --to-html your-command\n\nThe ``coloredlogs`` program is installed when you install the `coloredlogs`\nPython package. When you execute ``coloredlogs --to-html your-command`` it runs\n``your-command`` under the external program ``script`` (you need to have this\ninstalled). This makes ``your-command`` think that it's attached to an\ninteractive terminal which means it will output ANSI escape sequences which\nwill then be converted to HTML by the ``coloredlogs`` program. Yes, this is a\nbit convoluted, but it works great :-)\n\nModifying your Python code\n~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nThe ColoredCronMailer_ class provides a context manager that automatically\nenables HTML output when the ``$CONTENT_TYPE`` variable has been correctly set\nin the crontab.\n\nThis requires my capturer_ package which you can install using ``pip install\n'coloredlogs[cron]'``. The ``[cron]`` extra will pull in capturer_ 2.4 or newer\nwhich is required to capture the output while silencing it - otherwise you'd\nget duplicate output in the emails sent by ``cron``.\n\nThe context manager can also be used to retroactively silence output that has\nalready been produced, this can be useful to avoid spammy cron jobs that have\nnothing useful to do but still email their output to the system administrator\nevery few minutes :-).\n\nContact\n-------\n\nThe latest version of `coloredlogs` is available on PyPI_ and GitHub_. The\n`online documentation`_ is available on Read The Docs and includes a\nchangelog_. For bug reports please create an issue on GitHub_. If you have\nquestions, suggestions, etc. feel free to send me an e-mail at\n`peter@peterodding.com`_.\n\nLicense\n-------\n\nThis software is licensed under the `MIT license`_.\n\n© 2020 Peter Odding.\n\n\n.. External references:\n.. _#16: https://github.com/xolox/python-coloredlogs/issues/16\n.. _#45: https://github.com/xolox/python-coloredlogs/issues/45\n.. _ANSI escape sequences: https://en.wikipedia.org/wiki/ANSI_escape_code#Colors\n.. _capturer: https://pypi.org/project/capturer\n.. _changelog: https://coloredlogs.readthedocs.org/en/latest/changelog.html\n.. _colorama: https://pypi.org/project/colorama\n.. _ColoredCronMailer: https://coloredlogs.readthedocs.io/en/latest/api.html#coloredlogs.converter.ColoredCronMailer\n.. _ColoredFormatter: https://coloredlogs.readthedocs.io/en/latest/api.html#coloredlogs.ColoredFormatter\n.. _coloredlogs.install(): https://coloredlogs.readthedocs.io/en/latest/api.html#coloredlogs.install\n.. _cron: https://en.wikipedia.org/wiki/Cron\n.. _GitHub: https://github.com/xolox/python-coloredlogs\n.. _logging.basicConfig(): https://docs.python.org/2/library/logging.html#logging.basicConfig\n.. _logging.Filter: https://docs.python.org/3/library/logging.html#filter-objects\n.. _logging.Formatter: https://docs.python.org/2/library/logging.html#logging.Formatter\n.. _logging: https://docs.python.org/2/library/logging.html\n.. _MIT license: https://en.wikipedia.org/wiki/MIT_License\n.. _online documentation: https://coloredlogs.readthedocs.io/\n.. _per user site-packages directory: https://www.python.org/dev/peps/pep-0370/\n.. _peter@peterodding.com: peter@peterodding.com\n.. _PyPI: https://pypi.org/project/coloredlogs\n.. _release 3.0: https://coloredlogs.readthedocs.io/en/latest/changelog.html#release-3-0-2015-10-23\n.. _release 7.1: https://coloredlogs.readthedocs.io/en/latest/changelog.html#release-7-1-2017-07-15\n.. _release 9.3: https://coloredlogs.readthedocs.io/en/latest/changelog.html#release-9-3-2018-04-29\n.. _to include 'msecs': https://stackoverflow.com/questions/6290739/python-logging-use-milliseconds-in-time-format\n.. _verboselogs: https://pypi.org/project/verboselogs\n.. _virtual environments: http://docs.python-guide.org/en/latest/dev/virtualenvs/\n","funding_links":[],"categories":["Software Engineering","Resources"],"sub_categories":["Curated Python packages"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxolox%2Fpython-coloredlogs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxolox%2Fpython-coloredlogs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxolox%2Fpython-coloredlogs/lists"}