Mailing List Archive

log file
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?

import os
import csv
import logging
import assertion_design as asd
import random

#Create and configure logger
logging.basicConfig(filename="test_1.log", filemode='w', format='%(asctime)s %(message)s')
import os
import csv
import logging
import assertion_design as asd
import random

#Create and configure logger
logging.basicConfig(filename="test_1.log", filemode='w', format='%(asctime)s %(message)s')
--
https://mail.python.org/mailman/listinfo/python-list
Re: log file [ In reply to ]
On 22/03/19 4:25 PM, 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?
>
> import os
> import csv
> import logging
> import assertion_design as asd
> import random
>
> #Create and configure logger
> logging.basicConfig(filename="test_1.log", filemode='w', format='%(asctime)s %(message)s')
> import os
> import csv
> import logging
> import assertion_design as asd
> import random
>
> #Create and configure logger
> logging.basicConfig(filename="test_1.log", filemode='w', format='%(asctime)s %(message)s')
>


Do all of these lines actually appear, or is it an accidental
copy-paste+paste?

What do you use to actually record data in the log? eg

logging.info("Informational message")

Any error message from Python?

When you say "the log file is missing" do you mean that there is no such
file, that there is an empty file, or what? Which directory do you run
the code from, and in which directory do you expect to find the log file?

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list
Re: log file [ In reply to ]
On Thursday, March 21, 2019 at 10:26:14 PM UTC-5, 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.
>
I am thinking--hoping, rather--that you just kind of double pasted there. Anyways, you needed to specify the logging level in basicConfig:

import os
import csv
import logging
import random

#Create and configure logger
# Check out level=logging.INFO
logging.basicConfig(filename="test_1.log", filemode='w', format='%(asctime)s %(message)s', level=logging.INFO)
log = logging.getLogger()
log.info("Yay!")
--
https://mail.python.org/mailman/listinfo/python-list
Re: log file [ In reply to ]
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?
>
> import os
> import csv
> import logging
> import assertion_design as asd
> import random
>
> #Create and configure logger
> logging.basicConfig(filename="test_1.log", filemode='w', format='%(asctime)s %(message)s')
> import os
> import csv
> import logging
> import assertion_design as asd
> import random
>
> #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.
--
https://mail.python.org/mailman/listinfo/python-list
Re: log file [ In reply to ]
On Friday, 22 March 2019 09:09:14 UTC+5:30, DL Neil wrote:
> On 22/03/19 4:25 PM, 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?
> >
> > import os
> > import csv
> > import logging
> > import assertion_design as asd
> > import random
> >
> > #Create and configure logger
> > logging.basicConfig(filename="test_1.log", filemode='w', format='%(asctime)s %(message)s')
> > import os
> > import csv
> > import logging
> > import assertion_design as asd
> > import random
> >
> > #Create and configure logger
> > logging.basicConfig(filename="test_1.log", filemode='w', format='%(asctime)s %(message)s')
> >
>
>
> Do all of these lines actually appear, or is it an accidental
> copy-paste+paste?
>
> What do you use to actually record data in the log? eg
>
> logging.info("Informational message")
>
> Any error message from Python?
>
> When you say "the log file is missing" do you mean that there is no such
> file, that there is an empty file, or what? Which directory do you run
> the code from, and in which directory do you expect to find the log file?
>
> --
> Regards =dn

There is no log file at all in the directory where I am running.
I expected the log file to be in the directory where I am running the test from.

Let me describe it in more detail.
This is the directory - "D:\Users\sharanb\OneDrive - HCL Technologies Ltd\Projects\MyBackup\Projects\Initiatives\machine learning\programs\assertion\CNN"

The test program imports the design and runs some test on it.
Both the design file and test file are in the above directory.
--
https://mail.python.org/mailman/listinfo/python-list
Re: log file [ In reply to ]
On Friday, 22 March 2019 09:09:16 UTC+5:30, adam....@gmail.com wrote:
> On Thursday, March 21, 2019 at 10:26:14 PM UTC-5, 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.
> >
> I am thinking--hoping, rather--that you just kind of double pasted there. Anyways, you needed to specify the logging level in basicConfig:
>
> import os
> import csv
> import logging
> import random
>
> #Create and configure logger
> # Check out level=logging.INFO
> logging.basicConfig(filename="test_1.log", filemode='w', format='%(asctime)s %(message)s', level=logging.INFO)
> log = logging.getLogger()
> log.info("Yay!")

Adam,

I don't understand. The logger is set to DEBUG level using the following line.
logger.setLevel(logging.DEBUG)

