{ "info": { "author": "gocept ", "author_email": "mail@gocept.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: Zope Public License", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy" ], "description": "==============\ngocept.logging\n==============\n\n.. contents::\n :depth: 2\n\nThis package provides infrastructure for semi-structured log messages.\n\nThis means appending easily parseable information after the free-text log\nmessage to facilitate analysis of the logs later on. The ``logging`` module of\nthe Python standard library already has support for this, via the ``extra``\nparameter. gocept.logging provides a ``Formatter`` that extracts these\n``extra`` values, formats them as ``key=value`` pairs and appends them to the\nmessage::\n\n >>> import gocept.logging\n >>> import logging\n >>> import sys\n\n >>> handler = logging.StreamHandler(sys.stdout)\n >>> handler.setFormatter(gocept.logging.SyslogKeyValueFormatter())\n >>> log = logging.getLogger('example')\n >>> log.addHandler(handler)\n >>> log.warning('Hello, world!', extra={'foo': 'bar'})\n Aug 24 12:10:08 localhost example: Hello, world! foo=bar\n\nThis package is tested to be compatible with Python version 2.7 and 3.3.\n\n\nAdvanced usage\n==============\n\nIf you have ``extra`` values that you always want to pass to your log messages\n(e.g things like the current user, session id, ...) you can wrap your logger\nwith an `LoggerAdapter`_ that prefills these values. gocept.logging provides\none that allows both stacking adapters and overriding the prefilled values::\n\n >>> from gocept.logging.adapter import StaticDefaults\n >>> import logging\n\n >>> log = logging.getLogger('advanced')\n >>> log = StaticDefaults(log, {'foo': 'bar', 'qux': 'baz'})\n >>> log = StaticDefaults(log, {'blam': 'splat'})\n >>> log.warning('Hello, world!', extra={'foo': 'override'})\n # yields {'foo': 'override', 'qux': 'baz', 'blam': 'splat'}\n\n.. _`LoggerAdapter`: http://docs.python.org/2/library/logging.html#loggeradapter-objects\n\n\nTesting support\n---------------\n\nTo help inspecting the ``extra`` values, gocept.logging comes with a\nspecialized handler for testing::\n\n >>> import gocept.logging\n >>> import logging\n\n >>> log = logging.getLogger('testing')\n >>> handler = gocept.logging.TestingHandler()\n >>> log.addHandler(handler)\n >>> log.warning('Hello, world!', extra={'foo': 'bar'})\n >>> handler.messages[0].extra['foo']\n 'bar'\n\nThe TestingHandler records each log message as a namedtuple of type\n``gocept.logging.testing.LogMessage`` so you an easily access all parts of the\nmessage.\n\n\nExample configuration\n=====================\n\nCreating semi-structured log messages is the first half of the issue, while\nanalysing them is the second half. We use `logstash`_ for that purpose.\n\nThe recommended setup is::\n\n application -> syslogd on localhost -> logstash on central host (via UDP syslog input)\n\nFor development you might want to leave out the middle man and configure the\napplication to send log messags via syslog protocol directly to logstash.\n\n\n.. _`logstash`: http://logstash.net/\n\n\nSetup with ini file\n-------------------\n\nIf you have a paste.ini for your application, you might use something like\nthis::\n\n [loggers]\n keys = root\n\n [handlers]\n keys = console, syslog\n\n [formatters]\n keys = generic, keyvalue\n\n [logger_root]\n level = INFO\n handlers = console, syslog\n\n [handler_console]\n class = StreamHandler\n args = (sys.stderr,)\n level = NOTSET\n formatter = generic\n\n [formatter_generic]\n format = %(asctime)s %(levelname)-5.5s %(name)s: %(message)s\n\n [handler_syslog]\n class = logging.handlers.SysLogHandler\n args = ()\n formatter = keyvalue\n\n [formatter_keyvalue]\n class = gocept.logging.SyslogKeyValueFormatter\n\n\nSetup with ZConfig\n------------------\n\nIf you have a Zope application, you might use something like this::\n\n \n \n formatter zope.exceptions.log.Formatter\n format %(asctime)s %(levelname)-5.5s %(name)s: %(message)s\n path STDOUT\n \n \n formatter gocept.logging.SyslogKeyValueFormatter\n \n \n\n\nsyslogd configuration\n---------------------\n\nrsyslog::\n\n $EscapeControlCharactersOnReceive off\n $MaxMessageSize 64k\n user.* @localhost:5140\n\nThe first two lines are to support tracebacks, which are multiline and might\ntake up some space. The last line tells rsyslogd to forward all messages of the\n``user`` facility (which is what stdlib ``logging`` uses by default) via syslog\nUDP protocol to localhost port 5140 (where logstash might be listening).\n\n\nlogstash configuration\n----------------------\n\n::\n\n input {\n tcp {\n host => \"localhost\"\n port => 5140\n type => syslog\n }\n udp {\n host => \"localhost\"\n port => 5140\n type => syslog\n }\n }\n\n filter {\n grok {\n type => \"syslog\"\n pattern => [ \"(?m)<%{POSINT:syslog_pri}>%{SYSLOGTIMESTAMP:syslog_timestamp} %{SYSLOGHOST:syslog_hostname} %{DATA:syslog_program}(?:\\[%{POSINT:syslog_pid}\\])?: %{GREEDYDATA:syslog_message}\" ]\n }\n syslog_pri {\n type => \"syslog\"\n }\n date {\n type => \"syslog\"\n match => [ \"syslog_timestamp\", \"MMM d HH:mm:ss\", \"MMM dd HH:mm:ss\" ]\n }\n mutate {\n type => \"syslog\"\n exclude_tags => \"_grokparsefailure\"\n replace => [ \"@source_host\", \"%{syslog_hostname}\" ]\n replace => [ \"@message\", \"%{syslog_program}: %{syslog_message}\" ]\n }\n mutate {\n type => \"syslog\"\n remove => [ \"syslog_hostname\", \"syslog_timestamp\" ]\n }\n kv {\n exclude_tags => \"_grokparsefailure\"\n type => \"syslog\"\n }\n }\n\n output {\n elasticsearch { embedded => true }\n }\n\n\nAdditional features\n===================\n\nArgumentParser\n--------------\n\nThe provided ``gocept.logging.ArgumentParser`` provides you with the ability to\nset a ``logging`` level in you runscripts.::\n\n from gocept.logging import ArgumentParser\n parser = ArgumentParser()\n # Optionally set a custom log format, defaults to ``logging.BASIC_FORMAT``\n parser.LOG_FORMAT = 'LOG:%(message)s'\n # add your arguments with parser.add_argument() here\n options = parser.parse_args()\n\nUse ``your_run_script --help`` to see a help message about the arguments you\ncan pass to set logging level.\n\n\nKnown bugs\n==========\n\nIf you log messages as unicode, e.g. ``log.info(u'foo')``, the SyslogHandler\nwill (incorrectly) prepend a byte-order mark, which confuses the logstash\nparser, resulting in \"_grokparsefailure\". This is a `known bug`_ in the Python\nstandard library that has been fixed in Python-2.7.4.\n\n.. _`known bug`: http://bugs.python.org/issue14452\n\n\n=========================\nDeveloping gocept.logging\n=========================\n\n:Author:\n `gocept `_ \n\n:PyPI page:\n http://pypi.python.org/pypi/gocept.logging/\n\n:Issues:\n `report by e-mail `_\n\n:Source code:\n https://bitbucket.org/gocept/gocept.logging/\n\n:Current change log:\n https://bitbucket.org/gocept/gocept.logging/raw/tip/CHANGES.txt\n\n\n=============================\nChange log for gocept.logging\n=============================\n\n0.8.1 (2017-01-09)\n==================\n\n- Fix `setup.py` to use relative paths.\n\n\n0.8 (2016-03-17)\n================\n\n- Declare compatibility with PyPy and PyPy3.\n\n\n0.7 (2015-09-29)\n================\n\n- Declare Python 3.5 compatibility.\n\n\n0.6 (2015-09-17)\n================\n\n- Declare Python 3.4 compatibility.\n\n- ``ArgumentParser.parse_args()`` now stores the computed log level on the\n ``log_level`` attribute of the return value.\n\n0.5 (2014-02-07)\n================\n\n- Allow to change log format for the ``ArgumentParser``\n\n\n0.4 (2013-09-24)\n================\n\n- Handle non-string log messages properly.\n\n\n0.3 (2013-09-04)\n================\n\n- Added sepcialized ``argparse.ArgumentParser`` which enables user to set the\n ``logging`` level by default..\n\n\n0.2 (2013-08-24)\n================\n\n- Add timestamp and hostname to syslog messages,\n this allows plugging SyslogKeyValueFormatter directly into logstash\n without an intermediary syslogd.\n\n\n0.1 (2013-08-16)\n================\n\n- initial release", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://bitbucket.org/gocept/gocept.logging/", "keywords": "", "license": "ZPL 2.1", "maintainer": "", "maintainer_email": "", "name": "gocept.logging", "package_url": "https://pypi.org/project/gocept.logging/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/gocept.logging/", "project_urls": { "Homepage": "https://bitbucket.org/gocept/gocept.logging/" }, "release_url": "https://pypi.org/project/gocept.logging/0.8.1/", "requires_dist": null, "requires_python": "", "summary": "Infrastructure for semi-structured log messages.", "version": "0.8.1" }, "last_serial": 2712779, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "f92cbe32f6d6732ef9ad3296c8990e09", "sha256": "2b6fee8eee878ddeab1e28f62a296a875aa900a9f4e7532f28426584ec81e77c" }, "downloads": -1, "filename": "gocept.logging-0.1.zip", "has_sig": false, "md5_digest": "f92cbe32f6d6732ef9ad3296c8990e09", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15645, "upload_time": "2013-08-16T12:30:25", "url": "https://files.pythonhosted.org/packages/c0/04/ff80a8b37d6fbf913a1f6a58f46fac82b8718cb45a6555cdfb3be58c3c92/gocept.logging-0.1.zip" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "23dd729929e224351dcbb80845f66c6d", "sha256": "5c7e4b1fa08b4c1a6fce43dc8d07fdba629faa50af2c1b2986794856e1e9b70d" }, "downloads": -1, "filename": "gocept.logging-0.2.zip", "has_sig": false, "md5_digest": "23dd729929e224351dcbb80845f66c6d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18243, "upload_time": "2013-08-24T12:00:48", "url": "https://files.pythonhosted.org/packages/eb/21/7db18dd8ab71e1c5d84b6c4d25eb7d7c8ac93ad0e8d0a1c988bc96d0f052/gocept.logging-0.2.zip" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "992b09f1cc5bdb6f7d5c8fe550132267", "sha256": "47effe87a57bd04210a0f97efcf683f17b2db765a4ebe2a5fd935bffe1e2d042" }, "downloads": -1, "filename": "gocept.logging-0.3.zip", "has_sig": false, "md5_digest": "992b09f1cc5bdb6f7d5c8fe550132267", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20330, "upload_time": "2013-09-04T06:19:06", "url": "https://files.pythonhosted.org/packages/9e/8d/79d02abb05d1dc0c4759768d0c33e3c77f8a952aa27428d07b5d19de6ee7/gocept.logging-0.3.zip" } ], "0.4": [ { "comment_text": "", "digests": { "md5": "440d85c3bfc269503618ae868b96353d", "sha256": "6274b0c76d77546c2e006d65fd0769bc29a209bbe89be4fbd5cbfa5228e783f6" }, "downloads": -1, "filename": "gocept.logging-0.4.zip", "has_sig": false, "md5_digest": "440d85c3bfc269503618ae868b96353d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20456, "upload_time": "2013-09-24T06:45:49", "url": "https://files.pythonhosted.org/packages/85/bd/8900578eac696c0436ee7120955b4fcd7cd487dca1effd53b8fa947ccac6/gocept.logging-0.4.zip" } ], "0.5": [ { "comment_text": "", "digests": { "md5": "01d1ba7c789b0ef01c8913c8eb32f4c4", "sha256": "5704a359b84fe450b58170a7a9d0cad6c1f9879b512c600084d2efc23cfafd59" }, "downloads": -1, "filename": "gocept.logging-0.5.tar.gz", "has_sig": false, "md5_digest": "01d1ba7c789b0ef01c8913c8eb32f4c4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12150, "upload_time": "2014-02-07T13:56:21", "url": "https://files.pythonhosted.org/packages/c4/54/2f1810aac4040e4594134540a7b1717f00a24fe57d849b24e79105f8b806/gocept.logging-0.5.tar.gz" } ], "0.6": [ { "comment_text": "", "digests": { "md5": "d72655aafb13d7430e5a28d89237bdb7", "sha256": "6ad90048ce564008db6743676f306bfc6d3fca76a5a8a813e455d709d733ace7" }, "downloads": -1, "filename": "gocept.logging-0.6.tar.gz", "has_sig": false, "md5_digest": "d72655aafb13d7430e5a28d89237bdb7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12430, "upload_time": "2015-09-17T12:28:25", "url": "https://files.pythonhosted.org/packages/f8/8c/1e9f90c1513887f83eb1f2374cb1a8f85c343dfc36224a8d52ed566e13ea/gocept.logging-0.6.tar.gz" } ], "0.7": [ { "comment_text": "", "digests": { "md5": "f88da89ea6ec3b288d1e8fd7ec95a2a7", "sha256": "17b15e31b668d2a4626756c741169c034babd6ccd9eaa69afac01d99fc7d12c1" }, "downloads": -1, "filename": "gocept.logging-0.7.tar.gz", "has_sig": false, "md5_digest": "f88da89ea6ec3b288d1e8fd7ec95a2a7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12516, "upload_time": "2015-09-29T15:39:34", "url": "https://files.pythonhosted.org/packages/ef/72/b1c756db4d5072de3c14a0266c49d0a31e76e76b8ebf53314b6149dd13da/gocept.logging-0.7.tar.gz" } ], "0.8": [ { "comment_text": "", "digests": { "md5": "6bc91b45a136c35f434b93248384b605", "sha256": "5d34e4e90d70d2e31eaf8f124b8ebe3d57ee442d808d6ec50731c58b02c0b5ca" }, "downloads": -1, "filename": "gocept.logging-0.8.tar.gz", "has_sig": false, "md5_digest": "6bc91b45a136c35f434b93248384b605", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12708, "upload_time": "2016-03-17T16:01:07", "url": "https://files.pythonhosted.org/packages/0d/0b/864f878eed9fcf0117cba46b3b26489521701ebca0e88a976ba7afafb57c/gocept.logging-0.8.tar.gz" } ], "0.8.1": [ { "comment_text": "", "digests": { "md5": "6998fdea82adaef8b0d5801001699d54", "sha256": "0cc8d067b594d00c08e58181f58c48a7bb6e99da002908f8bfadb9826a475d31" }, "downloads": -1, "filename": "gocept.logging-0.8.1.tar.gz", "has_sig": false, "md5_digest": "6998fdea82adaef8b0d5801001699d54", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12777, "upload_time": "2017-01-09T14:40:30", "url": "https://files.pythonhosted.org/packages/1c/8e/b59f01e81d0535355920ed5957ed29ed8ae72221b2f6fa28282b949465c7/gocept.logging-0.8.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "6998fdea82adaef8b0d5801001699d54", "sha256": "0cc8d067b594d00c08e58181f58c48a7bb6e99da002908f8bfadb9826a475d31" }, "downloads": -1, "filename": "gocept.logging-0.8.1.tar.gz", "has_sig": false, "md5_digest": "6998fdea82adaef8b0d5801001699d54", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12777, "upload_time": "2017-01-09T14:40:30", "url": "https://files.pythonhosted.org/packages/1c/8e/b59f01e81d0535355920ed5957ed29ed8ae72221b2f6fa28282b949465c7/gocept.logging-0.8.1.tar.gz" } ] }