.log Unterstützung
This commit is contained in:
parent
55881ee988
commit
428cc30429
1 changed files with 69 additions and 22 deletions
|
|
@ -8,7 +8,30 @@ import os
|
|||
import sys
|
||||
import random
|
||||
import shutil
|
||||
import logging
|
||||
from logging.handlers import RotatingFileHandler
|
||||
|
||||
|
||||
def setup_logging(app_dir, level=logging.INFO, console=True):
|
||||
log_file = app_dir / "Simbriefimport.log"
|
||||
|
||||
logger = logging.getLogger()
|
||||
logger.setLevel(level)
|
||||
logger.handlers.clear()
|
||||
|
||||
fmt = logging.Formatter("%(asctime)s %(levelname)s %(name)s: %(message)s")
|
||||
|
||||
# Datei: rotierend, damit sie nicht unendlich wächst
|
||||
fh = RotatingFileHandler(log_file, maxBytes=2_000_000, backupCount=5, encoding="utf-8")
|
||||
fh.setFormatter(fmt)
|
||||
logger.addHandler(fh)
|
||||
|
||||
if console:
|
||||
ch = logging.StreamHandler()
|
||||
ch.setFormatter(fmt)
|
||||
logger.addHandler(ch)
|
||||
|
||||
logging.info("Logging gestartet: %s", log_file)
|
||||
def conf():
|
||||
appname = os.path.basename(sys.argv[0])
|
||||
appname = appname.replace(".py", ".conf")
|
||||
|
|
@ -314,6 +337,7 @@ def BACKUP(Pfad):
|
|||
print(f"Backup erstellt. {len(txt_files)} Datei(en) gesichert.")
|
||||
return None
|
||||
|
||||
|
||||
host = os.getcwd()
|
||||
Pfad = os.getcwd() + '/Announcements/'
|
||||
_airports_cache = None
|
||||
|
|
@ -322,6 +346,7 @@ _airlines_cache = None
|
|||
|
||||
|
||||
app_dir = get_app_dir()
|
||||
setup_logging(app_dir, level=logging.INFO, console=True)
|
||||
conf_file = app_dir / "Simbriefimport.conf"
|
||||
|
||||
if conf_file.exists():
|
||||
|
|
@ -345,31 +370,51 @@ Stimmung = str(stimmung())
|
|||
aircraft_name, aircraft_icao, land_time, start_time, block, time, aircraft, dest_icao, dest_name, dest, origin_icao,
|
||||
origin_name, origin, general, airline_icao, route) = Simbriefimport()
|
||||
|
||||
print('')
|
||||
print("Airline:", general.get("icao_airline"))
|
||||
print("Airlinename:", airline)
|
||||
print("Flugnummer:", general.get("flight_number"))
|
||||
print("Abflug ICAO:", origin.get("icao_code"))
|
||||
print("von:", origin_name)
|
||||
print("Ziel ICAO:", dest.get("icao_code"))
|
||||
print("nach:", dest_name)
|
||||
print("Geplante Blockzeit:", block)
|
||||
print("geplanter Start:", start_time,"UTC")
|
||||
print("geplante Landung:", land_time, "UTC")
|
||||
print("Fluggerät:", aircraft_icao, aircraft_name)
|
||||
print("Cruiselevel:", fl)
|
||||
print("Entfernung:", distance, 'nm')
|
||||
print("Fuel:", fuel, 'kg')
|
||||
print("Passagiere:", pax)
|
||||
print("ZFW:", zfw, 'kg')
|
||||
print("TOW:", tow, 'kg')
|
||||
print("Wetter:", origin.get("icao_code"), metar_origin)
|
||||
print("Wetter:", dest["icao_code"], metar_dest)
|
||||
logging.info("--------------------------------------------------")
|
||||
logging.info("FLUGINFORMATIONEN")
|
||||
logging.info("--------------------------------------------------")
|
||||
logging.info("Airline (ICAO): %s", general.get("icao_airline"))
|
||||
logging.info("Airlinename: %s", airline)
|
||||
logging.info("Flugnummer: %s", general.get("flight_number"))
|
||||
|
||||
logging.info("Abflug ICAO: %s", origin.get("icao_code"))
|
||||
logging.info("Abflugort: %s", origin_name)
|
||||
|
||||
logging.info("Ziel ICAO: %s", dest.get("icao_code"))
|
||||
logging.info("Zielort: %s", dest_name)
|
||||
|
||||
logging.info("Geplante Blockzeit: %s", block)
|
||||
logging.info("Geplanter Start: %s UTC", start_time)
|
||||
logging.info("Geplante Landung: %s UTC", land_time)
|
||||
|
||||
logging.info("Fluggerät: %s (%s)", aircraft_icao, aircraft_name)
|
||||
logging.info("Cruiselevel: FL%s", fl)
|
||||
logging.info("Entfernung: %s nm", distance)
|
||||
|
||||
logging.info("Fuel: %s kg", fuel)
|
||||
logging.info("Passagiere: %s", pax)
|
||||
logging.info("ZFW: %s kg", zfw)
|
||||
logging.info("TOW: %s kg", tow)
|
||||
|
||||
logging.info(
|
||||
"Wetter Abflug %s: %s",
|
||||
origin.get("icao_code"),
|
||||
metar_origin
|
||||
)
|
||||
|
||||
logging.info(
|
||||
"Wetter Ziel %s: %s",
|
||||
dest.get("icao_code"),
|
||||
metar_dest
|
||||
)
|
||||
|
||||
logging.info("--------------------------------------------------")
|
||||
|
||||
|
||||
Pfad_wd = Pfad + airline_icao + '/'
|
||||
|
||||
ordnerneu = Path(Pfad_wd + '/neu/')
|
||||
print(Pfad_wd)
|
||||
logging.info(Pfad_wd)
|
||||
BACKUP(Pfad_wd)
|
||||
#print(replaceFiles())
|
||||
|
||||
|
|
@ -418,4 +463,6 @@ Pfad = Pfad_wd + 'CruiseElapsed80Percent.txt'
|
|||
txtSave(Pfad, InhaltCruise80)
|
||||
|
||||
Pfad = Pfad_wd + 'SafetyBriefing.txt'
|
||||
txtSave(Pfad, Safety)
|
||||
txtSave(Pfad, Safety)
|
||||
|
||||
logging.info('fertsch')
|
||||
Loading…
Add table
Add a link
Reference in a new issue