{ "info": { "author": "sashgorokhov", "author_email": "sashgorokhov@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "django-modelhandler\n*******************\n\n.. image:: https://badge.fury.io/py/django-modelhandler.svg\n :target: https://badge.fury.io/py/django-modelhandler\n\n.. image:: https://travis-ci.org/sashgorokhov/django-modelhandler.svg?branch=master\n :target: https://travis-ci.org/sashgorokhov/django-modelhandler\n\nA python logging handler that saves logs into django model. That's it.\n\nInstallation\n============\n\nVia pip:\n\n.. code-block:: shell\n\n pip install django-modelhandler\n\nUsage\n=====\n\nAdd ``modelhandler`` to your INSTALLED_APPS, then, configure log handler in your desired way.\nFor example, using dictConfig:\n\n.. code-block:: python\n\n {\n 'version': 1,\n 'handlers': {\n 'modelhandler': {\n 'class': 'modelhandler.handlers.LogModel',\n 'level': 'ERROR'\n }\n },\n 'loggers': {\n 'my_logger': {\n 'handlers': ['modelhandler'],\n 'level': 'ERROR'\n }\n }\n }\n\nRun migrations that will create a ``Log`` model:\n\n.. code-block:: shell\n\n python manage.py migrate\n\nAnd now you can start logging in django model.\n\nGetting logs:\n\n.. code-block:: python\n\n from modelhandler.models import Log\n # Get the latest log\n log = Log.objects.latest()\n log.name # logger name\n log.level # logging level integer\n log.levelname # logging level as string (DEBUG, INFO, etc.)\n log.message # the log message\n log.traceback # traceback, if exists. default: None\n log.filename # filename (with ext) where the log was sent\n log.funcName # function name where the log was sent\n log.created # log creation datetime\n log.formatted # the log message as if it was written in file. (with [datetime] [level] etc.)\n\n\nIf you have a django admin enabled, then you can browse your logs on model Log of application modelhandler.\nIt has a customized modeladmin to enabale filtering by logger name and levelname, and searching by message.\n\nIf you would like to customize a log model (to alter models Meta), then just subclass a ``modelhandler.models.Log``\nmodel, do whatever you want and add your model to LogModel handler parameters:\n\n.. code-block:: python\n\n 'handlers': {\n 'modelhandler': {\n 'class': 'modelhandler.handlers.LogModel',\n 'model': 'path.to.your.model'\n 'level': 'ERROR'\n }\n }\n\nIf you using celery in your project then you might want to add some model cleaning tasks in ``CELERYBEAT_SCHEDULE``:\n\n.. code-block:: python\n\n CELERYBEAT_SCHEDULE = {\n 'cleanup_day': {\n 'task': 'modelhandler.tasks.cleanup_day',\n 'schedule': timedelta(days=1)\n }, # OR\n 'cleanup_week': {\n 'task': 'modelhandler.tasks.cleanup_week',\n 'schedule': timedelta(days=7)\n }, # OR\n 'cleanup_month': {\n 'task': 'modelhandler.tasks.cleanup_month',\n 'schedule': timedelta(days=30)\n }\n }\n\n``modelhandler.tasks.cleanup_day`` will delete all logs that are older than one day from time of task execution.\n``modelhandler.tasks.cleanup_week`` and ``modelhandler.tasks.cleanup_month`` are similar.\n\nIf you want to customize the time of deletion, there is a task ``modelhandler.tasks.cleanup_logs`` that accepts\na ``before`` parameter that must be a datetime object or None (in this case a value of timezone.now() will be taken).\nThere is no magic: just ``Log.objects.filter(created__lte=before).delete()``\n\n\n.. :changelog:\n\nHistory\n-------\n\n1.0.0 (2016-06-12)\n++++++++++++++++++\n\n* Initial release", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/sashgorokhov/django-modelhandler/archive/master.zip", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/sashgorokhov/django-modelhandler", "keywords": "django,logging,handler", "license": "MIT License", "maintainer": null, "maintainer_email": null, "name": "django-modelhandler", "package_url": "https://pypi.org/project/django-modelhandler/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-modelhandler/", "project_urls": { "Download": "https://github.com/sashgorokhov/django-modelhandler/archive/master.zip", "Homepage": "https://github.com/sashgorokhov/django-modelhandler" }, "release_url": "https://pypi.org/project/django-modelhandler/1.0.0/", "requires_dist": null, "requires_python": null, "summary": "A python logging handler that saves logs into django model. That's it.", "version": "1.0.0" }, "last_serial": 2169145, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "8dd1cddeb9ac3509f0b20d6f40d3a3f7", "sha256": "46dca9679896173bfa6d922b8856d0f4e9c63ac306d6260c804104700d0e3435" }, "downloads": -1, "filename": "django-modelhandler-1.0.0.zip", "has_sig": false, "md5_digest": "8dd1cddeb9ac3509f0b20d6f40d3a3f7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6574, "upload_time": "2016-06-15T18:05:58", "url": "https://files.pythonhosted.org/packages/c6/89/93e4a4adecc3b0d8966cd3f90666f93513d9dabdcd55fe6a516f8d826f3d/django-modelhandler-1.0.0.zip" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8dd1cddeb9ac3509f0b20d6f40d3a3f7", "sha256": "46dca9679896173bfa6d922b8856d0f4e9c63ac306d6260c804104700d0e3435" }, "downloads": -1, "filename": "django-modelhandler-1.0.0.zip", "has_sig": false, "md5_digest": "8dd1cddeb9ac3509f0b20d6f40d3a3f7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6574, "upload_time": "2016-06-15T18:05:58", "url": "https://files.pythonhosted.org/packages/c6/89/93e4a4adecc3b0d8966cd3f90666f93513d9dabdcd55fe6a516f8d826f3d/django-modelhandler-1.0.0.zip" } ] }