mirror of
https://github.com/LmeSzinc/AzurLaneAutoScript.git
synced 2025-01-05 11:16:44 +08:00
Opt: Remove log output to stdout when using electron
Try to avoid #2051
This commit is contained in:
parent
702297d1c2
commit
81c20a0b5c
14
gui.py
14
gui.py
@ -1,6 +1,7 @@
|
||||
import threading
|
||||
from multiprocessing import Event, Process
|
||||
|
||||
from module.logger import logger
|
||||
from module.webui.setting import State
|
||||
|
||||
|
||||
@ -49,6 +50,19 @@ def func(ev: threading.Event):
|
||||
|
||||
host = args.host or State.deploy_config.WebuiHost or "0.0.0.0"
|
||||
port = args.port or int(State.deploy_config.WebuiPort) or 22267
|
||||
State.electron = args.electron
|
||||
|
||||
logger.hr("Launcher config")
|
||||
logger.attr("Host", host)
|
||||
logger.attr("Port", port)
|
||||
logger.attr("Electron", args.electron)
|
||||
logger.attr("Reload", ev is not None)
|
||||
|
||||
if State.electron:
|
||||
# https://github.com/LmeSzinc/AzurLaneAutoScript/issues/2051
|
||||
logger.info("Electron detected, remove log output to stdout")
|
||||
from module.logger import console_hdlr
|
||||
logger.removeHandler(console_hdlr)
|
||||
|
||||
uvicorn.run("module.webui.app:app", host=host, port=port, factory=True)
|
||||
|
||||
|
@ -3,15 +3,12 @@ from typing import Any, Callable
|
||||
|
||||
from rich.console import Console, ConsoleRenderable
|
||||
from rich.highlighter import RegexHighlighter
|
||||
from rich.logging import RichHandler
|
||||
from rich.theme import Theme
|
||||
|
||||
|
||||
class HTMLConsole(Console): ...
|
||||
|
||||
|
||||
class Highlighter(RegexHighlighter): ...
|
||||
|
||||
|
||||
WEB_THEME: Theme
|
||||
|
||||
logger_debug: bool
|
||||
@ -22,53 +19,54 @@ console_formatter: logging.Formatter
|
||||
web_formatter: logging.Formatter
|
||||
|
||||
stdout_console: Console
|
||||
console_hdlr: RichHandler
|
||||
|
||||
def set_file_logger(
|
||||
name: str = pyw_name,
|
||||
) -> None: ...
|
||||
def set_func_logger(
|
||||
func: Callable[[ConsoleRenderable], None],
|
||||
) -> None: ...
|
||||
|
||||
class __logger(logging.Logger):
|
||||
def rule(
|
||||
self,
|
||||
title: str = "",
|
||||
*,
|
||||
characters: str = "-",
|
||||
style: str = "rule.line",
|
||||
end: str = "\n",
|
||||
align: str = "center",
|
||||
self,
|
||||
title: str = "",
|
||||
*,
|
||||
characters: str = "-",
|
||||
style: str = "rule.line",
|
||||
end: str = "\n",
|
||||
align: str = "center",
|
||||
) -> None: ...
|
||||
|
||||
def hr(
|
||||
self,
|
||||
title,
|
||||
level: int = 3,
|
||||
self,
|
||||
title,
|
||||
level: int = 3,
|
||||
) -> None: ...
|
||||
|
||||
def attr(
|
||||
self,
|
||||
name,
|
||||
text,
|
||||
self,
|
||||
name,
|
||||
text,
|
||||
) -> None: ...
|
||||
|
||||
def attr_align(
|
||||
self,
|
||||
name,
|
||||
text,
|
||||
front = "",
|
||||
align: int = 22,
|
||||
self,
|
||||
name,
|
||||
text,
|
||||
front="",
|
||||
align: int = 22,
|
||||
) -> None: ...
|
||||
|
||||
def set_file_logger(
|
||||
self,
|
||||
name: str = pyw_name,
|
||||
self,
|
||||
name: str = pyw_name,
|
||||
) -> None: ...
|
||||
|
||||
def set_func_logger(
|
||||
func: Callable[[Any], Any],
|
||||
self,
|
||||
func: Callable[[ConsoleRenderable], None],
|
||||
) -> None: ...
|
||||
|
||||
def print(
|
||||
self,
|
||||
*objects: ConsoleRenderable,
|
||||
**kwargs,
|
||||
self,
|
||||
*objects: ConsoleRenderable,
|
||||
**kwargs,
|
||||
) -> None: ...
|
||||
|
||||
|
||||
logger: __logger
|
||||
|
@ -1207,9 +1207,6 @@ def app():
|
||||
action="store_true",
|
||||
help="Use jsdelivr cdn for pywebio static files (css, js). Self host cdn by default.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--electron", action="store_true", help="Runs by electron client."
|
||||
)
|
||||
parser.add_argument(
|
||||
"--run",
|
||||
nargs="+",
|
||||
@ -1223,7 +1220,6 @@ def app():
|
||||
lang.LANG = State.deploy_config.Language
|
||||
key = args.key or State.deploy_config.Password
|
||||
cdn = args.cdn if args.cdn else State.deploy_config.CDN
|
||||
State.electron = args.electron
|
||||
runs = None
|
||||
if args.run:
|
||||
runs = args.run
|
||||
@ -1238,7 +1234,6 @@ def app():
|
||||
logger.attr("Language", lang.LANG)
|
||||
logger.attr("Password", True if key else False)
|
||||
logger.attr("CDN", cdn)
|
||||
logger.attr("Electron", args.electron)
|
||||
|
||||
def index():
|
||||
if key is not None and not login(key):
|
||||
|
@ -1,3 +1,4 @@
|
||||
import argparse
|
||||
import os
|
||||
import queue
|
||||
import threading
|
||||
@ -119,8 +120,20 @@ class ProcessManager:
|
||||
def run_process(
|
||||
config_name, func: str, q: queue.Queue, e: threading.Event = None
|
||||
) -> None:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
"--electron", action="store_true", help="Runs by electron client."
|
||||
)
|
||||
args, _ = parser.parse_known_args()
|
||||
State.electron = args.electron
|
||||
|
||||
# Setup logger
|
||||
set_file_logger(name=config_name)
|
||||
if State.electron:
|
||||
# https://github.com/LmeSzinc/AzurLaneAutoScript/issues/2051
|
||||
logger.info("Electron detected, remove log output to stdout")
|
||||
from module.logger import console_hdlr
|
||||
logger.removeHandler(console_hdlr)
|
||||
set_func_logger(func=q.put)
|
||||
|
||||
from module.config.config import AzurLaneConfig
|
||||
|
Loading…
Reference in New Issue
Block a user