.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 sys
|
||||||
import random
|
import random
|
||||||
import shutil
|
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():
|
def conf():
|
||||||
appname = os.path.basename(sys.argv[0])
|
appname = os.path.basename(sys.argv[0])
|
||||||
appname = appname.replace(".py", ".conf")
|
appname = appname.replace(".py", ".conf")
|
||||||
|
|
@ -314,6 +337,7 @@ def BACKUP(Pfad):
|
||||||
print(f"Backup erstellt. {len(txt_files)} Datei(en) gesichert.")
|
print(f"Backup erstellt. {len(txt_files)} Datei(en) gesichert.")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
host = os.getcwd()
|
host = os.getcwd()
|
||||||
Pfad = os.getcwd() + '/Announcements/'
|
Pfad = os.getcwd() + '/Announcements/'
|
||||||
_airports_cache = None
|
_airports_cache = None
|
||||||
|
|
@ -322,6 +346,7 @@ _airlines_cache = None
|
||||||
|
|
||||||
|
|
||||||
app_dir = get_app_dir()
|
app_dir = get_app_dir()
|
||||||
|
setup_logging(app_dir, level=logging.INFO, console=True)
|
||||||
conf_file = app_dir / "Simbriefimport.conf"
|
conf_file = app_dir / "Simbriefimport.conf"
|
||||||
|
|
||||||
if conf_file.exists():
|
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,
|
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()
|
origin_name, origin, general, airline_icao, route) = Simbriefimport()
|
||||||
|
|
||||||
print('')
|
logging.info("--------------------------------------------------")
|
||||||
print("Airline:", general.get("icao_airline"))
|
logging.info("FLUGINFORMATIONEN")
|
||||||
print("Airlinename:", airline)
|
logging.info("--------------------------------------------------")
|
||||||
print("Flugnummer:", general.get("flight_number"))
|
logging.info("Airline (ICAO): %s", general.get("icao_airline"))
|
||||||
print("Abflug ICAO:", origin.get("icao_code"))
|
logging.info("Airlinename: %s", airline)
|
||||||
print("von:", origin_name)
|
logging.info("Flugnummer: %s", general.get("flight_number"))
|
||||||
print("Ziel ICAO:", dest.get("icao_code"))
|
|
||||||
print("nach:", dest_name)
|
logging.info("Abflug ICAO: %s", origin.get("icao_code"))
|
||||||
print("Geplante Blockzeit:", block)
|
logging.info("Abflugort: %s", origin_name)
|
||||||
print("geplanter Start:", start_time,"UTC")
|
|
||||||
print("geplante Landung:", land_time, "UTC")
|
logging.info("Ziel ICAO: %s", dest.get("icao_code"))
|
||||||
print("Fluggerät:", aircraft_icao, aircraft_name)
|
logging.info("Zielort: %s", dest_name)
|
||||||
print("Cruiselevel:", fl)
|
|
||||||
print("Entfernung:", distance, 'nm')
|
logging.info("Geplante Blockzeit: %s", block)
|
||||||
print("Fuel:", fuel, 'kg')
|
logging.info("Geplanter Start: %s UTC", start_time)
|
||||||
print("Passagiere:", pax)
|
logging.info("Geplante Landung: %s UTC", land_time)
|
||||||
print("ZFW:", zfw, 'kg')
|
|
||||||
print("TOW:", tow, 'kg')
|
logging.info("Fluggerät: %s (%s)", aircraft_icao, aircraft_name)
|
||||||
print("Wetter:", origin.get("icao_code"), metar_origin)
|
logging.info("Cruiselevel: FL%s", fl)
|
||||||
print("Wetter:", dest["icao_code"], metar_dest)
|
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 + '/'
|
Pfad_wd = Pfad + airline_icao + '/'
|
||||||
|
|
||||||
ordnerneu = Path(Pfad_wd + '/neu/')
|
ordnerneu = Path(Pfad_wd + '/neu/')
|
||||||
print(Pfad_wd)
|
logging.info(Pfad_wd)
|
||||||
BACKUP(Pfad_wd)
|
BACKUP(Pfad_wd)
|
||||||
#print(replaceFiles())
|
#print(replaceFiles())
|
||||||
|
|
||||||
|
|
@ -418,4 +463,6 @@ Pfad = Pfad_wd + 'CruiseElapsed80Percent.txt'
|
||||||
txtSave(Pfad, InhaltCruise80)
|
txtSave(Pfad, InhaltCruise80)
|
||||||
|
|
||||||
Pfad = Pfad_wd + 'SafetyBriefing.txt'
|
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