vishalanandl177 / DRF-API-Logger

An API Logger for your Django Rest Framework project.
https://github.com/vishalanandl177/DRF-API-Logger
Apache License 2.0
308 stars 56 forks source link

Log into another database is not working #36

Closed jatindergit closed 2 years ago

jatindergit commented 2 years ago

I have added the settings for different db for logs DRF_API_LOGGER_DEFAULT_DATABASE = 'logs'

DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': os.environ.get('DATABASE_NAME'), 'USER': os.environ.get('DATABASE_USER'), 'PASSWORD': os.environ.get('DATABASE_PASSWORD'), 'HOST': os.environ.get('DATABASE_HOST', 'localhost'), 'PORT': os.environ.get('DATABASE_PORT', 5432), }, 'logs': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': os.environ.get('LOGS_DATABASE_NAME'), 'USER': os.environ.get('LOGS_DATABASE_USER'), 'PASSWORD': os.environ.get('LOGS_DATABASE_PASSWORD'), 'HOST': os.environ.get('LOGS_DATABASE_HOST', 'localhost'), 'PORT': os.environ.get('LOGS_DATABASE_PORT', 5432), } }

But it shows error in django admin ProgrammingError at /manage-console/drf_api_logger/apilogsmodel/

relation "drf_api_logs" does not exist LINE 1: SELECT COUNT(*) AS "__count" FROM "drf_api_logs" WHERE ("drf...

vishalanandl177 commented 2 years ago

Looks like you forgot to migrate "logs" DB.

jatindergit commented 2 years ago

I migrate it using ./manage.py migrate drf_api_logger --database=logs and even insertion is working but error in django admin only

vishalanandl177 commented 2 years ago

Soon I'll fix and release a new version. Thanks for informing this issue.

jatindergit commented 2 years ago

Thanks I will be waiting

On Fri, 21 Jan 2022 at 2:06 PM, Vishal Anand @.***> wrote:

Soon I'll fix and release a new version. Thanks for informing this issue.

— Reply to this email directly, view it on GitHub https://github.com/vishalanandl177/DRF-API-Logger/issues/36#issuecomment-1018292914, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADSZDP3OLGCTZ2SAY4VY3X3UXELI5ANCNFSM5MOZPYIA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

-- Jatinder Singh (Senior Software Eng.) Mobile: +91 7696312994 Email: @.***

vishalanandl177 commented 2 years ago

Hi @jatindergit , I have tested the package with more than 10 databases and routing but it worked fine.

I used Postman to test the API. If you are using browsable API then it is not going to log into the DB because of the content-type.

jatindergit commented 2 years ago

@vishalanandl177 I think you forgot to add .using('logs') in your admin.py L#111 https://docs.djangoproject.com/en/4.0/topics/db/multi-db/#exposing-multiple-databases-in-django-s-admin-interface def get_queryset(self, request): return super(APILogsAdmin, self).get_queryset(request)

it should be def get_queryset(self, request): return super(APILogsAdmin, self).get_queryset(request).using('logs')

jatindergit commented 2 years ago

I locally changed this in my environment and it worked

vishalanandl177 commented 2 years ago

Thanks @jatindergit

I already improved this. In the next version, I'll deploy the changes as well.

vishalanandl177 commented 2 years ago

These changes will be part of the next release version 1.1.10.

jatindergit commented 2 years ago

@vishalanandl177 When you are going to release version 1.1.10 ?

vishalanandl177 commented 2 years ago

Tonight.

vishalanandl177 commented 2 years ago

Version 1.1.10 released.