Skip to main content

django-activity-log

Forked from : scailer/django-user-activity-log


Owner's Expressions :

This django app intended for writing HTTP log to database and/or watch last user activity.

Features:

  • DB router for writing logs to another database.
  • Filters for ignoring some queries by URL, HTTP methods and response codes.
  • Saving anonymous activity as fake user.
  • Autocreation log DB (for postgresql)

Install:

[deprecated]:

$ pip install django-user-activity-log

[new library]:

pip install django-activity-log 

settings.py:

INSTALLED_APPS = (
    ...
    'activity_log',
)

MIDDLEWARE_CLASSES = (
    ...
    'activity_log.middleware.ActivityLogMiddleware',
)

# For writing log to another DB

DATABASE_ROUTERS = ['activity_log.router.DatabaseAppsRouter']
DATABASE_APPS_MAPPING = {'activity_log': 'logs'}

# If you set up DATABASE_APPS_MAPPING, but don't set related value in
# DATABASES, it will created automatically using "default" DB settings
# as example.
DATABASES = {
    'logs': {
        ...
    },
}

# Create DB automatically (for postgres, and may be mysql).
# We create log database automatically using raw SQL in pre_migrate signal.
# You must insure, that DB user has permissions for creation databases. 
# Tested only for postgresql
ACTIVITYLOG_AUTOCREATE_DB = False

# App settings

# Log anonimus actions?
ACTIVITYLOG_ANONIMOUS = True

# Update last activity datetime in user profile. Needs updates for user model.
ACTIVITYLOG_LAST_ACTIVITY = True

# Only this methods will be logged
ACTIVITYLOG_METHODS = ('POST', 'GET')

# List of response statuses, which logged. By default - all logged.
# Don't use with ACTIVITYLOG_EXCLUDE_STATUSES
ACTIVITYLOG_STATUSES = (200, )

# List of response statuses, which ignores. Don't use with ACTIVITYLOG_STATUSES
# ACTIVITYLOG_EXCLUDE_STATUSES = (302, )

# URL substrings, which ignores
ACTIVITYLOG_EXCLUDE_URLS = ('/admin/activity_log/activitylog', )

account/models.py:

from django.contrib.auth.models import AbstractUser
from activity_log.models import UserMixin

# Only for LAST_ACTIVITY = True
class User(AbstractUser, UserMixin):
    pass

$ python manage.py migrate & python manage.py migrate --database=logs

If you use ACTIVITYLOG_AUTOCREATE_DB migrations to logs database will be run automatically.


Changelogs of this fork :

1. ACTIVITYLOG_MAIN_IP_KEY_VALUE:

You can set this string in the settings.py file. When you have a specific CDN or there are changes in headers of requests from the user on the frontend side, this key value takes the highest priority to set the IP address from the headers.

2. ACTIVITYLOG_MAXIMUM_RECORD_SIZE:

You can set this integer in the settings.py file. This constraint controls the number of saved records by removing the oldest records.

3. EXCLUDE_IP_LIST:

You can set this list in the settings.py file. This is a list of IP addresses that you do not want to log.

4. IP_ADDRESS_HEADERS:

I changed the priority to find the IP address better. When you have a CDN, the previous library saves the IP address of the CDN, which is not useful.

5. headers:

There is a new field in the changelog model that saves headers of requests from the user as a pretty string.

6. payload:

There is a new field in the changelog model that saves the payload of requests from the user as a pretty string.

7. Test on django version 4.0.1:

It works well with Django version 4.0.1.

8. change migration files:

Delete old migrations and create one file to migrate models of this library.

9. IP Management:

In admin panel , Model BlackListIPAdress you can archive or block every ip address would you like with its network address or not.

Repository : HosseinSayyedMousavi/django-user-activity-log

Metadata

Release files for django-activity-log 2.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-activity-log 2.0.3
File Size Uploaded
django_activity_log-2.0.3.tar.gz 9.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-activity-log 2.0.3
File Interpreter ABI Platform
django_activity_log-2.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 19.7 kB

Release files / django_activity_log-2.0.3.tar.gz

Download URL django_activity_log-2.0.3.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
3d9c211432f23d403126877a2d22dc1171cf9cd54e9b80ad56992f98cfb398e7
BLAKE2b-256 checksum
How to use checksums
0e269f872475927eb447055e3107ddd07a2bc0283c4732ddd847405d940b9bab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release files / django_activity_log-2.0.3-py3-none-any.whl

Download URL django_activity_log-2.0.3-py3-none-any.whl
Size 10.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fd8c3709e15b41cd2c073d5bc04dd6c1dcc4a245ab1a33530cdacf6d4462d7ed
BLAKE2b-256 checksum
How to use checksums
05e31ae9b7374f8a1d4952b411f5bc9e276c81cb7872d03bf25d367206d5cac1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release history Release notifications | RSS feed

This release

2.0.3 This release

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

1 release file

1.0.1

1 release file

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page