{
"info": {
"author": "Jim Fulton",
"author_email": "jim@zope.com",
"bugtrack_url": null,
"classifiers": [],
"description": "zc.z3monitor plugin and log handler for getting Log statistics\n==============================================================\n\nzc.monitorlogstats provides a zc.z3monitor plugin and log handler to\ntrack log statistics. The idea is that you can conect to it to find\nout how many log entries of various types have been posted. If you\nsample it over time, youcan see how many entries are added. In\nparticular, if you get new warning, error, or critical entries,\nsomeone might want to look at the logs to find out what's going on.\n\nCounting Log Handler\n--------------------\n\nLet's start by looking at the log handler. The factory\nzc.monitorlogstats.CountingHandler can be installed like any other\nhandler. It doesn't emit anything. It just counts.\n\nLet's create one to see how it works:\n\n >>> import logging, zc.monitorlogstats\n >>> handler = zc.monitorlogstats.CountingHandler()\n >>> logging.getLogger().addHandler(handler)\n >>> logging.getLogger().setLevel(logging.INFO)\n\nNow, let's log:\n\n >>> for i in range(5):\n ... logging.getLogger('foo').critical('Yipes')\n\n >>> for i in range(9):\n ... logging.getLogger('bar').error('oops')\n\n >>> for i in range(12):\n ... logging.getLogger('baz').warn('hm')\n\n >>> for i in range(21):\n ... logging.getLogger('foo').info('yawn')\n\n >>> for i in range(99):\n ... logging.getLogger('xxx').log(5, 'yuck yuck')\n\nWe can ask the handler for statistics:\n\n >>> handler.start_time\n datetime.datetime(2008, 9, 5, 21, 10, 14)\n\n >>> for level, count, message in handler.statistics:\n ... print level, count\n ... print `message`\n 20 21\n 'yawn'\n 30 12\n 'hm'\n 40 9\n 'oops'\n 50 5\n 'Yipes'\n\nThe statistics consist of the log level, the count of log messages,\nand the formatted text of last message.\n\nWe can also ask it to clear it's statistics:\n\n >>> handler.clear()\n >>> for i in range(3):\n ... logging.getLogger('foo').critical('Eek')\n\n >>> handler.start_time\n datetime.datetime(2008, 9, 5, 21, 10, 15)\n\n >>> for level, count, message in handler.statistics:\n ... print level, count\n ... print `message`\n 50 3\n 'Eek'\n\nThere's ZConfig support for defining counting handlers:\n\n >>> import ZConfig, StringIO\n >>> schema = ZConfig.loadSchemaFile(StringIO.StringIO(\"\"\"\n ... \n ... \n ... \n ... \n ... \n ... \"\"\"))\n\n >>> conf, _ = ZConfig.loadConfigFile(schema, StringIO.StringIO(\"\"\"\n ... %import zc.monitorlogstats\n ... \n ... name test\n ... level INFO\n ... \n ... format %(name)s %(message)s\n ... \n ... \n ... \"\"\"))\n\n >>> testhandler = conf.loggers[0]().handlers[0]\n\n >>> for i in range(2):\n ... logging.getLogger('test').critical('Waaa')\n >>> for i in range(22):\n ... logging.getLogger('test.foo').info('Zzzzz')\n\n >>> for level, count, message in handler.statistics:\n ... print level, count\n ... print `message`\n 20 22\n 'Zzzzz'\n 50 5\n 'Waaa'\n\n >>> for level, count, message in testhandler.statistics:\n ... print level, count\n ... print `message`\n 20 22\n 'test.foo Zzzzz'\n 50 2\n 'test Waaa'\n\nNote that the message output from the test handler reflects the format\nwe used when we set it up. \n\nThe example above illustrates that you can install as many counting\nhandlers as you want to.\n\nMonitor Plugin\n--------------\n\nThe zc.monitorlogstats Monitor plugin can be used to query log statistics.\n\n >>> import sys\n >>> plugin = zc.monitorlogstats.monitor(sys.stdout)\n 2008-09-05T21:10:15\n 20 22 'Zzzzz'\n 50 5 'Waaa'\n\nThe output consists of the start time and line for each log level for\nwhich there are statistics. Each statistics line has the log level,\nentry count, and a repr of the last log message.\n\nBy default, the root logger will be used. You can specify a logger name:\n\n >>> plugin = zc.monitorlogstats.monitor(sys.stdout, 'test')\n 2008-09-05T21:10:16\n 20 22 'test.foo Zzzzz'\n 50 2 'test Waaa'\n\nYou can use '.' for the root logger:\n\n >>> plugin = zc.monitorlogstats.monitor(sys.stdout, '.')\n 2008-09-05T21:10:15\n 20 22 'Zzzzz'\n 50 5 'Waaa'\n\nNote that if there are multiple counting handlers for a logger, only\nthe first will be used. (So don't define more than one. :)\n\nIt is an error to name a logger without a counting handler:\n\n >>> plugin = zc.monitorlogstats.monitor(sys.stdout, 'test.foo')\n Traceback (most recent call last):\n ...\n ValueError: Invalid logger name: test.foo\n\nYou can specify a second argument with a value of 'clear', ro clear\nstatistics:\n\n >>> plugin = zc.monitorlogstats.monitor(sys.stdout, 'test', 'clear')\n 2008-09-05T21:10:16\n 20 22 'test.foo Zzzzz'\n 50 2 'test Waaa'\n\n >>> plugin = zc.monitorlogstats.monitor(sys.stdout, 'test', 'clear')\n 2008-09-05T21:10:17\n\n.. Edge case:\n \n >>> plugin = zc.monitorlogstats.monitor(sys.stdout, 'test', 'yes')\n Traceback (most recent call last):\n ...\n ValueError: The second argument, if present, must have the value 'clear'.\n \n\n.. Cleanup:\n\n >>> logging.getLogger().removeHandler(handler)\n >>> logging.getLogger().setLevel(logging.NOTSET)\n \n >>> logging.getLogger('test').removeHandler(testhandler)\n >>> logging.getLogger('test').setLevel(logging.NOTSET)\n\nDownload\n--------",
"description_content_type": null,
"docs_url": null,
"download_url": "UNKNOWN",
"downloads": {
"last_day": -1,
"last_month": -1,
"last_week": -1
},
"home_page": "UNKNOWN",
"keywords": null,
"license": "ZPL 2.1",
"maintainer": null,
"maintainer_email": null,
"name": "zc.monitorlogstats",
"package_url": "https://pypi.org/project/zc.monitorlogstats/",
"platform": "UNKNOWN",
"project_url": "https://pypi.org/project/zc.monitorlogstats/",
"project_urls": {
"Download": "UNKNOWN",
"Homepage": "UNKNOWN"
},
"release_url": "https://pypi.org/project/zc.monitorlogstats/0.1.0/",
"requires_dist": null,
"requires_python": null,
"summary": "Log handler and zc.z3monitor plugin to monitor log activity",
"version": "0.1.0"
},
"last_serial": 802184,
"releases": {
"0.1.0": [
{
"comment_text": "",
"digests": {
"md5": "21a0333b05d8e4d680a169e8770fd2e6",
"sha256": "347d2254048f6062450be36e1fa6274adeb09a4042b68e36f2761f700cfb9251"
},
"downloads": -1,
"filename": "zc.monitorlogstats-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "21a0333b05d8e4d680a169e8770fd2e6",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 5315,
"upload_time": "2008-09-08T19:54:50",
"url": "https://files.pythonhosted.org/packages/c8/a0/10335898a84119558e5f9b4a5bf87afb15e024abdf1b94e29a766c28bb3e/zc.monitorlogstats-0.1.0.tar.gz"
}
]
},
"urls": [
{
"comment_text": "",
"digests": {
"md5": "21a0333b05d8e4d680a169e8770fd2e6",
"sha256": "347d2254048f6062450be36e1fa6274adeb09a4042b68e36f2761f700cfb9251"
},
"downloads": -1,
"filename": "zc.monitorlogstats-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "21a0333b05d8e4d680a169e8770fd2e6",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 5315,
"upload_time": "2008-09-08T19:54:50",
"url": "https://files.pythonhosted.org/packages/c8/a0/10335898a84119558e5f9b4a5bf87afb15e024abdf1b94e29a766c28bb3e/zc.monitorlogstats-0.1.0.tar.gz"
}
]
}