included stream logger. switched from default file logger to stream

This commit is contained in:
Peter Yefi 2023-04-17 17:59:34 -04:00
parent 73c8839814
commit 99b6860694
13 changed files with 65 additions and 24 deletions

View File

@ -1,16 +1,33 @@
import logging as logger
from pathlib import Path
import os
import logging
import sys
def get_logger(file_logger=False):
"""
Returns a logging object
:param file_logger: a boolean to indicate the kind of logging
object to return, true (default) means a file logger is required
:return:
"""
log_format = "%(asctime)s:%(levelname)s:{%(pathname)s:%(funcName)s:%(lineno)d} - %(message)s"
if file_logger:
log_dir = (Path(__file__).parent.parent / 'logs').resolve()
log_file = (log_dir / 'hub.log').resolve()
try:
if not os.path.isfile(log_file):
if not os.path.exists(log_dir):
os.mkdir(log_dir)
with open(log_file, 'x'):
pass
logger.basicConfig(filename=log_file, format=log_format, level=logger.DEBUG)
return logger
except IOError as err:
print(f'I/O exception: {err}')
else:
logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))
logging.getLogger().setLevel(logging.DEBUG)
return logger.getLogger()
log_dir = (Path(__file__).parent.parent / 'logs').resolve()
log_file = (log_dir / 'hub.log').resolve()
try:
if not os.path.isfile(log_file):
if not os.path.exists(log_dir):
os.mkdir(log_dir)
with open(log_file, 'x'):
pass
logger.basicConfig(filename=log_file, format="%(asctime)s:%(levelname)s:{%(pathname)s:%(funcName)s:%(lineno)d} "
"- %(message)s", level=logger.DEBUG)
except IOError as err:
print(f'I/O exception: {err}')

View File

@ -7,7 +7,7 @@ Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
import datetime
import math
import sys
from hub.hub_logger import logger
from hub.hub_logger import get_logger
import hub.helpers.constants as cte
from hub.catalog_factories.construction_catalog_factory import ConstructionCatalogFactory
@ -17,6 +17,8 @@ from hub.helpers.dictionaries import Dictionaries
from hub.imports.construction.helpers.construction_helper import ConstructionHelper
from hub.imports.construction.helpers.storeys_generation import StoreysGeneration
logger = get_logger()
class NrcanPhysicsParameters:
"""

View File

@ -7,7 +7,7 @@ Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concord
"""
import sys
from hub.hub_logger import logger
from hub.hub_logger import get_logger
from hub.catalog_factories.construction_catalog_factory import ConstructionCatalogFactory
from hub.city_model_structure.building_demand.layer import Layer
from hub.city_model_structure.building_demand.material import Material
@ -15,6 +15,8 @@ from hub.helpers.dictionaries import Dictionaries
from hub.imports.construction.helpers.construction_helper import ConstructionHelper
from hub.imports.construction.helpers.storeys_generation import StoreysGeneration
logger = get_logger()
class NrelPhysicsParameters:
"""

View File

@ -7,11 +7,13 @@ Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concord
"""
from pathlib import Path
from hub.hub_logger import logger
from hub.hub_logger import get_logger
from hub.helpers.utils import validate_import_export_type
from hub.imports.construction.nrel_physics_parameters import NrelPhysicsParameters
from hub.imports.construction.nrcan_physics_parameters import NrcanPhysicsParameters
logger = get_logger()
class ConstructionFactory:
"""

View File

@ -9,7 +9,9 @@ from pathlib import Path
from hub.imports.energy_systems.air_source_hp_parameters import AirSourceHeatPumpParameters
from hub.imports.energy_systems.water_to_water_hp_parameters import WaterToWaterHPParameters
from hub.helpers.utils import validate_import_export_type
from hub.hub_logger import logger
from hub.hub_logger import get_logger
logger = get_logger()
class EnergySystemsFactory:

View File

@ -13,7 +13,9 @@ from hub.imports.geometry.rhino import Rhino
from hub.imports.geometry.gpandas import GPandas
from hub.imports.geometry.geojson import Geojson
from hub.helpers.utils import validate_import_export_type
from hub.hub_logger import logger
from hub.hub_logger import get_logger
logger = get_logger()
class GeometryFactory:

View File

@ -11,7 +11,9 @@ from hub.imports.life_cycle_assessment.lca_vehicle import LcaVehicle
from hub.imports.life_cycle_assessment.lca_machine import LcaMachine
from hub.imports.life_cycle_assessment.lca_material import LcaMaterial
from hub.helpers.utils import validate_import_export_type
from hub.hub_logger import logger
from hub.hub_logger import get_logger
logger = get_logger()
class LifeCycleAssessment:

View File

@ -8,11 +8,13 @@ Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concord
from pathlib import Path
from hub.helpers.utils import validate_import_export_type
from hub.hub_logger import logger
from hub.hub_logger import get_logger
from hub.imports.results.simplified_radiosity_algorithm import SimplifiedRadiosityAlgorithm
from hub.imports.results.insel_monthly_energry_balance import InselMonthlyEnergyBalance
from hub.imports.results.insel_heatpump_energy_demand import InselHeatPumpEnergyDemand
logger = get_logger()
class ResultFactory:
"""

View File

@ -6,9 +6,11 @@ Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
"""
from pathlib import Path
from hub.hub_logger import logger
from hub.hub_logger import get_logger
from hub.helpers.utils import validate_import_export_type
logger = get_logger()
class SensorsFactory:
"""

View File

@ -8,7 +8,7 @@ import copy
import sys
import numpy
from hub.hub_logger import logger
from hub.hub_logger import get_logger
import hub.helpers.constants as cte
from hub.helpers.dictionaries import Dictionaries
from hub.city_model_structure.building_demand.usage import Usage
@ -21,6 +21,8 @@ from hub.city_model_structure.attributes.schedule import Schedule
from hub.city_model_structure.building_demand.internal_gain import InternalGain
from hub.catalog_factories.usage_catalog_factory import UsageCatalogFactory
logger = get_logger()
class ComnetUsageParameters:
"""

View File

@ -7,7 +7,7 @@ Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
import sys
from hub.hub_logger import logger
from hub.hub_logger import get_logger
import hub.helpers.constants as cte
from hub.helpers.dictionaries import Dictionaries
from hub.city_model_structure.building_demand.usage import Usage
@ -18,6 +18,8 @@ from hub.city_model_structure.building_demand.thermal_control import ThermalCont
from hub.city_model_structure.building_demand.domestic_hot_water import DomesticHotWater
from hub.catalog_factories.usage_catalog_factory import UsageCatalogFactory
logger = get_logger()
class NrcanUsageParameters:
"""

View File

@ -9,9 +9,11 @@ Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concord
from pathlib import Path
from hub.imports.usage.comnet_usage_parameters import ComnetUsageParameters
from hub.imports.usage.nrcan_usage_parameters import NrcanUsageParameters
from hub.hub_logger import logger
from hub.hub_logger import get_logger
from hub.helpers.utils import validate_import_export_type
logger = get_logger()
class UsageFactory:
"""

View File

@ -7,9 +7,11 @@ Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
from pathlib import Path
from hub.imports.weather.xls_weather_parameters import XlsWeatherParameters
from hub.imports.weather.epw_weather_parameters import EpwWeatherParameters
from hub.hub_logger import logger
from hub.hub_logger import get_logger
from hub.helpers.utils import validate_import_export_type
logger = get_logger()
class WeatherFactory:
"""