How to display log info level in the flask?

Hello, I want to when certain events in the vyuha generate logs of INFO level to the console, use Flask.
Tried in create_app() to do so:
# app/__init__.py

import logging

def create_app():
 app = Flask(__name__)
app.logger.setLevel(logging.INFO)
....
 return app

and so
# app/__init__.py

import logging

def create_app():
....
 logger = logging.getLogger("app.module_one")
logger.setLevel(logging.ERROR)
....
 return app

In that get info from werkzeug, my is not there
INFO:werkzeug:127.0.0.1 - - [13/Dec/2017 00:26:15] "GET /index/ HTTP/1.1" 200 -

My only work if directly in the view to indicate
# app/module_one/controllers.py

@module.route('/index/')
def index():
....
logging.- basicConfig(level=logging.INFO)
 logging.info('My message')
 ....


Is it possible it has something to do for the whole module?
June 10th 19 at 15:39
1 answer
June 10th 19 at 15:41
Solution
I like this logarou and Rotorua

# config.py
class Config(object):
 TESTING = False
 # And configs are different

class ProductionConfig(Config):
 DEBUG = False
 LOGFILE = 'logs/Production.log'


class DevelopmentConfig(Config):
 DEBUG = True
 LOGFILE = 'logs/Development.log'


# app.py
from logging.handlers import RotatingFileHandler
from logging import Formatter
import logging

app = Flask(__name__)

app.config.from_object('config.DevelopmentConfig')

# -----------------------------------------------------------------------------
# Enable, disable, and log rotation.
# -----------------------------------------------------------------------------

handler = RotatingFileHandler(app.config['LOGFILE'],
 maxBytes=1000000, backupCount=1)
handler.setLevel(logging.DEBUG)
handler.setFormatter(Formatter('%(asctime)s %(levelname)s: %(message)s '
 '[in %(pathname)s:%(lineno)d]'))
# logging.disable(logging.CRITICAL) # Rascomstar it to end of logs
app.logger.addHandler(handler)


And a short hello, if you need to throw a log in the console:
from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello_world():
 app.logger.info("My message")
 return 'Hello, World!'


if __name__ == "__main__":
 app.run(debug=True)
thanks for the example, but it is in the file and in the console I wonder how) - lucio commented on June 10th 19 at 15:44
, where I updated the response in the console at the level of helloword works. - Carroll_Cass commented on June 10th 19 at 15:47
thank you very much, the principle is understood))) - lucio commented on June 10th 19 at 15:50
and why in this video writes the second log?

def register_logger(app):
 """Register application logger."""
 import os, os.path
 if not os.path.exists("logs/"):
os.makedirs("logs/")

 # main logger

 handler = RotatingFileHandler('logs/main.log', maxBytes=10000, backupCount=1)
handler.setLevel(logging.INFO)
handler.setFormatter(
 logging.Formatter("[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s")
)
app.logger.addHandler(handler)

 # module_a logger

 handler = RotatingFileHandler('logs/module_1.log', maxBytes=10000, backupCount=1)
handler.setLevel(logging.INFO)
handler.setFormatter(
 logging.Formatter("[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s")
)
logging.getLogger('appdata.module_a').addHandler(handler)

 logging.getLogger('appdata.module_a').info('test') # do not write here!
- ralph.Pagac commented on June 10th 19 at 15:53
and I don't know, I've never done that and don't really understand why such a clever scheme :) - Carroll_Cass commented on June 10th 19 at 15:56
and how to write token module?

Here is
INFO:werkzeug:127.0.0.1 - - [13/Dec/2017 00:26:15] "GET /index/ HTTP/1.1" 200 -

Instead werkzeug fit module_a?

If the file is big and it will fall all in a row, I need how to granot him to see only what you need. - ralph.Pagac commented on June 10th 19 at 15:59
clear. Something like this:
https://stackoverflow.com/questions/29325259/call-...

Well, even a reference.

I just think that's how. While the site is developed, all perfectly visible in the console.
And when he came out in production, there are not so many rows in the Production.log falls, and the way is, that you can understand which module something is broken. - Carroll_Cass commented on June 10th 19 at 16:02
thank you, what you need. - ralph.Pagac commented on June 10th 19 at 16:05

Find more questions by tags FlaskLoggingPython