Click here to Skip to main content
15,443,982 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a flask server running in background i.e. created a .service file and initiated the flask application. Now, when I fire flask APIs from launcher file, I am unable to see logger messages on console.

I am doing this to add verbosity option to my launcher for example if user gives "launcher.py -v", it should print INFO, ERROR, WARN and DEBUG messages.

I am new to python and went through documentation as well, couldn't figure out a way. Can someone suggest the right way to do this ?

Note: If I launch the application normally, I can see output on console as I have added StreamHandler(sys.out) to logger.

What I have tried:

I wrote below code to get the output to console, which is not the efficient way

#log_file is populated by flask logging i.e. fileHandler

pro = subprocess.Popen(["tail", "-n0", "-f", log_file])    

#this is to terminate the process once launcher file exits

os.killpg(os.getpgid(pro.pid), signal.SIGTERM)
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900