On Sunday, 24 March 2019 10:57:13 UTC+5:30, Cameron Simpson wrote: > On 23Mar2019 21:47, Sharan Basappa <sharan.basa...@gmail.com> wrote: > >On Friday, 22 March 2019 09:13:18 UTC+5:30, MRAB wrote: > >> On 2019-03-22 03:25, Sharan Basappa wrote: > >> > I am running a program and even though the program runs all fine, the > >> > log file is missing. I have pasted first few lines of the code. > >> > Any suggestions where I maybe going wrong? > [...] > >> > #Create and configure logger > >> > logging.basicConfig(filename="test_1.log", filemode='w', > >> > format='%(asctime)s %(message)s') > >> > > >> Are you sure that you know where it's putting the log file? You have a > >> relative path there, but relative to where? Try it with an absolute path. > >> > >> Are you sure that it's logging anything? Log a simple message just after > >> configuring to double-check. > > > >Would the file not get logged using the current directory? > > It should be. > > >BTW, I changed the file location as follows and still I don't see it: > > > >logging.basicConfig(filename="D:\Users\sharanb\OneDrive - HCL > >Technologies Ltd\Projects\MyBackup\Projects\Initiatives\machine > >learning\programs\assertion\CNN\test_1.log", filemode='w', > >format='%(asctime)s %(message)s') > > Did you read my other recent post? You should define strings with > backslashes in them such are your file path as 'raw strings', which > start with r' or r" instead of a plain quote character. Raw strings do > not interpret \x escapes. In particular your path above has a '\a' in > it, which is not a backslash followed by an "a", it is a BEL character. > > That said, I can't see what's wrong with your original example which has > no backslashes. > > Cheers, > Cameron Simpson <c...@cskk.id.au>
Ah. I finally solved the issue though I don't know what the problem itself it. This is how the new code looks like: for handler in logging.root.handlers[:]: logging.root.removeHandler(handler) #Create and configure logger filename = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'test_1.log') logging.basicConfig(filename=filename, filemode='w', format='%(asctime)s %(message)s') I found the above tip from the following discussion: https://stackoverflow.com/questions/30861524/logging-basicconfig-not-creating-log-file-when-i-run-in-pycharm -- https://mail.python.org/mailman/listinfo/python-list