METADATA 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. Metadata-Version: 2.1
  2. Name: colorlog
  3. Version: 6.8.2
  4. Summary: Add colours to the output of Python's logging module.
  5. Home-page: https://github.com/borntyping/python-colorlog
  6. Author: Sam Clements
  7. Author-email: sam@borntyping.co.uk
  8. License: MIT License
  9. Classifier: Development Status :: 5 - Production/Stable
  10. Classifier: Environment :: Console
  11. Classifier: Intended Audience :: Developers
  12. Classifier: License :: OSI Approved :: MIT License
  13. Classifier: Operating System :: OS Independent
  14. Classifier: Programming Language :: Python
  15. Classifier: Programming Language :: Python :: 3
  16. Classifier: Programming Language :: Python :: 3.6
  17. Classifier: Programming Language :: Python :: 3.7
  18. Classifier: Programming Language :: Python :: 3.8
  19. Classifier: Programming Language :: Python :: 3.9
  20. Classifier: Programming Language :: Python :: 3.10
  21. Classifier: Topic :: Terminals
  22. Classifier: Topic :: Utilities
  23. Requires-Python: >=3.6
  24. Description-Content-Type: text/markdown
  25. License-File: LICENSE
  26. Requires-Dist: colorama ; sys_platform=="win32"
  27. Provides-Extra: development
  28. Requires-Dist: black ; extra == 'development'
  29. Requires-Dist: flake8 ; extra == 'development'
  30. Requires-Dist: mypy ; extra == 'development'
  31. Requires-Dist: pytest ; extra == 'development'
  32. Requires-Dist: types-colorama ; extra == 'development'
  33. # Log formatting with colors!
  34. [![](https://img.shields.io/pypi/v/colorlog.svg)](https://pypi.org/project/colorlog/)
  35. [![](https://img.shields.io/pypi/l/colorlog.svg)](https://pypi.org/project/colorlog/)
  36. Add colours to the output of Python's `logging` module.
  37. * [Source on GitHub](https://github.com/borntyping/python-colorlog)
  38. * [Packages on PyPI](https://pypi.org/pypi/colorlog/)
  39. ## Status
  40. colorlog currently requires Python 3.6 or higher. Older versions (below 5.x.x)
  41. support Python 2.6 and above.
  42. * colorlog 6.x requires Python 3.6 or higher.
  43. * colorlog 5.x is an interim version that will warn Python 2 users to downgrade.
  44. * colorlog 4.x is the final version supporting Python 2.
  45. [colorama] is included as a required dependency and initialised when using
  46. colorlog on Windows.
  47. This library is over a decade old and supported a wide set of Python versions
  48. for most of its life, which has made it a difficult library to add new features
  49. to. colorlog 6 may break backwards compatibility so that newer features
  50. can be added more easily, but may still not accept all changes or feature
  51. requests. colorlog 4 might accept essential bugfixes but should not be
  52. considered actively maintained and will not accept any major changes or new
  53. features.
  54. ## Installation
  55. Install from PyPI with:
  56. ```bash
  57. pip install colorlog
  58. ```
  59. Several Linux distributions provide official packages ([Debian], [Arch], [Fedora],
  60. [Gentoo], [OpenSuse] and [Ubuntu]), and others have user provided packages
  61. ([BSD ports], [Conda]).
  62. ## Usage
  63. ```python
  64. import colorlog
  65. handler = colorlog.StreamHandler()
  66. handler.setFormatter(colorlog.ColoredFormatter(
  67. '%(log_color)s%(levelname)s:%(name)s:%(message)s'))
  68. logger = colorlog.getLogger('example')
  69. logger.addHandler(handler)
  70. ```
  71. The `ColoredFormatter` class takes several arguments:
  72. - `format`: The format string used to output the message (required).
  73. - `datefmt`: An optional date format passed to the base class. See [`logging.Formatter`][Formatter].
  74. - `reset`: Implicitly adds a color reset code to the message output, unless the output already ends with one. Defaults to `True`.
  75. - `log_colors`: A mapping of record level names to color names. The defaults can be found in `colorlog.default_log_colors`, or the below example.
  76. - `secondary_log_colors`: A mapping of names to `log_colors` style mappings, defining additional colors that can be used in format strings. See below for an example.
  77. - `style`: Available on Python 3.2 and above. See [`logging.Formatter`][Formatter].
  78. Color escape codes can be selected based on the log records level, by adding
  79. parameters to the format string:
  80. - `log_color`: Return the color associated with the records level.
  81. - `<name>_log_color`: Return another color based on the records level if the formatter has secondary colors configured (see `secondary_log_colors` below).
  82. Multiple escape codes can be used at once by joining them with commas when
  83. configuring the color for a log level (but can't be used directly in the format
  84. string). For example, `black,bg_white` would use the escape codes for black
  85. text on a white background.
  86. The following escape codes are made available for use in the format string:
  87. - `{color}`, `fg_{color}`, `bg_{color}`: Foreground and background colors.
  88. - `bold`, `bold_{color}`, `fg_bold_{color}`, `bg_bold_{color}`: Bold/bright colors.
  89. - `thin`, `thin_{color}`, `fg_thin_{color}`: Thin colors (terminal dependent).
  90. - `reset`: Clear all formatting (both foreground and background colors).
  91. The available color names are:
  92. - `black`
  93. - `red`
  94. - `green`
  95. - `yellow`
  96. - `blue`,
  97. - `purple`
  98. - `cyan`
  99. - `white`
  100. You can also use "bright" colors. These aren't standard ANSI codes, and
  101. support for these varies wildly across different terminals.
  102. - `light_black`
  103. - `light_red`
  104. - `light_green`
  105. - `light_yellow`
  106. - `light_blue`
  107. - `light_purple`
  108. - `light_cyan`
  109. - `light_white`
  110. ## Examples
  111. ![Example output](docs/example.png)
  112. The following code creates a `ColoredFormatter` for use in a logging setup,
  113. using the default values for each argument.
  114. ```python
  115. from colorlog import ColoredFormatter
  116. formatter = ColoredFormatter(
  117. "%(log_color)s%(levelname)-8s%(reset)s %(blue)s%(message)s",
  118. datefmt=None,
  119. reset=True,
  120. log_colors={
  121. 'DEBUG': 'cyan',
  122. 'INFO': 'green',
  123. 'WARNING': 'yellow',
  124. 'ERROR': 'red',
  125. 'CRITICAL': 'red,bg_white',
  126. },
  127. secondary_log_colors={},
  128. style='%'
  129. )
  130. ```
  131. ### Using `secondary_log_colors`
  132. Secondary log colors are a way to have more than one color that is selected
  133. based on the log level. Each key in `secondary_log_colors` adds an attribute
  134. that can be used in format strings (`message` becomes `message_log_color`), and
  135. has a corresponding value that is identical in format to the `log_colors`
  136. argument.
  137. The following example highlights the level name using the default log colors,
  138. and highlights the message in red for `error` and `critical` level log messages.
  139. ```python
  140. from colorlog import ColoredFormatter
  141. formatter = ColoredFormatter(
  142. "%(log_color)s%(levelname)-8s%(reset)s %(message_log_color)s%(message)s",
  143. secondary_log_colors={
  144. 'message': {
  145. 'ERROR': 'red',
  146. 'CRITICAL': 'red'
  147. }
  148. }
  149. )
  150. ```
  151. ### With [`dictConfig`][dictConfig]
  152. ```python
  153. logging.config.dictConfig({
  154. 'formatters': {
  155. 'colored': {
  156. '()': 'colorlog.ColoredFormatter',
  157. 'format': "%(log_color)s%(levelname)-8s%(reset)s %(blue)s%(message)s"
  158. }
  159. }
  160. })
  161. ```
  162. A full example dictionary can be found in `tests/test_colorlog.py`.
  163. ### With [`fileConfig`][fileConfig]
  164. ```ini
  165. ...
  166. [formatters]
  167. keys=color
  168. [formatter_color]
  169. class=colorlog.ColoredFormatter
  170. format=%(log_color)s%(levelname)-8s%(reset)s %(bg_blue)s[%(name)s]%(reset)s %(message)s from fileConfig
  171. datefmt=%m-%d %H:%M:%S
  172. ```
  173. An instance of ColoredFormatter created with those arguments will then be used
  174. by any handlers that are configured to use the `color` formatter.
  175. A full example configuration can be found in `tests/test_config.ini`.
  176. ### With custom log levels
  177. ColoredFormatter will work with custom log levels added with
  178. [`logging.addLevelName`][addLevelName]:
  179. ```python
  180. import logging, colorlog
  181. TRACE = 5
  182. logging.addLevelName(TRACE, 'TRACE')
  183. formatter = colorlog.ColoredFormatter(log_colors={'TRACE': 'yellow'})
  184. handler = logging.StreamHandler()
  185. handler.setFormatter(formatter)
  186. logger = logging.getLogger('example')
  187. logger.addHandler(handler)
  188. logger.setLevel('TRACE')
  189. logger.log(TRACE, 'a message using a custom level')
  190. ```
  191. ## Tests
  192. Tests similar to the above examples are found in `tests/test_colorlog.py`.
  193. ## Status
  194. colorlog is in maintenance mode. I try and ensure bugfixes are published,
  195. but compatibility with Python 2.6+ and Python 3+ makes this a difficult
  196. codebase to add features to. Any changes that might break backwards
  197. compatibility for existing users will not be considered.
  198. ## Alternatives
  199. There are some more modern libraries for improving Python logging you may
  200. find useful.
  201. - [structlog]
  202. - [jsonlog]
  203. ## Projects using colorlog
  204. GitHub provides [a list of projects that depend on colorlog][dependents].
  205. Some early adopters included [Errbot], [Pythran], and [zenlog].
  206. ## Licence
  207. Copyright (c) 2012-2021 Sam Clements <sam@borntyping.co.uk>
  208. Permission is hereby granted, free of charge, to any person obtaining a copy of
  209. this software and associated documentation files (the "Software"), to deal in
  210. the Software without restriction, including without limitation the rights to
  211. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  212. the Software, and to permit persons to whom the Software is furnished to do so,
  213. subject to the following conditions:
  214. The above copyright notice and this permission notice shall be included in all
  215. copies or substantial portions of the Software.
  216. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  217. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  218. FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  219. COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  220. IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  221. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  222. [dictConfig]: http://docs.python.org/3/library/logging.config.html#logging.config.dictConfig
  223. [fileConfig]: http://docs.python.org/3/library/logging.config.html#logging.config.fileConfig
  224. [addLevelName]: https://docs.python.org/3/library/logging.html#logging.addLevelName
  225. [Formatter]: http://docs.python.org/3/library/logging.html#logging.Formatter
  226. [tox]: http://tox.readthedocs.org/
  227. [Arch]: https://archlinux.org/packages/extra/any/python-colorlog/
  228. [BSD ports]: https://www.freshports.org/devel/py-colorlog/
  229. [colorama]: https://pypi.python.org/pypi/colorama
  230. [Conda]: https://anaconda.org/conda-forge/colorlog
  231. [Debian]: [https://packages.debian.org/buster/python3-colorlog](https://packages.debian.org/buster/python3-colorlog)
  232. [Errbot]: http://errbot.io/
  233. [Fedora]: https://src.fedoraproject.org/rpms/python-colorlog
  234. [Gentoo]: https://packages.gentoo.org/packages/dev-python/colorlog
  235. [OpenSuse]: http://rpm.pbone.net/index.php3?stat=3&search=python-colorlog&srodzaj=3
  236. [Pythran]: https://github.com/serge-sans-paille/pythran
  237. [Ubuntu]: https://launchpad.net/python-colorlog
  238. [zenlog]: https://github.com/ManufacturaInd/python-zenlog
  239. [structlog]: https://www.structlog.org/en/stable/
  240. [jsonlog]: https://github.com/borntyping/jsonlog
  241. [dependents]: https://github.com/borntyping/python-colorlog/network/dependents?package_id=UGFja2FnZS01MDk3NDcyMQ%3D%3D