GithubHelp home page GithubHelp logo

pinax-eventlog's Introduction

Pinax Eventlog

CircleCi Codecov

Table of Contents

About Pinax

Pinax is an open-source platform built on the Django Web Framework. It is an ecosystem of reusable Django apps, themes, and starter project templates. This collection can be found at http://pinaxproject.com.

Important Links

Where you can find what you need:

pinax-eventlog

Overview

pinax-eventlog is a simple app that provides an easy and clean interface for logging diagnostic as well as business intelligence data about activity that occurs in your site.

By default this app writes directly to the database.

For small sites, it should be good enough to use inline but you might want to consider wrapping calls to the log() method and queue them in a job manager like celery or pyres so that the calls become asynchronous.

Supported Django and Python versions

Django / Python 3.6 3.7 3.8
2.2* * * *
3.0* * * *
3.1 * * *

see Installation in Django < 3.1 below

Documentation

Installation in Django >=3.1

To install pinax-eventlog:

    $ pip install pinax-eventlog

Add pinax.eventlog to your INSTALLED_APPS setting:

    INSTALLED_APPS = [
        # other apps
        "pinax.eventlog",
    ]

Run the app's migrations:

    $ python manage.py migrate eventlog

Installation in Django <3.1

Django 3.1 introduced a JSON model field on all supported backends:

https://docs.djangoproject.com/en/3.1/releases/3.1/#jsonfield-for-all-supported-database-backends

To use pinax-eventlog on sites running Django 2.2 and 3.0, you'll want to install the package with the django-lts extra:

    $ pip install pinax-eventlog[django-lts]

Add pinax.eventlog and django_jsonfield_backport to your INSTALLED_APPS setting:

    INSTALLED_APPS = [
        # other apps
        "django_jsonfield_backport,
        "pinax.eventlog",
    ]

Run the app's migrations:

    $ python manage.py migrate eventlog

Usage

Using pinax-eventlog is pretty simple. Throughout your site, you just call a single function, log() to record whatever information you want to log. If you are wanting to log things from third party apps, your best bet is to use signals. Hopefully the app in question provides some useful signals, but if not, perhaps some of the built in model signals will be enough (e.g. pre_save, post_delete, etc.)

Example:

from pinax.eventlog.models import log

def some_view(request):
    # stuff is done in body of view
    # then at the end before returning the response:
    log(
        user=request.user,
        action="CREATED_FOO_WIDGET",
        obj=foo,
        extra={
            "title": foo.title
        }
    )
    return HttpResponse()

The action parameter can be any string you choose. By convention, we always use all caps. Take note, however, whatever you choose, will be the label that appears in the admin's list filter, so give it some thought on naming conventions in your site so that the admin interface makes sense when you have 50,000 log records you want to filter down and analyze.

The extra parameter can be anything that will serialize to JSON. Results become easier to manage if you keep it at a single level. Also, keep in mind that this is displayed in the admin's list view so if you put too much it can take up a lot of space. A good rule of thumb here is put enough identifying data to get a sense for what is going on and a key or keys that enable you to dig deeper if you want or need to.

Mixin

You can also easily make your class based views auto-logged by using the pinax.eventlog.mixins.EventLogMixin. The only requirement is defining an action_kind property on the view. But you can also override a number of properties to customize what is logged.

Signals

There is a signal that you are setup a receiver for to enable you to trigger other actions when an event has been logged:

event_logged provides an event object as an argument that is the event that was just logged.

Change Log

5.1.1

5.1.0

