Dilshan-H / Oblivion-Inverse

A Simple E-mail Tracker - Made with Flask, Setup under 30 minutes - Track your messages using your own platform!
https://dilshan-h.github.io/Oblivion-Inverse/
MIT License
28 stars 18 forks source link

Configure Logging #16

Closed Dilshan-H closed 1 year ago

Dilshan-H commented 1 year ago

Resources: https://flask.palletsprojects.com/en/2.2.x/logging/

Pablohv91 commented 1 year ago

I would like to help, tell me what is the issue?

Dilshan-H commented 1 year ago

Hi @Pablohv91 Thanks for considering about this issue 🤗

Since logging in Flask is based on the standard Python logging module, you can easily implement this. app.py and routes.py are the files that require logging at the moment. Logging is required on major events within the the processes.

You can find more info from these resources also:

I can assign you to this issue if you would like to work on this. Just let me know.

Pablohv91 commented 1 year ago

Yes please.

Pablohv91 commented 1 year ago

I am confident that I can do the task but I am stuck in testing on your local machine, I get an error when I try to do the exports. Can you explain me furder ?

Thank you

Dilshan-H commented 1 year ago

@Pablohv91, The process mentioned in the Readme was outdated and now I have fixed it. Can you please try all the steps once again? If the issue persists you can share the traceback/error message.

Pablohv91 commented 1 year ago

Hi @Dilshan-H Fixed the error for logging

I think this way you could skip this part:

export FLASK_ENV="development"
export FIREBASE_API_KEY="Your-Firebase-API-Key"
export FIREBASE_DB_URL="Your-Firebase-Database-URL"
export SECRET_KEY="replace-this-text-with-a-suitable-key"

This was the error i was getting and how i fixed it!

Traceback (most recent call last): File "c:/Users/phdel/OneDrive/Escritorio/OpenSource/Oblivion-Inverse/app.py", line 33, in <module> app.config["SECRET_KEY"] = os.environ["SECRET_KEY"] File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\os.py", line 675, in __getitem__ raise KeyError(key) from None KeyError: 'SECRET_KEY' Drive/Escritorio/OpenSource/Oblivion-Inverse/routes.py Traceback (most recent call last): File "c:/Users/phdel/OneDrive/Escritorio/OpenSource/Oblivion-Inverse/routes.py", line 35, in <module> from app import app File "c:\Users\phdel\OneDrive\Escritorio\OpenSource\Oblivion-Inverse\app.py", line 33, in <module> app.config["SECRET_KEY"] = os.environ["SECRET_KEY"] File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\os.py", line 675, in __getitem__ raise KeyError(key) from None KeyError: 'SECRET_KEY'

So i decide to change the line 33 from app.py

app.config["SECRET_KEY"] = os.environ["SECRET_KEY"]

for

app.config["SECRET_KEY"] = os.path.join("credentials.json")

the same for line 216 from routes.py

api_key = os.environ["FIREBASE_API_KEY"]

for

api_key = os.path.join("credentials.json")

Once i change it didn´t give any errors

Dilshan-H commented 1 year ago

@Pablohv91 Since you're on Windows, the export method doesn't work for creating environment variables. Instead you can use following method on your terminal. (I've updated the README also, including that part)

set FLASK_ENV=development
set FIREBASE_API_KEY=Your-Firebase-API-Key
set FIREBASE_DB_URL=Your-Firebase-Database-URL
set SECRET_KEY=replace-this-text-with-a-suitable-key

Importantly, changing the way the environment variables are initialized like you did, will temporarily resolve the error. But the program cannot function as intended without setting the correct environment variable values. os.path.join method is used to join one or more path segments on a filesystem while os.environ is a mapping object where we have used to set/access keys and values. So, the best thing to do now is undo the changes that you've mentioned earlier and follow the new instructions. And I also assume that you have created a new Firebase project and use those credentials as mentioned in the Readme as well.

Pablohv91 commented 1 year ago

Hi @Dilshan-H still having problems with

set SECRE_KEY=replace-this-text-with-a-suitable-key

This is the traceback error

Traceback (most recent call last): File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 194, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "C:\Users\phdel\OneDrive\Escritorio\OpenSource\Oblivion-Inverse\Scripts\flask.exe\__main__.py", line 7, in <module> File "c:\users\phdel\onedrive\escritorio\opensource\oblivion-inverse\lib\site-packages\flask\cli.py", line 985, in main cli.main() File "c:\users\phdel\onedrive\escritorio\opensource\oblivion-inverse\lib\site-packages\flask\cli.py", line 579, in main return super().main(*args, **kwargs) File "c:\users\phdel\onedrive\escritorio\opensource\oblivion-inverse\lib\site-packages\click\core.py", line 1055, in main rv = self.invoke(ctx) File "c:\users\phdel\onedrive\escritorio\opensource\oblivion-inverse\lib\site-packages\click\core.py", line 1657, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "c:\users\phdel\onedrive\escritorio\opensource\oblivion-inverse\lib\site-packages\click\core.py", line 1404, in invoke return ctx.invoke(self.callback, **ctx.params) File "c:\users\phdel\onedrive\escritorio\opensource\oblivion-inverse\lib\site-packages\click\core.py", line 760, in invoke return __callback(*args, **kwargs) File "c:\users\phdel\onedrive\escritorio\opensource\oblivion-inverse\lib\site-packages\click\decorators.py", line 84, in new_func return ctx.invoke(f, obj, *args, **kwargs) File "c:\users\phdel\onedrive\escritorio\opensource\oblivion-inverse\lib\site-packages\click\core.py", line 760, in invoke return __callback(*args, **kwargs) File "c:\users\phdel\onedrive\escritorio\opensource\oblivion-inverse\lib\site-packages\flask\cli.py", line 847, in run_command app = DispatchingApp(info.load_app, use_eager_loading=eager_loading) File "c:\users\phdel\onedrive\escritorio\opensource\oblivion-inverse\lib\site-packages\flask\cli.py", line 299, in __init__ self._load_unlocked() File "c:\users\phdel\onedrive\escritorio\opensource\oblivion-inverse\lib\site-packages\flask\cli.py", line 333, in _load_unlocked self._app = rv = self.loader() File "c:\users\phdel\onedrive\escritorio\opensource\oblivion-inverse\lib\site-packages\flask\cli.py", line 393, in load_app app = locate_app(import_name, None, raise_if_not_found=False) File "c:\users\phdel\onedrive\escritorio\opensource\oblivion-inverse\lib\site-packages\flask\cli.py", line 234, in locate_app __import__(module_name) File "C:\Users\phdel\OneDrive\Escritorio\OpenSource\Oblivion-Inverse\app.py", line 33, in <module> app.config["SECRET_KEY"] = os.environ["SECRET_KEY"] File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\os.py", line 675, in __getitem__ raise KeyError(key) from None KeyError: 'SECRET_KEY'

Dilshan-H commented 1 year ago

On Windows, this approach has to work. Can you please share the error that you receive? so I can understand what's wrong. (and it's SECRET_KEY by the way, not _SECREKEY)

EDIT: Still it seems like there's an error while getting the environment variables. Make sure,

You can make sure whether setting variable was successful using this command: echo %SECRET_KEY%