m2m模型翻译
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

291 lines
12 KiB

6 months ago
  1. Metadata-Version: 2.1
  2. Name: coloredlogs
  3. Version: 15.0.1
  4. Summary: Colored terminal output for Python's logging module
  5. Home-page: https://coloredlogs.readthedocs.io
  6. Author: Peter Odding
  7. Author-email: peter@peterodding.com
  8. License: MIT
  9. Platform: UNKNOWN
  10. Classifier: Development Status :: 5 - Production/Stable
  11. Classifier: Environment :: Console
  12. Classifier: Intended Audience :: Developers
  13. Classifier: Intended Audience :: Information Technology
  14. Classifier: Intended Audience :: System Administrators
  15. Classifier: License :: OSI Approved :: MIT License
  16. Classifier: Operating System :: MacOS
  17. Classifier: Operating System :: Microsoft :: Windows
  18. Classifier: Operating System :: POSIX
  19. Classifier: Operating System :: Unix
  20. Classifier: Programming Language :: Python
  21. Classifier: Programming Language :: Python :: 2
  22. Classifier: Programming Language :: Python :: 2.7
  23. Classifier: Programming Language :: Python :: 3
  24. Classifier: Programming Language :: Python :: 3.5
  25. Classifier: Programming Language :: Python :: 3.6
  26. Classifier: Programming Language :: Python :: 3.7
  27. Classifier: Programming Language :: Python :: 3.8
  28. Classifier: Programming Language :: Python :: Implementation :: CPython
  29. Classifier: Programming Language :: Python :: Implementation :: PyPy
  30. Classifier: Topic :: Communications
  31. Classifier: Topic :: Scientific/Engineering :: Human Machine Interfaces
  32. Classifier: Topic :: Software Development
  33. Classifier: Topic :: Software Development :: Libraries :: Python Modules
  34. Classifier: Topic :: Software Development :: User Interfaces
  35. Classifier: Topic :: System
  36. Classifier: Topic :: System :: Shells
  37. Classifier: Topic :: System :: System Shells
  38. Classifier: Topic :: System :: Console Fonts
  39. Classifier: Topic :: System :: Logging
  40. Classifier: Topic :: System :: Systems Administration
  41. Classifier: Topic :: Terminals
  42. Classifier: Topic :: Utilities
  43. Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*
  44. Requires-Dist: humanfriendly (>=9.1)
  45. Provides-Extra: cron
  46. Requires-Dist: capturer (>=2.4) ; extra == 'cron'
  47. coloredlogs: Colored terminal output for Python's logging module
  48. ================================================================
  49. .. image:: https://travis-ci.org/xolox/python-coloredlogs.svg?branch=master
  50. :target: https://travis-ci.org/xolox/python-coloredlogs
  51. .. image:: https://coveralls.io/repos/github/xolox/python-coloredlogs/badge.svg?branch=master
  52. :target: https://coveralls.io/github/xolox/python-coloredlogs?branch=master
  53. The `coloredlogs` package enables colored terminal output for Python's logging_
  54. module. The ColoredFormatter_ class inherits from `logging.Formatter`_ and uses
  55. `ANSI escape sequences`_ to render your logging messages in color. It uses only
  56. standard colors so it should work on any UNIX terminal. It's currently tested
  57. on Python 2.7, 3.5+ and PyPy (2 and 3). On Windows `coloredlogs` automatically
  58. tries to enable native ANSI support (on up-to-date Windows 10 installations)
  59. and falls back on using colorama_ (if installed). Here is a screen shot of the
  60. demo that is printed when the command ``coloredlogs --demo`` is executed:
  61. .. image:: https://coloredlogs.readthedocs.io/en/latest/_images/defaults.png
  62. Note that the screenshot above includes custom logging levels defined by my
  63. verboselogs_ package: if you install both `coloredlogs` and `verboselogs` it
  64. will Just Work (`verboselogs` is of course not required to use
  65. `coloredlogs`).
  66. .. contents::
  67. :local:
  68. Installation
  69. ------------
  70. The `coloredlogs` package is available on PyPI_ which means installation should
  71. be as simple as:
  72. .. code-block:: console
  73. $ pip install coloredlogs
  74. There's actually a multitude of ways to install Python packages (e.g. the `per
  75. user site-packages directory`_, `virtual environments`_ or just installing
  76. system wide) and I have no intention of getting into that discussion here, so
  77. if this intimidates you then read up on your options before returning to these
  78. instructions 😉.
  79. Optional dependencies
  80. ~~~~~~~~~~~~~~~~~~~~~
  81. Native ANSI support on Windows requires an up-to-date Windows 10 installation.
  82. If this is not working for you then consider installing the colorama_ package:
  83. .. code-block:: console
  84. $ pip install colorama
  85. Once colorama_ is installed it will be used automatically.
  86. Usage
  87. -----
  88. Here's an example of how easy it is to get started:
  89. .. code-block:: python
  90. import coloredlogs, logging
  91. # Create a logger object.
  92. logger = logging.getLogger(__name__)
  93. # By default the install() function installs a handler on the root logger,
  94. # this means that log messages from your code and log messages from the
  95. # libraries that you use will all show up on the terminal.
  96. coloredlogs.install(level='DEBUG')
  97. # If you don't want to see log messages from libraries, you can pass a
  98. # specific logger object to the install() function. In this case only log
  99. # messages originating from that logger will show up on the terminal.
  100. coloredlogs.install(level='DEBUG', logger=logger)
  101. # Some examples.
  102. logger.debug("this is a debugging message")
  103. logger.info("this is an informational message")
  104. logger.warning("this is a warning message")
  105. logger.error("this is an error message")
  106. logger.critical("this is a critical message")
  107. Format of log messages
  108. ----------------------
  109. The ColoredFormatter_ class supports user defined log formats so you can use
  110. any log format you like. The default log format is as follows::
  111. %(asctime)s %(hostname)s %(name)s[%(process)d] %(levelname)s %(message)s
  112. This log format results in the following output::
  113. 2015-10-23 03:32:22 peter-macbook coloredlogs.demo[30462] DEBUG message with level 'debug'
  114. 2015-10-23 03:32:23 peter-macbook coloredlogs.demo[30462] VERBOSE message with level 'verbose'
  115. 2015-10-23 03:32:24 peter-macbook coloredlogs.demo[30462] INFO message with level 'info'
  116. ...
  117. You can customize the log format and styling using environment variables as
  118. well as programmatically, please refer to the `online documentation`_ for
  119. details.
  120. Enabling millisecond precision
  121. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  122. If you're switching from `logging.basicConfig()`_ to `coloredlogs.install()`_
  123. you may notice that timestamps no longer include milliseconds. This is because
  124. coloredlogs doesn't output milliseconds in timestamps unless you explicitly
  125. tell it to. There are three ways to do that:
  126. 1. The easy way is to pass the `milliseconds` argument to `coloredlogs.install()`_::
  127. coloredlogs.install(milliseconds=True)
  128. This became supported in `release 7.1`_ (due to `#16`_).
  129. 2. Alternatively you can change the log format `to include 'msecs'`_::
  130. %(asctime)s,%(msecs)03d %(hostname)s %(name)s[%(process)d] %(levelname)s %(message)s
  131. Here's what the call to `coloredlogs.install()`_ would then look like::
  132. coloredlogs.install(fmt='%(asctime)s,%(msecs)03d %(hostname)s %(name)s[%(process)d] %(levelname)s %(message)s')
  133. Customizing the log format also enables you to change the delimiter that
  134. separates seconds from milliseconds (the comma above). This became possible
  135. in `release 3.0`_ which added support for user defined log formats.
  136. 3. If the use of ``%(msecs)d`` isn't flexible enough you can instead add ``%f``
  137. to the date/time format, it will be replaced by the value of ``%(msecs)03d``.
  138. Support for the ``%f`` directive was added to `release 9.3`_ (due to `#45`_).
  139. Custom logging fields
  140. ~~~~~~~~~~~~~~~~~~~~~
  141. The following custom log format fields are supported:
  142. - ``%(hostname)s`` provides the hostname of the local system.
  143. - ``%(programname)s`` provides the name of the currently running program.
  144. - ``%(username)s`` provides the username of the currently logged in user.
  145. When `coloredlogs.install()`_ detects that any of these fields are used in the
  146. format string the applicable logging.Filter_ subclasses are automatically
  147. registered to populate the relevant log record fields.
  148. Changing text styles and colors
  149. -------------------------------
  150. The online documentation contains `an example of customizing the text styles and
  151. colors <https://coloredlogs.readthedocs.io/en/latest/api.html#changing-the-colors-styles>`_.
  152. Colored output from cron
  153. ------------------------
  154. When `coloredlogs` is used in a cron_ job, the output that's e-mailed to you by
  155. cron won't contain any ANSI escape sequences because `coloredlogs` realizes
  156. that it's not attached to an interactive terminal. If you'd like to have colors
  157. e-mailed to you by cron there are two ways to make it happen:
  158. .. contents::
  159. :local:
  160. Modifying your crontab
  161. ~~~~~~~~~~~~~~~~~~~~~~
  162. Here's an example of a minimal crontab::
  163. MAILTO="your-email-address@here"
  164. CONTENT_TYPE="text/html"
  165. * * * * * root coloredlogs --to-html your-command
  166. The ``coloredlogs`` program is installed when you install the `coloredlogs`
  167. Python package. When you execute ``coloredlogs --to-html your-command`` it runs
  168. ``your-command`` under the external program ``script`` (you need to have this
  169. installed). This makes ``your-command`` think that it's attached to an
  170. interactive terminal which means it will output ANSI escape sequences which
  171. will then be converted to HTML by the ``coloredlogs`` program. Yes, this is a
  172. bit convoluted, but it works great :-)
  173. Modifying your Python code
  174. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  175. The ColoredCronMailer_ class provides a context manager that automatically
  176. enables HTML output when the ``$CONTENT_TYPE`` variable has been correctly set
  177. in the crontab.
  178. This requires my capturer_ package which you can install using ``pip install
  179. 'coloredlogs[cron]'``. The ``[cron]`` extra will pull in capturer_ 2.4 or newer
  180. which is required to capture the output while silencing it - otherwise you'd
  181. get duplicate output in the emails sent by ``cron``.
  182. The context manager can also be used to retroactively silence output that has
  183. already been produced, this can be useful to avoid spammy cron jobs that have
  184. nothing useful to do but still email their output to the system administrator
  185. every few minutes :-).
  186. Contact
  187. -------
  188. The latest version of `coloredlogs` is available on PyPI_ and GitHub_. The
  189. `online documentation`_ is available on Read The Docs and includes a
  190. changelog_. For bug reports please create an issue on GitHub_. If you have
  191. questions, suggestions, etc. feel free to send me an e-mail at
  192. `peter@peterodding.com`_.
  193. License
  194. -------
  195. This software is licensed under the `MIT license`_.
  196. © 2020 Peter Odding.
  197. .. External references:
  198. .. _#16: https://github.com/xolox/python-coloredlogs/issues/16
  199. .. _#45: https://github.com/xolox/python-coloredlogs/issues/45
  200. .. _ANSI escape sequences: https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
  201. .. _capturer: https://pypi.org/project/capturer
  202. .. _changelog: https://coloredlogs.readthedocs.org/en/latest/changelog.html
  203. .. _colorama: https://pypi.org/project/colorama
  204. .. _ColoredCronMailer: https://coloredlogs.readthedocs.io/en/latest/api.html#coloredlogs.converter.ColoredCronMailer
  205. .. _ColoredFormatter: https://coloredlogs.readthedocs.io/en/latest/api.html#coloredlogs.ColoredFormatter
  206. .. _coloredlogs.install(): https://coloredlogs.readthedocs.io/en/latest/api.html#coloredlogs.install
  207. .. _cron: https://en.wikipedia.org/wiki/Cron
  208. .. _GitHub: https://github.com/xolox/python-coloredlogs
  209. .. _logging.basicConfig(): https://docs.python.org/2/library/logging.html#logging.basicConfig
  210. .. _logging.Filter: https://docs.python.org/3/library/logging.html#filter-objects
  211. .. _logging.Formatter: https://docs.python.org/2/library/logging.html#logging.Formatter
  212. .. _logging: https://docs.python.org/2/library/logging.html
  213. .. _MIT license: https://en.wikipedia.org/wiki/MIT_License
  214. .. _online documentation: https://coloredlogs.readthedocs.io/
  215. .. _per user site-packages directory: https://www.python.org/dev/peps/pep-0370/
  216. .. _peter@peterodding.com: peter@peterodding.com
  217. .. _PyPI: https://pypi.org/project/coloredlogs
  218. .. _release 3.0: https://coloredlogs.readthedocs.io/en/latest/changelog.html#release-3-0-2015-10-23
  219. .. _release 7.1: https://coloredlogs.readthedocs.io/en/latest/changelog.html#release-7-1-2017-07-15
  220. .. _release 9.3: https://coloredlogs.readthedocs.io/en/latest/changelog.html#release-9-3-2018-04-29
  221. .. _to include 'msecs': https://stackoverflow.com/questions/6290739/python-logging-use-milliseconds-in-time-format
  222. .. _verboselogs: https://pypi.org/project/verboselogs
  223. .. _virtual environments: http://docs.python-guide.org/en/latest/dev/virtualenvs/