5.0.0

  • Switch to Django 3.1's JSONField
  • Reset migrations (see discussion in #33)

4.0.1

  • Update models.py to support MySQL JSONField

4.0.0

  • Drop Django 1.11, 2.0, and 2.1, and Python 2,7, 3.4, and 3.5 support
  • Add Django 2.2 and 3.0, and Python 3.6, 3.7, and 3.8 support
  • Update packaging configs
  • Direct users to community resources

3.0.0

2.0.3

  • Use SET_NULL so Log instances are not deleted when related object is deleted
  • Update runtests.py
  • Update CI configuration
  • Update jsonfield requirement

2.0.2

  • fix setup.py LONG_DESCRIPTION for PyPi

2.0.1

  • Standardize and improve documentation

2.0.0

  • Add Django 2.0 compatibility testing
  • Drop Django 1.8, 1.9, 1.10 and Python 3.3 support
  • Convert CI and coverage to CircleCi and CodeCov
  • Add PyPi-compatible long description
  • Move documentation to README.md

1.1.2

  • Fix spelling error in documentation
  • Added wheel release
  • Dropped 3.2 support

1.1.1

  • Added missing migration from the switch to jsonfield

1.1.0

  • Started testing against Django master
  • Switched to jsonfield from django-jsonfield
  • Added ability to link a log to any object via a GFK
  • Added ability to override timestamp
  • Fixed template fragment path

1.0.0

  • Eldarion donated to Pinax, renaming from eventlog to pinax-eventlog

0.11.0

  • added the ability to link content objects you are logging about

0.10.0

  • added property to provide template fragment name

0.9.0

  • Add mixin for making it easy to audit CBV

0.8.0

  • removed non-working templatetag
  • update setup to work with Python 3.3+

0.7.0

  • remove pusher integration
  • support for custom user model

0.6.7

  • added the event_logged signal
  • corrected typo in usage documentation

0.6.6

  • attempts at fixing admin performance

0.6.5

  • attempts at fixing admin performance

0.6.4

  • attempts at fixing admin performance with an index on action

0.6.3

  • attempts at fixing admin performance with an index on timestamp

0.6.2

  • update setup.py to use install_requires instead of setup_requires

0.6.1

  • made the extra argument optional

0.6.0

  • improve the admin

0.5.5

  • use django.utils.timezone.now instead of datetime.datetime.now for timestamp

0.5.4

  • when a user is deleted set FK to null instead of losing data

0.5.3

  • bumped version on django-jsonfield

0.5.2

  • added docs

0.5.1

  • initial release

History

This project was originally named eventlog and was created by the team at Eldarion. It was later donated to Pinax and at that time renamed to pinax-eventlog.

Contribute

Contributing information can be found in the Pinax community health file repo.

Code of Conduct

In order to foster a kind, inclusive, and harassment-free community, the Pinax Project has a Code of Conduct. We ask you to treat everyone as a smart human programmer that shares an interest in Python, Django, and Pinax with you.

Connect with Pinax

For updates and news regarding the Pinax Project, please follow us on Twitter @pinaxproject and check out our Pinax Project blog.

License

Copyright (c) 2012-present James Tauber and contributors under the MIT license.

pinax-eventlog's People

Contributors

brosner avatar grahamu avatar jacobwegner avatar jtauber avatar katherinemichel avatar mfonism avatar micrypt avatar msabramo avatar paltman avatar patrickscottbest avatar rosscdh avatar stard0g avatar tbitai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pinax-eventlog's Issues

"TypeError: Type str doesn't support the buffer API" when installing under Python 3.3

I get the following error when trying to install eventlog in a virtualenv with Python 3:

» pip install eventlog
Downloading/unpacking eventlog
  Downloading eventlog-0.6.6.tar.gz
  Running setup.py egg_info for package eventlog
    Traceback (most recent call last):
      File "<string>", line 16, in <module>
      File "/home/totte/virtual_environments/webenv/build/eventlog/setup.py", line 138, in <module>
        zip_safe=False
      File "/usr/lib/python3.3/distutils/core.py", line 148, in setup
        dist.run_commands()
      File "/usr/lib/python3.3/distutils/dist.py", line 917, in run_commands
        self.run_command(cmd)
      File "/usr/lib/python3.3/distutils/dist.py", line 936, in run_command
        cmd_obj.run()
      File "<string>", line 13, in replacement_run
      File "/home/totte/virtual_environments/webenv/lib/python3.3/site-packages/setuptools/command/egg_info.py", line 415, in write_pkg_info
        metadata.write_pkg_info(cmd.egg_info)
      File "/usr/lib/python3.3/distutils/dist.py", line 1015, in write_pkg_info
        self.write_pkg_file(pkg_info)
      File "/usr/lib/python3.3/distutils/dist.py", line 1036, in write_pkg_file
        long_desc = rfc822_escape(self.get_long_description())
      File "/usr/lib/python3.3/distutils/util.py", line 490, in rfc822_escape
        lines = header.split('\n')
    TypeError: Type str doesn't support the buffer API
...

In a CBV how do you override the extra_data?

I can't get the override of the extra_data property to work on a CBV view. It complains about view object is not JSON serializable.

This is what I am trying to do to override it.

 class  ApplicationUpdateView(EventLogMixin, UpdateView):
     ....
     def extra_data(self):      
         return super(ApplicationUpdateView, self).extra_data({"TEST": "TEST"})

Latest V4.0.1 not working for Mysql Database

Describe the bug
I tried to upgrade to new version pinax-eventlog for my app with djangoV3.0.8, Python 3.8,Mysql 5.7.22 and when trying to launch the instance i see this following error. When I looked at the migration file
eventlog.0004_auto_20191205_2033 that is failing on it trying to grab a postgres field/variable (field=django.contrib.postgres.fields.jsonb.JSONField()) which my app doesn't have
I see this issue with both 3.0.1 and 4.0.1 version and currently i was on v2 which did not had a problem. is there a work around for this?

Applying eventlog.0001_initial... OK
Applying eventlog.0002_auto_20150113_1450... OK
Applying eventlog.0003_auto_20160111_0208... OK
Applying eventlog.0004_auto_20191205_2033...Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/django/db/backends/utils.py", line 86, in _execute
   return self.cursor.execute(sql, params)
File "/usr/local/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 74, in execute
    return self.cursor.execute(query, args)
   File "/usr/local/lib/python3.8/site-packages/MySQLdb/cursors.py", line 209, in execute
    res = self._query(query)
   File "/usr/local/lib/python3.8/site-packages/MySQLdb/cursors.py", line 315, in _query
     db.query(q)
  File "/usr/local/lib/python3.8/site-packages/MySQLdb/connections.py", line 239, in query
    _mysql.connection.query(self, query)
 MySQLdb._exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'jsonb NOT NULL' at line 1")

Reproduce behavior

  1. Upgrade to new version 4.0.1 build and start the instance and when applying migrations the error occurs

Expected behavior
All migrations should apply correctly

Desktop

  • Mac

django-jsonfield vs jsonfield

I would like to use jsonfield instead of django-jsonfield which works fine once it is installed but when I install eventlog after I installed jsonfield django-jsonfield will overwrite the package. This is more of a django-jsonfield issue but I was wondering if maybe eventlog could provide an option to install jsonfield instead of django-jsonfield.

I think I would change the setup.py to include an "extra" option to use jsonfield instead. What do you think?

Support Django 2.2 via django-jsonfield-backport

As discussed in #32, #33 drops Django 2.2 support.

Since Django 2.2 is an LTS release, the co-author of the new JSONField added in 3.1 actually created a backport package:

https://github.com/laymonage/django-jsonfield-backport#why-create-another-one

Django's release process does not backport new features to previous feature releases. However, the current LTS release is 2.2 which is still supported until April 2022. The next LTS release is Django 3.2 in April 2021 that happens to be the end of extended support for Django 3.1.

Some projects only use LTS releases of Django. There are also incompatibilities between Django 3.0 and 3.1. Therefore, using Django 3.1 may not be an option for some people at the moment

Since JSONField seems to be in popular demand and that it works well as a standalone package, I decided to create a backport.

I'd like to propose we introduce a small shim to the 5.x release that:

  • adds django-jsonfield-backport as an optional dependency
  • modifies models.py and the initial migration to work with the shim'd field
  • provides documentation to site developers on how to use eventlog in Django~2.2 projects via django-jsonfield-backport

As part of this work, we would update the tox test matrix to prove out this support.

@paltman and @KatherineMichel: Does this seem reasonable to you? This would allow us to leverage the awesome JSONField while still keeping Django 2.2 compatibility as outlined in https://github.com/pinax/pinax/wiki/Pinax-20.XX-Release-Plan#pinax-20xx-release-overview.

If so, I can prepare a PR within the next week or so.

Thanks!

Event model used in eventlog_tags.py can not be resolved

When using the template tags and retrieve the calls with the following line
{% user_event_log user as logs %}
I got an error saying "global name 'Event' is not defined."

And, when I changed eventlog_tags.py to get the logs from Log model, everything looks fine. So I either missing something or the library has a dependency that can not be resolved.

Django version is 1.6.1
Database is Postgres

ImportError: No module named eventlog

Im getting this error, i have installed using:
sudo pip install pinax-eventlog

Also i have added 'pinax.eventlog' to the installed apps but nothing.

Anyway to solve this?
PD: Solve it.
This problem was due to i had installed 'Pinax' and also 'pinax-eventlog', so i uninstalled both and then installing only 'pinax-eventlog'.

eventlog models has changed to support Mysql?

We are finding it difficult to use this in our Mysql-based project because of the reliance in release 3.0.1 because of the reliance on django.contrib.postgres.fields to define the "extra" field.

When will the next release on pypi be?

Call for Maintainers

Looking for maintainers!

There is a lot of pull requests and open issues that the current maintainers, myself included, are just not finding the time to properly get to.

Maybe you've submitted some PRs and are frustrated with the lack of attention. Maybe you use this project in one or more of your projects and want to see that it is properly carried forward.

Whatever you reasons may be, let me know if you have interest and I'll add you to the repo and to PyPI (will need your PyPI name).

Preference will go to those who have commits on this repo and/or have shown an active interest in the issues.

Thanks!
Patrick

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.