-1
logging.basicConfig(level=logging.INFO,filename=r"path\Logs.txt",format='%(asctime)s %(message)s',filemode='a')

Its printing in the console instead of writing to a file.

I am expecting it to be written to a log file.

Mayank Porwal
  • 33,470
  • 8
  • 37
  • 58
Kishore Kumar
  • 47
  • 1
  • 6
  • 1
    Does this answer your question? [How to write to a file, using the logging Python module?](https://stackoverflow.com/questions/6386698/how-to-write-to-a-file-using-the-logging-python-module) – Gabio Apr 10 '20 at 06:56
  • `basicConfig` only works if no logging has been configured already. Is there any logging configured before this call? – blues Apr 10 '20 at 07:54

1 Answers1

0

If you are trying to write debug log after setting log level to info, it will not be written. Try writing info and warning logs. As below:

logging.info("Info Log")
logging.warn("Warning Log")
logging.debug("Debug Log")   #It will not be written in your log file
Sushanta Das
  • 131
  • 1
  • Hi @sushanta Das. Even after changing its written in the console instead of writing it to a file – Kishore Kumar Apr 10 '20 at 07:50
  • logger = logging.getLogger(**__name__**) logger.propagate = False #Add this part in your code before writing the log message to file, this might solve #Are you importing any python module in your code apart from logging – Sushanta Das Apr 10 '20 at 08:09
  • It didnt work i tried everything its printing in the console and its not wiriting into the log file – Kishore Kumar Apr 10 '20 at 09:46