{ "info": { "author": "Derrick Gilland", "author_email": "dgilland@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "Intended Audience :: System Administrators", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.2", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: System :: Logging", "Topic :: System :: Systems Administration" ], "description": "*********\r\nlogconfig\r\n*********\r\n\r\n|version| |travis| |coveralls| |license|\r\n\r\nSimple helper moudle for configuring Python logging.\r\n\r\n\r\nRequirements\r\n============\r\n\r\n\r\nCompatibility\r\n-------------\r\n\r\n- Python 2.6\r\n- Python 2.7\r\n- Python 3.2\r\n- Python 3.3\r\n- Python 3.4\r\n\r\n\r\nDependencies\r\n------------\r\n\r\n- PyYAML\r\n- logutils (if using Python 2)\r\n\r\n\r\nInstallation\r\n============\r\n\r\n\r\n::\r\n\r\n pip install logconfig\r\n\r\n\r\nOverview\r\n========\r\n\r\nThis simple library exposes several helper methods for configuring the standard library's ``logging`` module. There's nothing fancy about it. Under the hood ``logconfig`` uses ``logging.config`` to load various configuartion formats.\r\n\r\nIn addition to configuration loading, ``logconfig`` provides helpers for easily converting a configured logger's handlers utilize a queue.\r\n\r\n\r\nSupported Configuration Formats\r\n-------------------------------\r\n\r\n- JSON\r\n- YAML\r\n- ConfigParser\r\n- Python Dict\r\n\r\n\r\nQuickstart\r\n==========\r\n\r\nConfiguration Loading\r\n---------------------\r\n\r\n.. code-block:: python\r\n\r\n import logconfig\r\n import logging\r\n\r\n # Load config from JSON file\r\n logconfig.from_json('path/to/file.json')\r\n\r\n # Load config from YAML file\r\n logconfig.from_yaml('path/to/file.yml')\r\n\r\n # Load config from ConfigParser file\r\n logconfig.from_yaml('path/to/file.cfg')\r\n\r\n # Load config from dict\r\n logconfig.from_dict(config_dict)\r\n\r\n log = logging.getLogger()\r\n log.debug('Configuration loaded using logconfig')\r\n\r\n\r\nQueue Utilization\r\n-----------------\r\n\r\n.. code-block:: python\r\n\r\n import logconfig\r\n import logging\r\n\r\n logconfig.from_dict({\r\n 'version': 1,\r\n 'disable_existing_loggers': False,\r\n 'handlers': {\r\n 'console': {\r\n 'class': 'logging.StreamHandler',\r\n 'level': 'DEBUG'\r\n }\r\n },\r\n 'loggers': {\r\n 'mylogger': {\r\n 'handlers': ['console']\r\n }\r\n }\r\n })\r\n\r\n # Convert logger's handlers to utilize a queue\r\n queue = logconfig.Queue(-1)\r\n listener = logconfig.QueueListener(queue)\r\n handler = logconfig.QueueHandler(queue)\r\n\r\n mylogger = logging.getLogger('mylogger')\r\n\r\n # You can also pass in the logger name instead of the actual logger.\r\n # logconfig.queuify_logger('mylogger', handler, listener)\r\n logconfig.queuify_logger(mylogger, handler, listener)\r\n\r\n assert isinstance(mylogger.handlers[0], logconfig.QueueHandler)\r\n\r\n # Start the listener.\r\n listener.start()\r\n\r\n # When finished, stop the listener.\r\n # This is optional, but not doing so may prevent some logs from being processed.\r\n listener.stop()\r\n\r\n\r\nUsage\r\n=====\r\n\r\nUse ``logconfig`` to easily load ``logging`` configurations. For more details on configuring ``logging``, visit https://docs.python.org/library/logging.config.html.\r\n\r\n\r\n.. code-block:: python\r\n\r\n import logconfig\r\n\r\n\r\nConfiguration from JSON\r\n-----------------------\r\n\r\nConfigure logging using JSON file.\r\n\r\n\r\n.. code-block:: python\r\n\r\n logconfig.from_json(filename)\r\n\r\n\r\nExample JSON file:\r\n\r\n\r\n.. code-block:: javascript\r\n\r\n {\r\n \"version\": 1,\r\n \"disable_existing_loggers\": false,\r\n \"formatters\": {\r\n \"simple\": {\r\n \"format\": \"%(asctime)s. - %(name)s - %(levelname)s - %(message)s\"\r\n }\r\n },\r\n \"handlers\": {\r\n \"console\": {\r\n \"class\": \"logging.StreamHandler\",\r\n \"level\": \"DEBUG\",\r\n \"formatter\": \"simple\",\r\n \"stream\": \"ext://sys.stdout\"\r\n }\r\n },\r\n \"root\": {\r\n \"level\": \"DEBUG\",\r\n \"handlers\": [\"console\"]\r\n }\r\n }\r\n\r\n\r\nConfiguration from YAML\r\n-----------------------\r\n\r\nConfigure logging using YAML file.\r\n\r\n\r\n.. code-block:: python\r\n\r\n logconfig.from_yaml(filename)\r\n\r\n\r\nExample YAML file:\r\n\r\n\r\n.. code-block:: yaml\r\n\r\n version: 1\r\n disable_existing_loggers: False\r\n formatters:\r\n simple:\r\n format: \"%(asctime)s. - %(name)s - %(levelname)s - %(message)s\"\r\n handlers:\r\n console:\r\n class: logging.StreamHandler\r\n level: DEBUG\r\n formatter: simple\r\n stream: ext://sys.stdout\r\n root:\r\n level: DEBUG\r\n handlers: [console]\r\n\r\n\r\nConfiguration from ConfigParser File\r\n------------------------------------\r\n\r\nConfigure logging using ConfigParser compatible file.\r\n\r\n\r\n.. code-block:: python\r\n\r\n logconfig.from_file(filename)\r\n\r\n\r\nExample CFG file:\r\n\r\n\r\n.. code-block:: ini\r\n\r\n [loggers]\r\n keys=root\r\n\r\n [handlers]\r\n keys=console\r\n\r\n [formatters]\r\n keys=simple\r\n\r\n [logger_root]\r\n level=DEBUG\r\n handlers=console\r\n\r\n [handler_console]\r\n class=StreamHandler\r\n level=DEBUG\r\n formatter=simple\r\n args=(sys.stdout,)\r\n\r\n [formatter_simple]\r\n format=%(asctime)s - %(name)s - %(levelname)s - %(message)s\r\n\r\n\r\nConfiguration from Dict\r\n-----------------------\r\n\r\nConfigure logging using Python dictionary.\r\n\r\n\r\n.. code-block:: python\r\n\r\n logconfig.from_dict(dct)\r\n\r\n\r\nExample dict:\r\n\r\n\r\n.. code-block:: python\r\n\r\n {\r\n 'version': 1,\r\n 'disable_existing_loggers': False,\r\n 'formatters': {\r\n 'simple': {\r\n 'format': '%(asctime)s. - %(name)s - %(levelname)s - %(message)s'\r\n }\r\n },\r\n 'handlers': {\r\n 'console': {\r\n 'formatter': 'simple',\r\n 'class': 'logging.StreamHandler',\r\n 'level': 'DEBUG',\r\n 'stream': 'ext://sys.stdout'\r\n }\r\n },\r\n 'root': {\r\n 'handlers': ['console'],\r\n 'level': 'DEBUG'\r\n }\r\n }\r\n\r\n\r\nConfiguration from Autodetection\r\n--------------------------------\r\n\r\nIf, for whatever reason, you do not know what the source of the configuration will be (or if you're just feeling lucky), then you can try to coerce logging configuration using one of the autodetection methods:\r\n\r\n\r\n.. code-block:: python\r\n\r\n logconfig.from_filename(filename)\r\n logconfig.from_autodetect(filename_or_dict)\r\n\r\n try:\r\n logconfig.from_filename(filename)\r\n logconfig.from_autodetect(filename_or_dict)\r\n except logconfig.LogConfigException as ex:\r\n # Unrecognized configuration argument.\r\n pass\r\n\r\n\r\nThese methods will try to dispatch the function argument to the proper configuration loader or fail trying.\r\n\r\n\r\nConfiguration from Environment Variable\r\n---------------------------------------\r\n\r\nConfigure logging using filename provided via environment variable.\r\n\r\n\r\n.. code-block:: python\r\n\r\n logconfig.from_env(variable_name)\r\n\r\n\r\n**NOTE:** Environment variable value will be passed to ``from_filename()``.\r\n\r\n\r\n.. |version| image:: https://img.shields.io/pypi/v/logconfig.svg?style=flat\r\n :target: https://pypi.python.org/pypi/logconfig/\r\n\r\n.. |travis| image:: https://img.shields.io/travis/dgilland/logconfig/master.svg?style=flat\r\n :target: https://travis-ci.org/dgilland/logconfig\r\n\r\n.. |coveralls| image:: https://img.shields.io/coveralls/dgilland/logconfig/master.svg?style=flat\r\n :target: https://coveralls.io/r/dgilland/logconfig\r\n\r\n.. |license| image:: https://img.shields.io/pypi/l/logconfig.svg?style=flat\r\n :target: https://pypi.python.org/pypi/logconfig/", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/dgilland/logconfig", "keywords": "logging config configuration", "license": "MIT License", "maintainer": "", "maintainer_email": "", "name": "logconfig", "package_url": "https://pypi.org/project/logconfig/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/logconfig/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/dgilland/logconfig" }, "release_url": "https://pypi.org/project/logconfig/0.4.0/", "requires_dist": null, "requires_python": null, "summary": "Simple helper moudle for configuring Python logging", "version": "0.4.0" }, "last_serial": 1621351, "releases": { "0.4.0": [ { "comment_text": "", "digests": { "md5": "31dde75abcfd7a8c0634c03c01c5f727", "sha256": "19500458c84858ad5f6efe90c9cc6d1bbd06bba998ecbc8ddb621ae37d2743fd" }, "downloads": -1, "filename": "logconfig-0.4.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "31dde75abcfd7a8c0634c03c01c5f727", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 9903, "upload_time": "2014-12-24T07:01:14", "url": "https://files.pythonhosted.org/packages/0f/58/7593f76aa0a393c23492f28860c9afe9adb8c640aeb507daad4fe46685a7/logconfig-0.4.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8a1f736b4f74c5cc696f0ef58ed4dc0a", "sha256": "04280128fa1762604281dfafc2dbf527975a5e532c9dc4f76c68cd080274a663" }, "downloads": -1, "filename": "logconfig-0.4.0.tar.gz", "has_sig": false, "md5_digest": "8a1f736b4f74c5cc696f0ef58ed4dc0a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7838, "upload_time": "2014-12-24T07:01:18", "url": "https://files.pythonhosted.org/packages/4c/ee/615dc71711e101ffa22746437e86a10eee5fd8dd78dfb559ea39133ff213/logconfig-0.4.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "31dde75abcfd7a8c0634c03c01c5f727", "sha256": "19500458c84858ad5f6efe90c9cc6d1bbd06bba998ecbc8ddb621ae37d2743fd" }, "downloads": -1, "filename": "logconfig-0.4.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "31dde75abcfd7a8c0634c03c01c5f727", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 9903, "upload_time": "2014-12-24T07:01:14", "url": "https://files.pythonhosted.org/packages/0f/58/7593f76aa0a393c23492f28860c9afe9adb8c640aeb507daad4fe46685a7/logconfig-0.4.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8a1f736b4f74c5cc696f0ef58ed4dc0a", "sha256": "04280128fa1762604281dfafc2dbf527975a5e532c9dc4f76c68cd080274a663" }, "downloads": -1, "filename": "logconfig-0.4.0.tar.gz", "has_sig": false, "md5_digest": "8a1f736b4f74c5cc696f0ef58ed4dc0a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7838, "upload_time": "2014-12-24T07:01:18", "url": "https://files.pythonhosted.org/packages/4c/ee/615dc71711e101ffa22746437e86a10eee5fd8dd78dfb559ea39133ff213/logconfig-0.4.0.tar.gz" } ] }