diff options
| author | Martin Bielik <mx.bielik@gmail.com> | 2023-04-11 17:30:16 +0200 |
|---|---|---|
| committer | Martin Bielik <mx.bielik@gmail.com> | 2023-04-11 17:30:16 +0200 |
| commit | 2d644e05545be6cd699eb5e834d6ba4468f12b41 (patch) | |
| tree | 0e74bccadde6e2e8555cfcccf90af3357083df94 /py/utils.py | |
| parent | 8c97b5cfde56540c8e6619c8d56dc7056d49866f (diff) | |
| download | vim-ai-2d644e05545be6cd699eb5e834d6ba4468f12b41.tar.gz | |
added debug logging
Diffstat (limited to '')
| -rw-r--r-- | py/utils.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/py/utils.py b/py/utils.py index 2291a26..5e560b3 100644 --- a/py/utils.py +++ b/py/utils.py @@ -1,6 +1,10 @@ +import datetime import sys import os +is_debugging = vim.bindeval("g:vim_ai_debug") == 1 +debug_log_file = vim.bindeval("g:vim_ai_debug_log_file") + def load_api_key(): config_file_path = os.path.join(os.path.expanduser("~"), ".config/openai.token") api_key = os.getenv("OPENAI_API_KEY") @@ -56,3 +60,9 @@ def parse_chat_messages(chat_content): def vim_break_undo_sequence(): # breaks undo sequence (https://vi.stackexchange.com/a/29087) vim.command("let &ul=&ul") + +def printDebug(text, *args): + if not is_debugging: + return + with open(debug_log_file, "a") as file: + file.write(f"[{datetime.datetime.now()}] " + text.format(*args) + "\n") |