Do you see anything incorrect?
--
https://mail.python.org/mailman/listinfo/python-list
Re: log file [ In reply to ]
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?
> >
> > import os
> > import csv
> > import logging
> > import assertion_design as asd
> > import random
> >
> > #Create and configure logger
> > logging.basicConfig(filename="test_1.log", filemode='w', format='%(asctime)s %(message)s')
> > import os
> > import csv
> > import logging
> > import assertion_design as asd
> > import random
> >
> > #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?

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')
--
https://mail.python.org/mailman/listinfo/python-list
Re: log file [ In reply to ]
On 23Mar2019 21:47, Sharan Basappa <sharan.basappa@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 <cs@cskk.id.au>
--
https://mail.python.org/mailman/listinfo/python-list
Re: log file [ In reply to ]
On Sunday, 24 March 2019 10:57:13 UTC+5:30, Cameron Simpson wrote:
> On 23Mar2019 21:47, Sharan Basappa <sharan.basappa@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 <cs@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
Re: log file [ In reply to ]
On 24-3-2019 09:50, Sharan Basappa wrote:
>
> Ah. I finally solved the issue though I don't know what the problem itself it.


The problem, shown with a simple example

Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 22:20:52) [MSC v.1916
32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> print ("hallo")
hallo
>>> print ("h\allo")
hllo
>>> print (r"h\allo")
h\allo
>>>

The first line is a simple print statement to print the text "hallo"  
(which is Dutch for "hello")

In the second line i added a '\' (backslash), the letter 'a' seems to be
missing, unless audio on your computer works. If audio works you will
hear a bell.
(see: https://docs.python.org/2.0/ref/strings.html )

In the third line a 'r' is put in front of the string, and now the 'a'
is shown again (and also the '\').


In your path there is something like '.......programs\assertion\CNN......'.

Python does see a '\a', after 'programs', and before 'ssertion', and
tries to sound a 'bell'....




--
https://mail.python.org/mailman/listinfo/python-list
Re: log file [ In reply to ]
On Sunday, 24 March 2019 14:20:36 UTC+5:30, Sharan Basappa wrote:
> On Sunday, 24 March 2019 10:57:13 UTC+5:30, Cameron Simpson wrote:
> > On 23Mar2019 21:47, Sharan Basappa <sharan.basappa@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 <cs@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

I think I got some more idea about the issue though I still don't know the root cause.
So, my test program is importing design file.
Both test and design file are have the following lines:
#Create and configure logger
filename = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'test_5.log')
logging.basicConfig(filename=filename, filemode='w', format='%(asctime)s %(message)s')
#Creating an object
logger = logging.getLogger()

I think this is causing the issue. Anyway, I am able to log from the test program. However, I am not able to log anything from design program.

I will open a separate thread on this topic.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Log File [ In reply to ]
On 5/31/23 00:22, ahsan iqbal wrote:
> Why we need a log file ? If i read a large text file than how log file help me in this regard?

If you were parsing each line of this text file looking for information,
perhaps some of the lines would not be formatted correctly, and you would be unable
to get the information from those lines. Maybe you would like to
write those bad lines to a log file so that you could analyze them later.



--
https://mail.python.org/mailman/listinfo/python-list
Re: Log File [ In reply to ]
On 2023-05-31 00:22:11 -0700, ahsan iqbal wrote:
> Why we need a log file ?

A log file contains information about what your program was doing. You
use it to check that your program was performing as intended after the
fact. This is especially useful for tracking down problems with programs
which are either long-running or are running unattended.

For example, if a user tells me that they were having a problem
yesterday evening I can read the log file to see what my program was
doing at the time which will help me to pin down the problem.

The important part to remember is that a log file will only contain
information the program writes. If you didn't think to log some
information then it won't be in the log file and you can't look it up
afterwards. On the other hand you don't want to log too much information
because that might cause performance problems, it might fill up your
disks and it will be a chore to find the relevant information in a sea
of irrelevant details. So deciding what to log is a bit of an art.

> If i read a large text file than how log file help me in this regard?

It won't help you with reading the file.

However, you might want to log some information about operation, e.g.
when you started (log files usually contain time stamps), when you
ended, how large the file was, etc. That way you can compare different
runs (has the file increased in size over the last month? Was reading
especially slow yesterday?). You could also log a status message every
once in a while (e.g. every 100 MB or every 100000 lines). That will
give you reassurance that the program is working and a rough estimate
when it will be finished. Or you can log any other information you think
might be useful.

hp

--
_ | Peter J. Holzer | Story must make more sense than reality.
|_|_) | |
| | | hjp@hjp.at | -- Charles Stross, "Creative writing
__/ | http://www.hjp.at/ | challenge!"