Re: Logging into single file from multiple modules in python when TimedRotatingFileHandler is used

2022-06-22 Thread Lars Liedtke


--
Lars Liedtke
Software Entwickler


Phone:  
Fax:+49 721 98993-
E-mail: [email protected]


solute GmbH
Zeppelinstraße 15   
76185 Karlsruhe
Germany


Marken der solute GmbH | brands of solute GmbH
billiger.de | Shopping.de 



Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten
Webseite | www.solute.de
Sitz | Registered Office: Karlsruhe
Registergericht | Register Court: Amtsgericht Mannheim
Registernummer | Register No.: HRB 110579
USt-ID | VAT ID: DE234663798


Informationen zum Datenschutz | Information about privacy policy
http://solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php

Am 21.06.22 um 11:04 schrieb Chethan Kumar S:

I have a main process which makes use of different other modules. And these 
modules also use other modules. I need to log all the logs into single log 
file. Due to use of TimedRotatingFileHandler, my log behaves differently after 
midnight. I got to know why it is so but couldn't get how I can solve it.
Issue was because of serialization in logging when multiple processes are 
involved.


Could be unrelated and only a part of a solution, but if you are on a 
unixoid system, you could use logrotate, instead of 
TimedRotatingFileHandler. logfrotate ensures that the logging service 
does not realize, its logs have been rotated. So it can log as if 
nothing has happened.


I don't know, if that helps with your multiple processes, or is a 
solution at all.


Cheers

Lars


--
https://mail.python.org/mailman/listinfo/python-list


Re: Logging into single file from multiple modules in python when TimedRotatingFileHandler is used

2022-06-22 Thread Barry Scott



> On 22 Jun 2022, at 11:06, Lars Liedtke  wrote:
> 
> Could be unrelated and only a part of a solution, but if you are on a unixoid 
> system, you could use logrotate, instead of TimedRotatingFileHandler. 
> logfrotate ensures that the logging service does not realize, its logs have 
> been rotated. So it can log as if nothing has happened.


The process that is writing the file must be told that rotation has happened 
for it to work.
Other wise all the logs keep being write to the original file via the FD that 
the process has.

logrotate's config include how to tell the process the log file needs reopening.

Barry


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Logging into single file from multiple modules in python when TimedRotatingFileHandler is used

2022-06-22 Thread Lars Liedtke


The process that is writing the file must be told that rotation has 
happened for it to work.
Other wise all the logs keep being write to the original file via the 
FD that the process has.


logrotate's config include how to tell the process the log file needs 
reopening.



Thanks for clearing.

--
Lars Liedtke
Software Entwickler


Phone:  
Fax:+49 721 98993-
E-mail: [email protected]


solute GmbH
Zeppelinstraße 15   
76185 Karlsruhe
Germany


Marken der solute GmbH | brands of solute GmbH
billiger.de | Shopping.de 



Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten
Webseite | www.solute.de
Sitz | Registered Office: Karlsruhe
Registergericht | Register Court: Amtsgericht Mannheim
Registernummer | Register No.: HRB 110579
USt-ID | VAT ID: DE234663798


Informationen zum Datenschutz | Information about privacy policy
http://solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php


--
https://mail.python.org/mailman/listinfo/python-list


Re: Subtract n months from datetime [Why?]

2022-06-22 Thread Paulo da Silva

Às 05:29 de 21/06/22, Paulo da Silva escreveu:

As a general response to some comments ...

Suppose we need to delete records from a database older than ...
Today, it's usual to specify days. For example you have to keep some gov 
papers for 90 days. This seems to come from computers era. In our minds, 
however, we immediately think 90 days=3 months.
For example, one may want to delete some files older than 9 months. It's 
far more intuitive than 270 days.
When we talk about years it is still going. For example I need to keep 
my receipts for 5 years because IRS audits.
Accepting this, it's intuitive, for example, that 3 months before July, 
31 is April, 30.

