Re: FileNotFoundError thrown due to file name in file, rather than file itself

2024-11-14 Thread Ethan Furman via Python-list
On 11/13/24 23:03, Left Right via Python-list wrote: >> On any Unix system this is untrue. Rotating a log file is quite simple: > > I realized I posted this without cc'ing the list: > http://jdebp.info/FGA/do-not-use-logrotate.html . > > The link above gives a more detailed description of why lo

Re: FileNotFoundError thrown due to file name in file, rather than file itself

2024-11-14 Thread Jon Ribbens via Python-list
On 2024-11-14, Michael Torrie wrote: > On 11/14/24 12:03 AM, Left Right wrote: >>> On any Unix system this is untrue. Rotating a log file is quite simple: >> >> I realized I posted this without cc'ing the list: >> http://jdebp.info/FGA/do-not-use-logrotate.html . >> >> The link above gives a mo

Re: FileNotFoundError thrown due to file name in file, rather than file itself

2024-11-14 Thread Michael Torrie via Python-list
On 11/14/24 12:03 AM, Left Right wrote: >> On any Unix system this is untrue. Rotating a log file is quite simple: > > I realized I posted this without cc'ing the list: > http://jdebp.info/FGA/do-not-use-logrotate.html . > > The link above gives a more detailed description of why log rotation >

Re: FileNotFoundError thrown due to file name in file, rather than file itself

2024-11-14 Thread Barry via Python-list
> On 14 Nov 2024, at 14:07, Loris Bennett via Python-list > wrote: > > I don't quite understand what your suggestion is. Do you mean that I > should log to stderr and then run my program as > > my_program ... 2>&1 | logger On almost all Linux distros you would run a long running program a

Re: FileNotFoundError thrown due to file name in file, rather than file itself

2024-11-14 Thread D'Arcy Cain via Python-list
On 11/13/24 02:12, Roel Schroeven via Python-list wrote: What I most often do is use one logfile per day, with the date in the filename. Then simply delete all files older than 7 days, or 30 days, or whatever is useful for the task at hand. Not only does that sidestep any issues with rotating l

Re: FileNotFoundError thrown due to file name in file, rather than file itself

2024-11-14 Thread Loris Bennett via Python-list
Left Right writes: >> I am not entirely convinced by NB2. I am, in fact, a sort of sysadmin >> person and most of my programs write to a log file. The programs are >> also moderately complex, so a single program might access a database, >> query an LDAP server, send email etc., so potentially q

Re: FileNotFoundError thrown due to file name in file, rather than file itself

2024-11-14 Thread Chris Angelico via Python-list
On Thu, 14 Nov 2024 at 18:05, Left Right via Python-list wrote: > > > On any Unix system this is untrue. Rotating a log file is quite simple: > > I realized I posted this without cc'ing the list: > http://jdebp.info/FGA/do-not-use-logrotate.html . > > The link above gives a more detailed descript

Re: FileNotFoundError thrown due to file name in file, rather than file itself

2024-11-13 Thread Left Right via Python-list
> On any Unix system this is untrue. Rotating a log file is quite simple: I realized I posted this without cc'ing the list: http://jdebp.info/FGA/do-not-use-logrotate.html . The link above gives a more detailed description of why log rotation on the Unix system is not only not simple, but is, in

Re: FileNotFoundError thrown due to file name in file, rather than file itself

2024-11-13 Thread Michael Torrie via Python-list
On 11/12/24 12:10 PM, Left Right via Python-list wrote: > But, it's > impossible to reliably rotate a log file. There's always a chance > that during the rotation some log entries will be written to the file > past the point of rotation, but prior to the point where the next logs > volume starts.

Re: FileNotFoundError thrown due to file name in file, rather than file itself

