Flask implementation - Pyctuator messes with app logging conf
See original GitHub issueHi,
I’m trying to install Pyctuator on our existing app on Flask/uWSGI.
Everything works fine except that pyctuator is modifying the logging configuration of the application, and some things don’t work as expected after Pyctuator is set up.
Our app is created the following way (redacted to the relevant part only) :
def create_app():
""" Flask application factory """
# create and configure the app
app = Flask(__name__, instance_path=instance_path, instance_relative_config=True)
app.config.from_json('config.json')
# Allow CORS from angers.cnp.fr
CORS(app)
# Add proxyfix middleware to handle redirects correctly
# x_port = 0 to work around Kong sending incorrect X-Forwarded-Port header
app.wsgi_app = ProxyFix(app.wsgi_app, x_host=1, x_port=0)
# configure the DB
# pool_recycle must be set below 3600 to avoid the session to be killed by the firewall
engine = create_engine(app.config["DATABASE_URI"], convert_unicode=True, pool_pre_ping=True, pool_recycle=3500)
# Enable pyctuator
pyctuator = Pyctuator(
app,
"Plateforme IA",
pyctuator_endpoint_url=app.config["ROOT_API_PATH"]+'/actuator',
app_url=None,
registration_url=None
)
pyctuator.set_build_info(
name="Plateforme IA",
version=app.config["VERSION"],
time=dateutil.parser.parse(app.config["BUILD_DATE"]),
)
pyctuator.register_health_provider(DbHealthProvider(engine))
sentinel = Sentinel(app.config["CACHE_REDIS_SENTINELS"], socket_timeout=1.0)
master = sentinel.master_for(app.config["CACHE_REDIS_SENTINEL_MASTER"], socket_timeout=1.0)
pyctuator.register_health_provider(RedisHealthProvider(master))
return app
application = create_app()
- Before setting up Pyctuator, any runtime exception will be logged in uwsgi_error.log and I can use the root logger anywhere in an endpoint code and it gets logged in uwsgi_error.log, such as :
import logging
logging.critical("Test")
- After setting up Pyctuator, nothing is logged in uwsgi_error.log at all.
This is not acceptable for us.
Any idea why we have this behaviour ?
FYI if I comment the line 92 in pyctuator.py, the problem goes away :
root_logger.addHandler(self.pyctuator_impl.logfile.log_messages)
Thanks
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Application logging with Flask - CircleCI
The Flask logging module gives you a way to record errors over different severity levels. A default logging module is included in the...
Read more >Flask logging - Cannot get it to write to a file - Stack Overflow
First, add this logging code to your main: import logging, logging.config, yaml logging.config.dictConfig(yaml.load(open('logging.conf'))).
Read more >pyctuator - PyPI
Pyctuator. Monitor Python web apps using Spring Boot Admin. Pyctuator supports Flask, FastAPI, aiohttp and Tornado. Django support is planned as well.
Read more >Create a Flask Application With Google Login - Real Python
In this article, you'll work through the creation of a Flask web application. Your application will allow a user to log in using...
Read more >Spring Boot Admin Reference Guide - GitHub Pages
Enable pyctuator by pointing it to your Flask app and letting it know ... file log pattern as Spring Boot's default one doesn't...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Looking at your reproducer app: while the
critical
log entires aren’t shown in console, I can see them via the Pycatuator logfile API (/actuator/logfile
in your case).The reason is that the python logging system wasn’t initialized before Pyctuator started. In this case Pyctuator’s logging-handler (the one that’s responsible for intercepting log messages and making them available via the API) is the only handler that is installed…
As you can see in https://docs.python.org/3/library/logging.html#logging.basicConfig:
To fix this, you should initialize the logging system before starting Pyctuator by calling any of:
logging.info("some message")
logging.basicConfig(level=logging.INFO)
(we’ve used the latter in flask_example_app)Regardless, I will change Pyctuator so it will initialize the logging system if not yet initialized which will solve this issue.
Ok, this makes perfect sense.
I upgraded to v0.13 and I confirm that the behaviour is fixed in the reproducer app, and also in my real application.
Thanks for your actions 😃