Skip to content

Commit

Permalink
fix: Log ipython commands
Browse files Browse the repository at this point in the history
  • Loading branch information
ankush committed Mar 12, 2024
1 parent ee03bf7 commit 8bdc88f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions frappe/commands/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import subprocess
import sys
import typing

import click

Expand All @@ -14,6 +15,9 @@

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")
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit 8bdc88f

Please sign in to comment.