2024-11-13 Thread Kushal Kumaran via Python-list
On Wed, Nov 13 2024 at 07:36:04 PM, dieter.mau...@online.de wrote: > Loris Bennett wrote at 2024-11-12 10:00 +0100: >> ... >>However, it strikes me as not immediately obvious that the logging file >>must exist at this point. I can imagine a situation in which I want to >>configure a default log fi

Re: FileNotFoundError thrown due to file name in file, rather than file itself

2024-11-13 Thread Dieter Maurer via Python-list
Loris Bennett wrote at 2024-11-12 10:00 +0100: > ... >However, it strikes me as not immediately obvious that the logging file >must exist at this point. I can imagine a situation in which I want to >configure a default log file and create it if it missing. This is what happens usually: if you ope

Re: FileNotFoundError thrown due to file name in file, rather than file itself

2024-11-13 Thread Roel Schroeven via Python-list
Op 12/11/2024 om 20:10 schreef Left Right via Python-list: > I am not entirely convinced by NB2. I am, in fact, a sort of sysadmin > person and most of my programs write to a log file. The programs are > also moderately complex, so a single program might access a database, > query an LDAP serve

Re: FileNotFoundError thrown due to file name in file, rather than file itself

2024-11-12 Thread Greg Ewing via Python-list
On 13/11/24 8:10 am, Left Right wrote: since logs are designed to grow indefinitely, the natural response to this design property is log rotation. I don't see how writing logs to stderr solves that problem in any way. Whatever stderr is sent to still has a potentially unlimited amount of data t

Re: FileNotFoundError thrown due to file name in file, rather than file itself

2024-11-12 Thread Rob Cliffe via Python-list
On 12/11/2024 08:52, Loris Bennett via Python-list wrote: Cameron Simpson writes: Generally you should put a try/except around the smallest possible piece of code. That is excellent advice. Best wishes Rob Cliffe So: config = configparser.ConfigParser() try: config.r

Re: FileNotFoundError thrown due to file name in file, rather than file itself

2024-11-12 Thread Chris Angelico via Python-list
On Wed, 13 Nov 2024 at 07:29, Mats Wichmann via Python-list wrote: > > On 11/12/24 12:10, Left Right via Python-list wrote: > > > Finally, if you want your logs to go to a file, and currently, your > > only option is stderr, your shell gives you a really, really simple > > way of redirecting stder

Re: FileNotFoundError thrown due to file name in file, rather than file itself

2024-11-12 Thread Mats Wichmann via Python-list
On 11/12/24 12:10, Left Right via Python-list wrote: Finally, if you want your logs to go to a file, and currently, your only option is stderr, your shell gives you a really, really simple way of redirecting stderr to a file. So, really, there aren't any excuses to do that. an awful lot of th

Re: FileNotFoundError thrown due to file name in file, rather than file itself

2024-11-12 Thread Left Right via Python-list
> I am not entirely convinced by NB2. I am, in fact, a sort of sysadmin > person and most of my programs write to a log file. The programs are > also moderately complex, so a single program might access a database, > query an LDAP server, send email etc., so potentially quite a lot can go > wrong

Re: FileNotFoundError thrown due to file name in file, rather than file itself

2024-11-12 Thread Loris Bennett via Python-list
Left Right writes: > Poor error reporting is a very common problem in programming. Python > is not anything special in this case. Of course, it would've been > better if the error reported what file wasn't found. But, usually > these problems are stacking, like in your code. Unfortunately, it

Re: FileNotFoundError thrown due to file name in file, rather than file itself

2024-11-12 Thread Karsten Hilbert via Python-list
Am Tue, Nov 12, 2024 at 09:52:31AM +0100 schrieb Loris Bennett via Python-list: > Regarding your example above, if 'missingfile.py' contains the following > > import configparser > > config = configparser.ConfigParser() > > try: > config.read('/foo/bar') > except FileNotFoundError as

Re: FileNotFoundError thrown due to file name in file, rather than file itself