The same happens for the years. 5 years before February, 29 is February, 28.

Again, this is my opinion and that's the way I like it :-)
Regards
Paulo
--
https://mail.python.org/mailman/listinfo/python-list


Re: Subtract n months from datetime [Why?]

2022-06-22 Thread MRAB

On 2022-06-22 17:59, Paulo da Silva wrote:

Às 05:29 de 21/06/22, Paulo da Silva escreveu:

As a general response to some comments ...

Suppose we need to delete records from a database older than ...
Today, it's usual to specify days. For example you have to keep some gov
papers for 90 days. This seems to come from computers era. In our minds,
however, we immediately think 90 days=3 months.
For example, one may want to delete some files older than 9 months. It's
far more intuitive than 270 days.
When we talk about years it is still going. For example I need to keep
my receipts for 5 years because IRS audits.
Accepting this, it's intuitive, for example, that 3 months before July,
31 is April, 30.
The same happens for the years. 5 years before February, 29 is February, 28.

Again, this is my opinion and that's the way I like it :-)


What makes sense depends on where you're looking from.

It's 28 February, you need to keep it for 5 years, therefore you could 
reason that you can dispose of it on 28 February, 5 years hence.


However, that happens to be a leap year.

Should you still have it on 29 February?
--
https://mail.python.org/mailman/listinfo/python-list


Re: Logging into single file from multiple modules in python when TimedRotatingFileHandler is used

2022-06-22 Thread Dieter Maurer
Chethan Kumar S wrote at 2022-6-21 02:04 -0700:
> ...
>I have a main process which makes use of different other modules. And these 
>modules also use other modules. I need to log all the logs into single log 
>file. Due to use of TimedRotatingFileHandler, my log behaves differently after 
>midnight. I got to know why it is so but couldn't get how I can solve it.
>Issue was because of serialization in logging when multiple processes are 
>involved.
>
>Below is log_config.py which is used by all other modules to get the logger 
>and log.
>import logging
>import sys
>from logging.handlers import TimedRotatingFileHandler
>
>FORMATTER = logging.Formatter("%(asctime)s — %(name)s — %(message)s")

The usual logging usage pattern is:
the individual components decide what to log
but how the logging happens it decided centrally - common
for all components.
This implies that usually the individual components do not handle
handlers or formatters but use the configuration set up centrally.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Subtract n months from datetime

2022-06-22 Thread Marco Sulla
The package arrow has a simple shift method for months, weeks etc

https://arrow.readthedocs.io/en/latest/#replace-shift
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Subtract n months from datetime [Why?]

2022-06-22 Thread Barry Scott


> On 22 Jun 2022, at 17:59, Paulo da Silva 
>  wrote:
> 
> Às 05:29 de 21/06/22, Paulo da Silva escreveu:
> 
> As a general response to some comments ...
> 
> Suppose we need to delete records from a database older than ...
> Today, it's usual to specify days. For example you have to keep some gov 
> papers for 90 days. This seems to come from computers era. In our minds, 
> however, we immediately think 90 days=3 months.
> For example, one may want to delete some files older than 9 months. It's far 
> more intuitive than 270 days.
> When we talk about years it is still going. For example I need to keep my 
> receipts for 5 years because IRS audits.
> Accepting this, it's intuitive, for example, that 3 months before July, 31 is 
> April, 30.
> The same happens for the years. 5 years before February, 29 is February, 28.

The advantage of 30 days, 90 days etc is that a contract or law does not need 
to tell you
how to deal with the problems of calendar months.

As you say in peoples thoughts that 1 month or 3 months etc. But an accounts 
department
will know how to to the number of days till they have to pay up.

Barry


> 
> Again, this is my opinion and that's the way I like it :-)
> Regards
> Paulo
> -- 
> https://mail.python.org/mailman/listinfo/python-list

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Subtract n months from datetime [Why?]

2022-06-22 Thread MRAB

On 2022-06-22 20:25, Barry Scott wrote:




