Create a logging decorator (@logit) that stores logging information in a PostgreSQL table. The logging table contains information about the method called, and the user who called the method.
Have an active PostgreSQL server running locally.
- Create an .env file in the projects' root folder containing the following database-related variables:
HOST | PORT | DB_NAME | USER | PASSWORD |
-
Create a .venv folder in the projects' root folder, create a virtual environment by running the command
$ virtualenv .venv
and install the psycopg2 package. -
Access to a local PostgreSQL server using
$ psql -U postgres
. -
Run the database_script.sql using
$ \i path\database_script.sql
once connected to the local server. -
Activate the virtual environment using
$ source .venv/bin/activate
. -
Run the main.py script.
-
Deactivate the virtual environment using
$ deactivate
.
References |
---|
Python virtual environments |
Python decorators |
Psycopg 2.9.5 documentation |