My main program PGM_A calls API2 and another module Subpgm_1. Subpgm_1 invokes SubAPI_1.
PGM_A
-- Subpgm_1
-- SubAPI_1
-- API2
I would need to write a log file in the following format: {"@timestamp":"09/10/2022 11:42:33 AM","log.level":"INFO","message":"Main : Refresh started!!! "}
I have the following code in my main program PGM_A:
filename = datetime.now().strftime('Logfile_%H%M%d%m%Y.log')
logging.basicConfig(filename=filename,
format='{"@timestamp":"%(asctime)s","log.level":"%(levelname)-1s","message":"%(message)s"}',
datefmt='%m/%d/%Y %H:%M:%S %p')
logger = logging.getLogger('Delta_Refresh_Pipeline')
logger.setLevel(logging.INFO)
handler = logging.StreamHandler()
handler.setLevel(logging.ERROR)
logger.addHandler(handler)
I am able to get the logs from main program. But I would need the log messages from APIs and submodule to be written to same log file Logfile.
In short, my log data should look like:
{"@timestamp":"09/10/2022 11:42:33 AM","log.level":"INFO","message":"Log from PGM_A "}
{"@timestamp":"09/10/2022 11:42:34 AM","log.level":"INFO","message":"Log from Subpgm_1"}
{"@timestamp":"09/10/2022 11:42:35 AM","log.level":"INFO","message":"Log from SubAPI_1"}
{"@timestamp":"09/10/2022 11:42:36 AM","log.level":"INFO","message":"Log from API2"}
{"@timestamp":"09/10/2022 11:42:37 AM","log.level":"INFO","message":"Log from PGM_A "}
Any pointers what modification I have to do in the API code and Subpgm_1? Thanks