[Tutor] Where does logging put its files?
Peter Otten
__peter__ at web.de
Thu Apr 24 18:08:45 CEST 2014
Alan Gauld wrote:
> I've been playing with the logging module - long overdue!
>
> I started with the basic tutorial but fell at the first hurdle.
> It says to specify a file in the logging.basicConfig() function then
> asks you to open the file after logging some events.
>
> But I can't find the file anywhere...
>
> Here's my code:
>
> >>> import logging
> >>> logging.basicConfig(file='./log.txt', level=logging.DEBUG)
> >>> logging.info('some stuff')
> INFO:root:some stuff
> >>> logging.error('Somethings burning')
> ERROR:root:Somethings burning
> >>> logging.critical('I warned you!')
> CRITICAL:root:I warned you!
> >>>
>
> But if I exit Python there is no file called log.txt
> that I can find either in the current folder or in my
> home folder. The tutorial seems to suggest it
> should be obvious...
The printed logging messages might give a hint that you were not successful
in your attempt to specify a log-file. Try "filename" instead of "file":
$ ls
log.txt
$ python3
Python 3.3.2+ (default, Feb 28 2014, 00:52:16)
[GCC 4.8.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>> logging.basicConfig(filename="./log.txt", level=logging.DEBUG)
>>> logging.info("There you are")
>>>
$ cat log.txt
INFO:root:There you are
More information about the Tutor
mailing list