This question is following another post I made.
In a specific .py file, I tried the following code :
import logging
logging.basicConfig(filename='example.log', encoding='utf-8', level=logging.WARNING)
logging.debug('This message should not go to the log file')
logging.info('Neither')
logging.warning('This message should go to the log file')
logging.error('And non-ASCII stuff, too, like Øresund and Malmö')
It's working pretty well. : the .log file is created and the data written.
Then,I tried within my code :
print('diag_results>0 for %s'%self.codification_poste)
print('---------------------------------------------------------------------------------------------------------------------------------------')
logging.basicConfig(filename='result_test.log', encoding='utf-8', level=logging.WARNING)
logging.debug('This message should not go to the log file')
logging.info('So not should this')
logging.warning('And this, should')
logging.error('And non-ASCII stuff, too, like Øresund and Malmö')
diag_functions = ["missing_bus_indices(net)",
"disconnected_elements(net)",
"different_voltage_levels_connected(net)",
"impedance_values_close_to_zero(net, min_r_ohm, min_x_ohm, min_r_pu, min_x_pu)",
"nominal_voltages_dont_match(net, nom_voltage_tolerance)",
"invalid_values(net)",
"overload(net, overload_scaling_factor)",
"wrong_switch_configuration(net)",
"multiple_voltage_controlling_elements_per_bus(net)",
"no_ext_grid(net)",
"wrong_reference_system(net)",
"deviation_from_std_type(net)",
"numba_comparison(net, numba_tolerance)",
"parallel_switches(net)"]
overload_scaling_factor = 0.001
min_r_ohm = 0.001
min_x_ohm = 0.001
min_r_pu = 1e-05
min_x_pu = 1e-05
nom_voltage_tolerance = 0.3
numba_tolerance = 1e-05
diag_params = {
"overload_scaling_factor": overload_scaling_factor,
"min_r_ohm": min_r_ohm,
"min_x_ohm": min_x_ohm,
"min_r_pu": min_r_pu,
"min_x_pu": min_x_pu,
"nom_voltage_tolerance": nom_voltage_tolerance,
"numba_tolerance": numba_tolerance
}
compact_report = True
diag_errors = {}
for diag_function in diag_functions:
try:
diag_result = eval(diag_function)
if not diag_result == None:
diag_results[diag_function.split("(")[0]] = diag_result
except Exception as e:
diag_errors[diag_function.split("(")[0]] = e
diag_report = pp.diagnostic_reports.DiagnosticReports(self.net, diag_results, diag_errors, diag_params, compact_report=True)
report_methods = {
"missing_bus_indices": diag_report.report_missing_bus_indices,
"disconnected_elements": diag_report.report_disconnected_elements,
"different_voltage_levels_connected": diag_report.report_different_voltage_levels_connected,
"impedance_values_close_to_zero": diag_report.report_impedance_values_close_to_zero,
"nominal_voltages_dont_match": diag_report.report_nominal_voltages_dont_match,
"invalid_values": diag_report.report_invalid_values,
"overload": diag_report.report_overload,
"multiple_voltage_controlling_elements_per_bus": diag_report.report_multiple_voltage_controlling_elements_per_bus,
"wrong_switch_configuration": diag_report.report_wrong_switch_configuration,
"no_ext_grid": diag_report.report_no_ext_grid,
"wrong_reference_system": diag_report.report_wrong_reference_system,
"deviation_from_std_type": diag_report.report_deviation_from_std_type,
"numba_comparison": diag_report.report_numba_comparison,
"parallel_switches": diag_report.report_parallel_switches
}
# separator between log messages
log_message_sep = ("\n --------\n")
logging.warning("\n\n_____________ PANDAPOWER DIAGNOSTIC TOOL _____________ \n")
for key in report_methods:
if (key in diag_results):
report_methods[key]()
logging.warning(log_message_sep)
logging.warning("_____________ END OF PANDAPOWER DIAGNOSTIC _____________ ")
The .log file is created but nothing is written. Does sb have an idea Why ?
Best regards.
"It looks like your post is mostly code; please add some more details. blablablal kjdklj lksdjlksj dklsjlkslkjdlksjdkljs dkljsdklsjdkljskljdskldj oeiz klaj oi jqs lksqjdklqs. Then, sdlkjfklsdjf. I am wonderring why . lkjqkldsj qsdlkjqskldj qsd "