Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to output logging.info and logging.debug to console?

Tags:

python

tornado

I can only see warning and error, how can I get info and debug printed out? To clarify, I am starting the tornado app with python app.py. I want the info and debug logs to print out to the console after I run the app.

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write('hello fun fun test world from tornado super')
        logging.info('info')
        logging.warning('warning')
        logging.error('error')
        logging.debug('debug')


application = tornado.web.Application([(r"/", MainHandler)], debug=True)
like image 842
mergesort Avatar asked Nov 22 '13 17:11

mergesort


People also ask

How do I show log debugging?

To view a debug log, from Setup, enter Debug Logs in the Quick Find box, then select Debug Logs. Then click View next to the debug log that you want to examine. Click Download to download the log as an XML file. Debug logs have the following limits.

How do you display logging information in Python?

Python Logging – INFO Level To log an INFO line using Python Logging, Check if the logger has atleast a logging level of INFO. Use logging.info() method, with the message passed as argument, to print the INFO line to the console or log file.

How do I print logs from console?

You should use the console. log() method to print to console JavaScript. The JavaScript console log function is mainly used for code debugging as it makes the JavaScript print the output to the console. To open the browser console, right-click on the page and select Inspect, and then click Console.

How do I console log in Python?

Use the logging Module to Print the Log Message to Console in Python. To use logging and set up the basic configuration, we use logging. basicConfig() . Then instead of print() , we call logging.


3 Answers

You probably need to change the level of the logging module to allow for debug and info messages to be displayed in the console.

logger.setLevel(logging.DEBUG) # this should allow all messages to be displayed

if you don't want to display debug messages then do this:

logger.setLevel(logging.INFO)

And just a quick fyi. Here are the levels in order, so if you set one of them it will display any messages of the types below the set level and it will NOT any messages above the set level.

logging.DEBUG
logging.INFO
logging.WARNING
logging.ERROR
logging.CRITICAL
like image 50
jramirez Avatar answered Oct 23 '22 22:10

jramirez


By calling tornado.options.parse_command_line you register tornado command line flags.

You can use logging command line flag to change logging level from command line.

For more information: https://stackoverflow.com/a/14269208/63097

like image 33
Andrea Di Persio Avatar answered Oct 23 '22 21:10

Andrea Di Persio


python helloworld.py --logging=debug
  • helloworld.py is tornado offical demo

  • more details about tornado/options.py

like image 20
Mio Avatar answered Oct 23 '22 21:10

Mio