[issue43344] RotatingFileHandler breaks file type associations

2021-07-29 Thread Vinay Sajip


Vinay Sajip  added the comment:

> Could you please share best practices, looks like this documentation is 
> missing.

I don't think so, because the implementation of the namer is up to the user.

Note that this specific issue relates to RotatingFileHandler, not 
TimedRotatingFileHandler. I will take a look at the other issue you raised.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43344] RotatingFileHandler breaks file type associations

2021-07-28 Thread Alexander Smirnov


Alexander Smirnov  added the comment:

the namer was implemented to add "*.log" extension, to avoid broken file 
association problem.

```
log_handler.namer = lambda name: name.replace(".log", "") + ".log"
```

>implemented carefully enough
Could you please share best practices, looks like this documentation is missing.

I created a separate issue related to disregarding of backupCount configuration 
- https://bugs.python.org/issue44753

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43344] RotatingFileHandler breaks file type associations

2021-07-28 Thread Vinay Sajip


Vinay Sajip  added the comment:

> the problem with namer solution is that it will stop respecting backupCount 
> parameter

Not necessarily, as far as I can tell. Can you give a specific rationale for 
your statement - how does that happen, if the namer has been implemented 
carefully enough?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43344] RotatingFileHandler breaks file type associations

2021-07-27 Thread Alexander Smirnov


Alexander Smirnov  added the comment:

the problem with namer solution is that it will stop respecting backupCount 
parameter

--
nosy: +alexander.smirnoff

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43344] RotatingFileHandler breaks file type associations

2021-03-03 Thread Vinay Sajip


Change by Vinay Sajip :


--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43344] RotatingFileHandler breaks file type associations

2021-03-02 Thread Kevin Hollingshead


Kevin Hollingshead  added the comment:

Thanks Vinay, I was able to do this with:

def namer(name):
return name.replace(".log", "") + ".log"

Then when initializing the logger:

handler.namer = namer

My full initializer script:

import os
import logging
from logging.handlers import TimedRotatingFileHandler
from config import constants

def namer(name):
return name.replace(".log", "") + ".log"

def init(baseFilename):
logPath = constants.LOGGING_DIR
envSuffix = '-prod' if constants.ENV == 'prod' else '-dev'
logFilename = os.path.join(logPath, baseFilename + envSuffix + '.log')
print(f"Logging to {logFilename}")

handler = TimedRotatingFileHandler(logFilename,
when = "midnight",
backupCount = 30,
encoding = 'utf8')
handler.setLevel(logging.DEBUG)
handler.suffix = "%Y%m%d"
handler.namer = namer

formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s
[%(module)s:%(lineno)d]')
handler.setFormatter(formatter)

logging.basicConfig(
handlers = [handler],
format = '%(asctime)s %(levelname)s %(message)s
[%(module)s:%(lineno)d]',
level = logging.DEBUG,
datefmt = '%Y-%m-%d %H:%M:%S')

if __name__ == '__main__':
init('testing')
logging.error("ohai")
logging.debug("ohai debug")
logging.getLogger().handlers[0].doRollover()
logging.error("ohai next day")
logging.debug("ohai debug next day")

On Mon, Mar 1, 2021 at 8:13 AM Vinay Sajip  wrote:

>
> Vinay Sajip  added the comment:
>
> As per the documentation at
>
>
> https://docs.python.org/3/library/logging.handlers.html#logging.handlers.BaseRotatingHandler.namer
>
> You can set the handler's "namer" attribute to a callable that returns a
> computed name for the rotated file - this can be computed as per your
> requirements. The cookbook also has an entry about this:
>
>
> https://docs.python.org/3/howto/logging-cookbook.html#using-a-rotator-and-namer-to-customize-log-rotation-processing
>
> --
>
> ___
> Python tracker 
> 
> ___
>

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43344] RotatingFileHandler breaks file type associations

2021-03-02 Thread Vinay Sajip


Vinay Sajip  added the comment:

I'll add to the cookbook recipe with this real-world example, when I get a 
chance.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43344] RotatingFileHandler breaks file type associations

2021-03-02 Thread Vinay Sajip


Vinay Sajip  added the comment:

> Thanks Vinay, I was able to do this

Glad to hear it, Kevin. That namer is exactly what I had in my mind's eye ;-)

So shall I close the issue?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43344] RotatingFileHandler breaks file type associations

2021-03-02 Thread Kevin Hollingshead


Kevin Hollingshead  added the comment:

Sure. Thanks for your help.

On Tue, Mar 2, 2021, 1:08 PM Vinay Sajip  wrote:

>
> Vinay Sajip  added the comment:
>
> I'll add to the cookbook recipe with this real-world example, when I get a
> chance.
>
> --
>
> ___
> Python tracker 
> 
> ___
>

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43344] RotatingFileHandler breaks file type associations

2021-03-01 Thread Vinay Sajip


Vinay Sajip  added the comment:

As per the documentation at

https://docs.python.org/3/library/logging.handlers.html#logging.handlers.BaseRotatingHandler.namer

You can set the handler's "namer" attribute to a callable that returns a 
computed name for the rotated file - this can be computed as per your 
requirements. The cookbook also has an entry about this:

https://docs.python.org/3/howto/logging-cookbook.html#using-a-rotator-and-namer-to-customize-log-rotation-processing

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43344] RotatingFileHandler breaks file type associations

2021-02-28 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

+1 The ability to customize the filenames seems like a reasonable feature 
request.  Perhaps an optional *format* option could introduced.

--
nosy: +rhettinger, vinay.sajip
versions: +Python 3.10

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43344] RotatingFileHandler breaks file type associations

2021-02-27 Thread Kevin Hollingshead


New submission from Kevin Hollingshead :

The filenames generated by logging.RotatingFileHandler breaks the ability to 
associate a program (e.g. notepad++, sublime text, etc.) with the log files 
using Windows or OSX file associations because the extension is overridden by 
the added suffix. For example, if I specify the filename as "test.log" for a 
TimeBasedRotatingFileHandler with a suffix of "%Y%m%d", rolled over files are 
named test.log.MMDD. There is no way to associate a program with this type 
of file extension. A good non-breaking fix would be to add a parameter 
"extension" to RotatingFileHandler, and if specified would be applied to all 
filenames. Thus if I specify filename="test" and "extension="log" for my 
handler it would give "test.log" for the initial file and "test.MMDD.log" 
for rollover files.

--
components: Extension Modules
files: logger_bug.py
messages: 387793
nosy: kh14821
priority: normal
severity: normal
status: open
title: RotatingFileHandler breaks file type associations
type: behavior
Added file: https://bugs.python.org/file49840/logger_bug.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com