{"id":14483336,"url":"https://github.com/joeribekker/django-logdb","last_synced_at":"2025-03-21T03:33:26.253Z","repository":{"id":57420673,"uuid":"465225","full_name":"joeribekker/django-logdb","owner":"joeribekker","description":"Django-logdb enables you to log entries to a database, aggregate and act on  them with certain rules, and gives you more insight in what's going on.","archived":false,"fork":false,"pushed_at":"2016-10-23T08:37:36.000Z","size":247,"stargazers_count":31,"open_issues_count":4,"forks_count":7,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-12T07:29:28.392Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://www.maykinmedia.nl","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joeribekker.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES.rst","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-01-09T16:02:50.000Z","updated_at":"2022-04-28T14:22:32.000Z","dependencies_parsed_at":"2022-09-13T02:00:43.300Z","dependency_job_id":null,"html_url":"https://github.com/joeribekker/django-logdb","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeribekker%2Fdjango-logdb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeribekker%2Fdjango-logdb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeribekker%2Fdjango-logdb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeribekker%2Fdjango-logdb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joeribekker","download_url":"https://codeload.github.com/joeribekker/django-logdb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221811374,"owners_count":16884305,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-03T00:01:42.297Z","updated_at":"2024-10-28T09:17:06.579Z","avatar_url":"https://github.com/joeribekker.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"DJANGO-LOGDB\r\n============\r\n\r\nDjango-logdb enables you to log entries to a database, aggregate and act on \r\nthem with certain rules, and gives you more insight in what's going on.\r\n\r\nDjango-logdb requires Django 1.1 and higher.\r\n\r\nDescription\r\n-----------\r\n\r\nDjango-logdb has a custom logging handler that writes log entries to the\r\ndatabase. It therefore integrates nicely with your existing logging \r\nconfiguration and you can decide what log entries are written to the database.\r\n\r\nThe Django admin site is extended with a graphical view of recent log entries\r\nto provide more insight in what is going on. The log messages are grouped by\r\nlog level or \"type of log entry\".\r\n\r\nTo minimize database access, aggregation is done via a Django command that you\r\ncan call periodically (as a cronjob).\r\n\r\nInstall\r\n-------\r\n\r\nThe easiest way to install the package is via setuptools::\r\n\r\n    easy_install django-logdb\r\n\r\nOnce installed, update your Django `settings.py` and add ``djangologdb`` to your \r\nINSTALLED_APPS::\r\n\r\n    INSTALLED_APPS = (\r\n        'django.contrib.admin',\r\n        'django.contrib.auth',\r\n        'django.contrib.contenttypes',\r\n        'django.contrib.sessions',\r\n        ...\r\n        'djangologdb',\r\n    )\r\n\r\nIn your Django `urls.py`, include the `djangologdb.urls` before the admin::\r\n\r\n    urlpatterns = patterns('',\r\n        ...\r\n        (r'^admin/djangologdb/', include('djangologdb.urls')),\r\n        ...\r\n        (r'^admin/', include(admin.site.urls)),\r\n    )\r\n\r\nOptionally, if you want to log exceptions, add the middleware::\r\n\r\n    MIDDLEWARE_CLASSES = (\r\n        'django.middleware.common.CommonMiddleware',\r\n        'django.contrib.sessions.middleware.SessionMiddleware',\r\n        'django.contrib.auth.middleware.AuthenticationMiddleware',\r\n        ...\r\n        'djangologdb.middleware.LoggingMiddleware',\r\n    )\r\n\r\nRun ``python manage.py syncdb`` to create the database tables.\r\n\r\nSetup logging\r\n-------------\r\n\r\nNow, for the actual logging part, you should use the database logging handler.\r\nThere are two ways to do this: Using only Python code, or, by using a \r\nconfiguration file. Both methods are explained below. \r\n\r\nTo add this handler via Python to, for example, your root logger, you can add\r\nthe following to your Django `settings.py`::\r\n\r\n    import logging\r\n    from djangologdb.handler import DjangoDatabaseHandler, add_handler\r\n    \r\n    logging.basicConfig(level=logging.DEBUG)\r\n    logger = logging.getLogger()\r\n    \r\n    # A bug in Django causes the settings to load twice. Using \r\n    # this handler instead of logging.addHandler works around that.\r\n    add_handler(logger, DjangoDatabaseHandler())\r\n        \r\nTo use this handler via a logging configuration file, simply import the \r\n``handlers`` module from ``djangologdb`` in your Django `settings.py` before \r\nloading the configuration from a file::\r\n\r\n    from djangologdb import handlers\r\n    logging.config.fileConfig(...)\r\n    \r\nThen in your logging configuration file, you can add it from the handlers \r\nnamespace and add it to any logger you want::\r\n\r\n    [handlers]\r\n    keys=djangologdb\r\n    \r\n    [logger_root]\r\n    level=NOTSET\r\n    handlers=djangologdb\r\n    \r\n    [handler_djangologdb]\r\n    class=handlers.DjangoDatabaseHandler\r\n    args=()\r\n\r\nConfiguration\r\n-------------\r\n\r\nYou can set the following settings in your Django `settings.py` file:\r\n\r\nLOGDB_HISTORY_DAYS\r\n\tThe number of days to show in the various graphs.\r\n\t\r\n\tDefault::\r\n\t\r\n\t\tLOGDB_HISTORY_DAYS = 30\r\n\r\nLOGDB_INTERVAL\r\n\tThe ``timedelta`` between each datapoint in the various graphs.\r\n\t\r\n\tDefault::\r\n\r\n\t\tLOGDB_INTERVAL = datetime.timedelta(1) # 1 day\r\n\r\nLOGDB_RULES\r\n    Define rules to create a new log entry when certain conditions are true.\r\n    \r\n    Default::\r\n    \r\n        LOGDB_RULES = \r\n            [{\r\n                # If 3 logs with level WARNING or higher occur in 5 minutes or\r\n                # less, create a new log with level CRITICAL.\r\n                'conditions': {\r\n                    'min_level': logging.WARNING,\r\n                    'qualname': '',\r\n                    'min_times_seen': 3,\r\n                    'within_time': datetime.timedelta(0, 5 * 60),\r\n                },\r\n                'actions': {\r\n                    'level': logging.CRITICAL,\r\n                }\r\n            }]\r\n\r\nLOGDB_LEVEL_COLORS\r\n    Set colors to use in the graph for level based datasets.\r\n\r\n    Default::\r\n    \r\n        LOGDB_LEVEL_COLORS =\r\n            {\r\n                logging.DEBUG: '#c2c7d1',\r\n                logging.INFO: '#aad2e9',\r\n                logging.WARNING: '#b9a6d7',\r\n                logging.ERROR: '#deb7c1',\r\n                logging.CRITICAL: '#e9a8ab',\r\n            }\r\n\r\nLOGDB_MEDIA_ROOT\r\n    Set the absolute path to the directory of `django-logdb` media.\r\n    \r\n    Default::\r\n        \r\n        LOGDB_MEDIA_ROOT = os.path.join(djangologdb.__path__[0], 'media')\r\n    \r\nLOGDB_MEDIA_URL\r\n    Set the URL that handles the media served from ``LOGDB_MEDIA_ROOT``. Make \r\n    sure to add a trailing slash at the end. If ``settings.DEBUG=True``, the \r\n    media will be served by Django.\r\n    \r\n    Default::    \r\n    \r\n        LOGDB_MEDIA_URL = '/admin/djangologdb/media/'\r\n\r\nCommands\r\n--------\r\n\r\naggregate_logs\r\n    Aggregates log entries and triggers any action with matching rules. \r\n    \r\n    *Usage*:\r\n        ``python django-admin.py aggregate_logs``\r\n        \r\n    *Options*:\r\n        -s, --skip-actions    Do not use the rules to create new logs.\r\n        --cleanup=CLEANUP     Specifies the number of days to keep log entries\r\n                              and deletes the rest.\r\n\r\nFAQ\r\n---\r\n\r\nThe graph doesn't show in the Django admin.\r\n    If you don't have ``settings.DEBUG=True``, the media will not be served by \r\n    Django. You should copy the media directory to your own media directory and\r\n    set LOGDB_MEDIA_ROOT and LOGDB_MEDIA_URL accordingly.\r\n    \r\n    Example::\r\n    \t\r\n    \tLOGDB_MEDIA_ROOT = '/myproject/media/djanglogdb/'\r\n    \tLOGDB_MEDIA_URL = '/media/djanglogdb/'\r\n    \r\n    Instead of copying, you can also use Apache's Alias directive to serve the \r\n    static files, as you probably also did for Django's own media files. It is\r\n    explained here: http://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/#serving-media-files\r\n    This boils down to adding the following line to your VirtualHost entry::\r\n    \r\n    \tAlias \u003cyour LOGDB_MEDIA_URL setting\u003e \u003cpath to django-logdb media dir\u003e\r\n    \r\n    Example::\r\n\r\n\t\tAlias /admin/djangologdb/media/ /myproject/eggs/django_logdb-0.9.5-py2.6.egg/djangologdb/media/\r\n\r\nThe Django admin pages for django-logdb load very slow.\r\n    If you have a lot of datapoints in the graph, it executes a lot of queries.\r\n    This can take some time. You should decrease the time period or increase the\r\n    interval. By default, the last 30 days with an interval of 1 day is used, \r\n    resulting in 30 datapoints.\r\n    See the settings ``LOGDB_HISTORY_DAYS`` and ``LOGDB_INTERVAL``.\r\n    \r\nWhy is there 1 query executed for each datapoint?\r\n    Django does not (yet) allow to group by certain date information. Even \r\n    though a timestamp is stored in the database, there is no way to tell the \r\n    Django ORM to group by day, by hour, etc. The solution I used was to \r\n    filter/limit the results needed to construct 1 datapoint.\r\n\r\nWhen I run my tests, I see ``ERROR:djangologdb.middleware`` [...]\r\n    When you run, for example, the testproject, the configuration is set so\r\n    that any error is also displayed on ``sys.stderr``. As you you'll see, the\r\n    tests all succeed but the exceptions that are tested are just displayed in\r\n    the console. This is not an error!\r\n\r\n    You can disable this behaviour by disabling logging to the console for your\r\n    test configuration (ie. remove the handler).\r\n\r\nWhy are the templates extending a local version of the Django base templates?\r\n    This is done for optimal flexibility regarding custom templates. Skins like\r\n    Grappelli override a lot of templates and sometimes you want to be able to\r\n    change and use the base template in django-logdb and change some specifics\r\n    in the django-logdb template itself without copying all the base template\r\n    stuff.\r\n\r\nTest project\r\n------------\r\n\r\nThe testproject is a sample installation of django-logdb. It provides a \r\nsettings file for Django 1.1 and Django 1.2, just to run it.\r\n\r\nIn the directory below the testproject, create a virtual environment::\r\n\r\n    $ virtualenv .\r\n    $ source bin/activate\r\n\r\nInstall Django and run the internal server using one of the setting files for\r\nyour Django version.\r\n\r\n    $ bin/python bin/pip install django\r\n    $ bin/python bin/django-admin.py runserver --settings=testproject.settings_django_1_1\r\n\r\n\r\nThanks\r\n------\r\nTo the various people that helped making this project better and better:\r\n\r\n- Maciek Szczesniak (vvarp)\r\n- Victor van den Elzen\r\n\r\nThanks to David Cramer for his work on django-db-log \r\n(http://github.com/dcramer/django-db-log/) on which this package was based.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoeribekker%2Fdjango-logdb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoeribekker%2Fdjango-logdb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoeribekker%2Fdjango-logdb/lists"}