Merge pull request #25364 from ankush/ipython_logging

fix: Log ipython commands
This commit is contained in:
Ankush Menat 2024-03-12 20:34:15 +05:30 committed by GitHub
commit 676c40a15b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 2 deletions

View file

@ -536,8 +536,7 @@ def log(msg: str) -> None:
:param msg: Message."""
if not request:
if conf.get("logging"):
print(repr(msg))
print(repr(msg))
debug_log.append(as_unicode(msg))

View file

@ -2,6 +2,7 @@ import json
import os
import subprocess
import sys
import typing
import click
@ -14,6 +15,9 @@ from frappe.utils import cint, update_progress_bar
EXTRA_ARGS_CTX = {"ignore_unknown_options": True, "allow_extra_args": True}
if typing.TYPE_CHECKING:
from IPython.terminal.embed import InteractiveShellEmbed
@click.command("build")
@click.option("--app", help="Build assets for app")
@ -584,6 +588,18 @@ def _console_cleanup():
frappe.destroy()
def store_logs(terminal: "InteractiveShellEmbed") -> None:
from contextlib import suppress
frappe.log_level = 20 # info
with suppress(Exception):
logger = frappe.logger("ipython")
logger.info("=== bench console session ===")
for line in terminal.history_manager.get_range():
logger.info(line[2])
logger.info("=== session end ===")
@click.command("console")
@click.option("--autoreload", is_flag=True, help="Reload changes to code automatically")
@pass_context
@ -607,6 +623,7 @@ def console(context, autoreload=False):
all_apps = frappe.get_installed_apps()
failed_to_import = []
register(store_logs, terminal) # Note: atexit runs in reverse order of registration
for app in list(all_apps):
try: