3

in my python project i have several lines that are logging with debug level and other with info level. Now, when i run my code i can set at the begging the log level to info or debug level and that will log to a file and on the screen only the info or both info/debug messages accordingly.

How can i achieve to set to log to file always debug level but on screen always info level?

Example (only a small part):

loggername = 'Main.Case.' self.logger = logging.getLogger(loggername) self.logger.info('case() - Started') self.logger.debug('System ready...') self.logger.debug('File ready...') self.logger.debug('Memory ready...') self.logger.info('case() - Ready') 

This would print with info level only (on screen and log file):

Main.Case.case() - Started Main.Case.case() - Ready 

With debug level i will get (on screen and log file):

Main.Case.case() - Started Main.Case.System ready... Main.Case.File ready... Main.Case.Memory ready... Main.Case.case() - Ready 

I actually would like to have on screen always only the info level lines and in the log file info/debug level!

When i activate debug level then i will get everything to both out puts (screen/file).

Any one any idea??

Thanks in adv.

4
  • RTM. The python logging docs show you how to create stream and file handlers. use setLevel to set the logger to DEBUG and the handlers to INFO or DEBUG. Besides the docs, there are lots of examples. Commented Apr 20, 2015 at 17:19
  • possible duplicate of Printing to screen and writing to a file at the same time Commented Apr 20, 2015 at 17:20
  • See this possible duplicate: stackoverflow.com/questions/6652727/… Commented Apr 20, 2015 at 17:22
  • Thanks, next time i will search more! Commented Apr 20, 2015 at 20:16

1 Answer 1

1

How to do this exact thing is documented in the logging cookbook in the Python docs.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.