Skip to content

Commit

Permalink
Minimize Console Window on Startup
Browse files Browse the repository at this point in the history
Merge pull request #377 from EtalumaSupport/dovydas_dev
  • Loading branch information
dovydasv2 authored Jul 10, 2024
2 parents 2b992b6 + b7670c6 commit 8c71a71
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lvp_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import logging
from logging.handlers import RotatingFileHandler
import os
import sys
import ctypes

os.makedirs("logs/LVP_Log", exist_ok=True)

Expand All @@ -59,6 +61,19 @@ def format(self, record):
# # if INFO level, only log the message
# return record.getMessage()
return logging.Formatter.format(self, record)

def minimize_logger_window():
if sys.platform == "win32":
try:
console_window = ctypes.windll.kernel32.GetConsoleWindow()
if console_window:
# Setting the found console window to a minimized state (state 6)
ctypes.windll.user32.ShowWindow(console_window, 6)
logger.info("[Logger ] Console window minimized")
else:
logger.warning("[Logger ] Console window not found.")
except Exception as e:
logger.error(f"[Logger ] Failed to minimize console window: {e}")

# ensures logger is specific to the file importing lvp_logger
logger = logging.getLogger(__name__)
Expand All @@ -83,3 +98,4 @@ def format(self, record):
# file_handler = logging.FileHandler(LOG_FILE)
file_handler.setFormatter(CustomFormatter())
logger.addHandler(file_handler)
minimize_logger_window()

0 comments on commit 8c71a71

Please sign in to comment.