On 22 Jun 2022, at 17:59, Paulo da Silva  
wrote:

Às 05:29 de 21/06/22, Paulo da Silva escreveu:

As a general response to some comments ...

Suppose we need to delete records from a database older than ...
Today, it's usual to specify days. For example you have to keep some gov papers 
for 90 days. This seems to come from computers era. In our minds, however, we 
immediately think 90 days=3 months.
For example, one may want to delete some files older than 9 months. It's far 
more intuitive than 270 days.
When we talk about years it is still going. For example I need to keep my 
receipts for 5 years because IRS audits.
Accepting this, it's intuitive, for example, that 3 months before July, 31 is 
April, 30.
The same happens for the years. 5 years before February, 29 is February, 28.


The advantage of 30 days, 90 days etc is that a contract or law does not need 
to tell you
how to deal with the problems of calendar months.

As you say in peoples thoughts that 1 month or 3 months etc. But an accounts 
department
will know how to to the number of days till they have to pay up.

OT, but in the UK, when the Gregorian Calendar was adopted, there were 
complaints.


It's often believed that they were just being superstitious about 
"losing" 11 days, but the truth is that they were complaining that rent 
was paid by the month, but wages by the number of days worked.


That month was a lot shorter, with far fewer working days, yet they were 
still expected to pay the same rent!

--
https://mail.python.org/mailman/listinfo/python-list


Re: Subtract n months from datetime [Why?]

2022-06-22 Thread Paulo da Silva

Às 20:25 de 22/06/22, Barry Scott escreveu:




On 22 Jun 2022, at 17:59, Paulo da Silva  
wrote:

Às 05:29 de 21/06/22, Paulo da Silva escreveu:

As a general response to some comments ...

Suppose we need to delete records from a database older than ...
Today, it's usual to specify days. For example you have to keep some gov papers 
for 90 days. This seems to come from computers era. In our minds, however, we 
immediately think 90 days=3 months.
For example, one may want to delete some files older than 9 months. It's far 
more intuitive than 270 days.
When we talk about years it is still going. For example I need to keep my 
receipts for 5 years because IRS audits.
Accepting this, it's intuitive, for example, that 3 months before July, 31 is 
April, 30.
The same happens for the years. 5 years before February, 29 is February, 28.


The advantage of 30 days, 90 days etc is that a contract or law does not need 
to tell you
how to deal with the problems of calendar months.

As you say in peoples thoughts that 1 month or 3 months etc. But an accounts 
department
will know how to to the number of days till they have to pay up.

Yes. But my point is to justify why I want months. And it depends on the 
application.
Let's suppose a program for Joe User to clean something - files, for 
example. There are no rules except for the comfort of the user. He would 
prefer to be able to say 9 months back instead of 270 days. And by 9 
months, he expects to count down 9 months. Not 270 days.

That's what happens with the script I am writing.

Paulo
--
https://mail.python.org/mailman/listinfo/python-list


Re: Subtract n months from datetime

2022-06-22 Thread Paulo da Silva

Às 19:47 de 22/06/22, Marco Sulla escreveu:

The package arrow has a simple shift method for months, weeks etc

https://arrow.readthedocs.io/en/latest/#replace-shift


At first look it seems pretty good! I didn't know it.
Thank you Marco.

Paulo
--
https://mail.python.org/mailman/listinfo/python-list


Aw: Re: Subtract n months from datetime [Why?]

2022-06-22 Thread Karsten Hilbert
> What makes sense depends on where you're looking from.
>
> It's 28 February, you need to keep it for 5 years, therefore you could
> reason that you can dispose of it on 28 February, 5 years hence.
>
> However, that happens to be a leap year.
>
> Should you still have it on 29 February?

Nope because that's *after* the 5 years (they end Feb 28).

If it originates on March 1st, however, you shouldn't dispose of it on Feb 29th 
just yet.

Karsten
-- 
https://mail.python.org/mailman/listinfo/python-list