mirror of
https://github.com/LmeSzinc/AzurLaneAutoScript.git
synced 2025-01-07 08:26:55 +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
|
import threading
|
||||||
from multiprocessing import Event, Process
|
from multiprocessing import Event, Process
|
||||||
|
|
||||||
|
from module.logger import logger
|
||||||
from module.webui.setting import State
|
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"
|
host = args.host or State.deploy_config.WebuiHost or "0.0.0.0"
|
||||||
port = args.port or int(State.deploy_config.WebuiPort) or 22267
|
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)
|
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.console import Console, ConsoleRenderable
|
||||||
from rich.highlighter import RegexHighlighter
|
from rich.highlighter import RegexHighlighter
|
||||||
|
from rich.logging import RichHandler
|
||||||
from rich.theme import Theme
|
from rich.theme import Theme
|
||||||
|
|
||||||
|
|
||||||
class HTMLConsole(Console): ...
|
class HTMLConsole(Console): ...
|
||||||
|
|
||||||
|
|
||||||
class Highlighter(RegexHighlighter): ...
|
class Highlighter(RegexHighlighter): ...
|
||||||
|
|
||||||
|
|
||||||
WEB_THEME: Theme
|
WEB_THEME: Theme
|
||||||
|
|
||||||
logger_debug: bool
|
logger_debug: bool
|
||||||
@ -22,53 +19,54 @@ console_formatter: logging.Formatter
|
|||||||
web_formatter: logging.Formatter
|
web_formatter: logging.Formatter
|
||||||
|
|
||||||
stdout_console: Console
|
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):
|
class __logger(logging.Logger):
|
||||||
def rule(
|
def rule(
|
||||||
self,
|
self,
|
||||||
title: str = "",
|
title: str = "",
|
||||||
*,
|
*,
|
||||||
characters: str = "-",
|
characters: str = "-",
|
||||||
style: str = "rule.line",
|
style: str = "rule.line",
|
||||||
end: str = "\n",
|
end: str = "\n",
|
||||||
align: str = "center",
|
align: str = "center",
|
||||||
) -> None: ...
|
) -> None: ...
|
||||||
|
|
||||||
def hr(
|
def hr(
|
||||||
self,
|
self,
|
||||||
title,
|
title,
|
||||||
level: int = 3,
|
level: int = 3,
|
||||||
) -> None: ...
|
) -> None: ...
|
||||||
|
|
||||||
def attr(
|
def attr(
|
||||||
self,
|
self,
|
||||||
name,
|
name,
|
||||||
text,
|
text,
|
||||||
) -> None: ...
|
) -> None: ...
|
||||||
|
|
||||||
def attr_align(
|
def attr_align(
|
||||||
self,
|
self,
|
||||||
name,
|
name,
|
||||||
text,
|
text,
|
||||||
front = "",
|
front="",
|
||||||
align: int = 22,
|
align: int = 22,
|
||||||
) -> None: ...
|
) -> None: ...
|
||||||
|
|
||||||
def set_file_logger(
|
def set_file_logger(
|
||||||
self,
|
self,
|
||||||
name: str = pyw_name,
|
name: str = pyw_name,
|
||||||
) -> None: ...
|
) -> None: ...
|
||||||
|
|
||||||
def set_func_logger(
|
def set_func_logger(
|
||||||
func: Callable[[Any], Any],
|
self,
|
||||||
|
func: Callable[[ConsoleRenderable], None],
|
||||||
) -> None: ...
|
) -> None: ...
|
||||||
|
|
||||||
def print(
|
def print(
|
||||||
self,
|
self,
|
||||||
*objects: ConsoleRenderable,
|
*objects: ConsoleRenderable,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
) -> None: ...
|
) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
logger: __logger
|
logger: __logger
|
||||||
|
@ -1207,9 +1207,6 @@ def app():
|
|||||||
action="store_true",
|
action="store_true",
|
||||||
help="Use jsdelivr cdn for pywebio static files (css, js). Self host cdn by default.",
|
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(
|
parser.add_argument(
|
||||||
"--run",
|
"--run",
|
||||||
nargs="+",
|
nargs="+",
|
||||||
@ -1223,7 +1220,6 @@ def app():
|
|||||||
lang.LANG = State.deploy_config.Language
|
lang.LANG = State.deploy_config.Language
|
||||||
key = args.key or State.deploy_config.Password
|
key = args.key or State.deploy_config.Password
|
||||||
cdn = args.cdn if args.cdn else State.deploy_config.CDN
|
cdn = args.cdn if args.cdn else State.deploy_config.CDN
|
||||||
State.electron = args.electron
|
|
||||||
runs = None
|
runs = None
|
||||||
if args.run:
|
if args.run:
|
||||||
runs = args.run
|
runs = args.run
|
||||||
@ -1238,7 +1234,6 @@ def app():
|
|||||||
logger.attr("Language", lang.LANG)
|
logger.attr("Language", lang.LANG)
|
||||||
logger.attr("Password", True if key else False)
|
logger.attr("Password", True if key else False)
|
||||||
logger.attr("CDN", cdn)
|
logger.attr("CDN", cdn)
|
||||||
logger.attr("Electron", args.electron)
|
|
||||||
|
|
||||||
def index():
|
def index():
|
||||||
if key is not None and not login(key):
|
if key is not None and not login(key):
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import argparse
|
||||||
import os
|
import os
|
||||||
import queue
|
import queue
|
||||||
import threading
|
import threading
|
||||||
@ -119,8 +120,20 @@ class ProcessManager:
|
|||||||
def run_process(
|
def run_process(
|
||||||
config_name, func: str, q: queue.Queue, e: threading.Event = None
|
config_name, func: str, q: queue.Queue, e: threading.Event = None
|
||||||
) -> 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
|
# Setup logger
|
||||||
set_file_logger(name=config_name)
|
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)
|
set_func_logger(func=q.put)
|
||||||
|
|
||||||
from module.config.config import AzurLaneConfig
|
from module.config.config import AzurLaneConfig
|
||||||
|
Loading…
Reference in New Issue
Block a user