2024-11-12 Thread Loris Bennett via Python-list
Chris Angelico writes: > On Tue, 12 Nov 2024 at 01:59, Loris Bennett via Python-list > wrote: >> 2. In terms of generating a helpful error message, how should one >>distinguish between the config file not existing and the log file not >>existing? > > By looking at the exception's attribu

Re: FileNotFoundError thrown due to file name in file, rather than file itself

2024-11-12 Thread Loris Bennett via Python-list
Cameron Simpson writes: > On 11Nov2024 18:24, dieter.mau...@online.de wrote: >>Loris Bennett wrote at 2024-11-11 15:05 +0100: >>>I have the following in my program: >>>try: >>>logging.config.fileConfig(args.config_file) >>>config = configparser.ConfigParser() >>>confi

Re: FileNotFoundError thrown due to file name in file, rather than file itself

2024-11-12 Thread Loris Bennett via Python-list
Chris Angelico writes: > On Tue, 12 Nov 2024 at 01:59, Loris Bennett via Python-list > wrote: >> 2. In terms of generating a helpful error message, how should one >>distinguish between the config file not existing and the log file not >>existing? > > By looking at the exception's attribu

Re: FileNotFoundError thrown due to file name in file, rather than file itself

2024-11-12 Thread Dieter Maurer via Python-list
Cameron Simpson wrote at 2024-11-12 08:17 +1100: >On 11Nov2024 18:24, dieter.mau...@online.de wrote: >>Loris Bennett wrote at 2024-11-11 15:05 +0100: >>>I have the following in my program: >>>try: >>>logging.config.fileConfig(args.config_file) >>>config = configparser.ConfigPar

Re: FileNotFoundError thrown due to file name in file, rather than file itself

2024-11-11 Thread Chris Angelico via Python-list
On Tue, 12 Nov 2024 at 01:59, Loris Bennett via Python-list wrote: > 2. In terms of generating a helpful error message, how should one >distinguish between the config file not existing and the log file not >existing? By looking at the exception's attributes rather than assuming and hard-c

Re: FileNotFoundError thrown due to file name in file, rather than file itself

2024-11-11 Thread dn via Python-list
On 12/11/24 10:17, Cameron Simpson via Python-list wrote: On 11Nov2024 18:24, dieter.mau...@online.de wrote: Loris Bennett wrote at 2024-11-11 15:05 +0100: I have the following in my program:    try:    logging.config.fileConfig(args.config_file)    config = configparser.ConfigParser()

Re: FileNotFoundError thrown due to file name in file, rather than file itself

2024-11-11 Thread Cameron Simpson via Python-list
On 11Nov2024 18:24, dieter.mau...@online.de wrote: Loris Bennett wrote at 2024-11-11 15:05 +0100: I have the following in my program: try: logging.config.fileConfig(args.config_file) config = configparser.ConfigParser() config.read(args.config_file) if args.verbos

Re: FileNotFoundError thrown due to file name in file, rather than file itself

2024-11-11 Thread Dieter Maurer via Python-list
Loris Bennett wrote at 2024-11-11 15:05 +0100: >I have the following in my program: >try: >logging.config.fileConfig(args.config_file) >config = configparser.ConfigParser() >config.read(args.config_file) >if args.verbose: >print(f"Configuration file:

Re: FileNotFoundError thrown due to file name in file, rather than file itself

2024-11-11 Thread Left Right via Python-list
Poor error reporting is a very common problem in programming. Python is not anything special in this case. Of course, it would've been better if the error reported what file wasn't found. But, usually these problems are stacking, like in your code. Unfortunately, it's your duty, as the language

FileNotFoundError thrown due to file name in file, rather than file itself

2024-11-11 Thread Loris Bennett via Python-list
Hi, I have the following in my program: try: logging.config.fileConfig(args.config_file) config = configparser.ConfigParser() config.read(args.config_file) if args.verbose: print(f"Configuration file: {args.config_file}") except FileNotFoundErro