Re: Python Logging and printf()
Hi Chris, Thanks for the comments , Iam planning to use logging handlers ( StreamHandler and FileHandler) to achieve my requirement . Any quick reference example to this will be great , Iam on Python 2.7 , Iam referring the python docs for mow. Regards, Ganesh On Fri, Nov 21, 2014 at 5:25 PM, Chris Angelico ros...@gmail.com wrote: On Fri, Nov 21, 2014 at 9:48 PM, Ganesh Pal ganesh1...@gmail.com wrote: Please provide your input on the below questions. (1). How do i guarantee that all console messages will be logged into the logfile ? (2) I feel the need to retain few print(), how do I ensure the print() messages are also logged into the log file. If you're using Python 3, you can shadow print() with your own function. The logging functions don't have the same signature, so you'd need to write a wrapper (or else stick to a strict policy of one argument to print() and it must be a string), but it's certainly possible. But part of the point of the logging module is that it's not the same as console messages: you can reduce log spam by changing the logging level. So no, you don't have a guarantee that all console messages will be logged to the log file. If you want that, I would suggest a process-level wrapper - something which invokes a subprocess with redirected stdout and/or stderr - or, at very least, a startup routine that does the redirection (which will have similar effect, except that it can't catch startup failure messages from Python itself). ChrisA -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Logging and printf()
On 21 Nov 2014, at 11:48, Ganesh Pal wrote: Hi Team , Iam using the python logging module to log the events for my application into a log file . I have set the logging level to DEBUG as shown below logging.basicConfig(filename=options.log_file, level=logging.DEBUG, format='%(asctime)s %(levelname)s:%(message)s', datefmt='%m/%d/%Y %I:%M:%S %p') iam also using logging.warning(),logging.error(),logging.info() etc as and when required. Please provide your input on the below questions. (1). How do i guarantee that all console messages will be logged into the logfile ? There is no guarantee, it's a software. But all the log messages have to be stored in the logfile (2) I feel the need to retain few print(), how do I ensure the print() messages are also logged into the log file. the print function or print keyword don't use the logging module, you need to use it. Regards, Ganesh -- https://mail.python.org/mailman/listinfo/python-list -- Stéphane Wirtel - http://wirtel.be - @matrixise -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Logging and printf()
On Fri, Nov 21, 2014 at 9:48 PM, Ganesh Pal ganesh1...@gmail.com wrote: Please provide your input on the below questions. (1). How do i guarantee that all console messages will be logged into the logfile ? (2) I feel the need to retain few print(), how do I ensure the print() messages are also logged into the log file. If you're using Python 3, you can shadow print() with your own function. The logging functions don't have the same signature, so you'd need to write a wrapper (or else stick to a strict policy of one argument to print() and it must be a string), but it's certainly possible. But part of the point of the logging module is that it's not the same as console messages: you can reduce log spam by changing the logging level. So no, you don't have a guarantee that all console messages will be logged to the log file. If you want that, I would suggest a process-level wrapper - something which invokes a subprocess with redirected stdout and/or stderr - or, at very least, a startup routine that does the redirection (which will have similar effect, except that it can't catch startup failure messages from Python itself). ChrisA -- https://mail.python.org/mailman/listinfo/python-list