Add a basicConfig logger...
Howdy. What are the odds of including a basicConfig logger for Flask-Scripts? I'm not 100% sure where the right place to add this is, but I think this is as good as it get.
diff --git a/flaskext/script.py b/flaskext/script.py
index 09e054a..7c42a85 100644
--- a/flaskext/script.py
+++ b/flaskext/script.py
@@ -2,6 +2,7 @@
from __future__ import absolute_import
from __future__ import with_statement
+import logging
import os
import sys
import code
@@ -17,6 +18,12 @@ from flask import Flask, _request_ctx_stack
__all__ = ["Command", "Shell", "Server", "Manager", "Option",
"prompt", "prompt_pass", "prompt_bool", "prompt_choices"]
+LOG_FORMAT = (
+ '\n%(levelname)s in %(module)s [%(pathname)s:%(lineno)d]:\n\n' +
+ '\t%(message)s'
+ )
+logging.basicConfig(format=LOG_FORMAT)
+
def prompt(name, default=None):
"""
A logger is probably easier to add in your specific Command, I'd say.
On 22 June 2011 16:28, sean- [email protected] wrote:
Howdy. What are the odds of including a basicConfig logger for Flask-Scripts? I'm not 100% sure where the right place to add this is, but I think this is as good as it get. Will attach patch.
Reply to this email directly or view it on GitHub: https://github.com/danjac/Flask-Script/issues/1
Over the last few months that's what I've done, but I've found that I'm adding a basicConfig() logger to nearly all of my projects now. Submitting this patch was prompted by forgetting to set a logger and having logging output vanish in to thin air until I realized what was going on.
Having logging messages to go stderr seems like a sensible default to me so I kicked something upstream. If a user wants to customize things they can, but at least they're getting something vs. having those bits go to /dev/null by default.
I suppose another option would be to override one of the manager methods and have it there.
I would be a bit weary about it being a standard feature though. OTOH it could use Flask's included logger.
On 22 June 2011 16:36, sean- [email protected] wrote:
Over the last few months that's what I've done, but I've found that I'm adding a basicConfig() logger to nearly all of my projects now. Submitting this patch was prompted by forgetting to set a logger and having logging output vanish in to thin air until I realized what was going on.
Having logging messages to go stderr seems like a sensible default to me so I kicked something upstream. If a user wants to customize things they can, but at least they're getting something vs. having those bits go to /dev/null by default.
Reply to this email directly or view it on GitHub: https://github.com/danjac/Flask-Script/issues/1#issuecomment-1418852
However you see it best. It just strikes me as reasonable to have the default be to send logging messages from scripts to stderr.
I just looked at flask/logger.py and it's just using the built in logger, but it doesn't setup the logger and leaves that up to the app. Since this is a script and not an app, providing a default basicConfig() seems reasonable enough. Nothing gets sent to the logger right now unless something is already logging to the logger, so enabling a basic stderr logger doesn't seem like it would break anything, but it would allow script authors to use app.logger.*() without having to tweak or add anything.
I agree with the idea that it would be nice for flask-script to make it a little easier to enable logging via Server. Has anything changed on this in the last 5 years?