Skip to content

Make logging configurable #1057

@joschkazj

Description

@joschkazj

Hi,

first of all many thanks for putting together this package! Ever since reading the book by Kuhn and Johnson and working with caret in R I've been wanting an equivalent Python library.

Referencing #315 I wanted to propose to change the way the default logger is configured in pycaret.internal.logging:

    try:
        ch = logging.FileHandler("logs.log")    # <-- don't specify a handler with a fixed filename, here
    except:
        print("Could not attach a FileHandler to the logger! No logs will be saved.")
        traceback.print_exc()
        ch = logging.NullHandler()
    ch.setLevel(logging.DEBUG)

In #315:

pycaret commented on Aug 2, 2020
@eonsmile Nope. Is there is a reason you want to disable? Maybe we can mark this as enhancement and somebody can work on making this functionality optional, if that make sense.

For me the use case is an application wrapping a PyCaret model. I've packaged the application using PyInstaller and it is distributed with a setup wizard as a "conventional" Windows application. After installation it's placed in the system's program folder (C:\Program Files (x86)) where normal users don't have write permissions -- but PyCaret wants to create its log file there. As PyCaret is imported in different modules, monkey-patching would require editing some external libraries as well, so re-configuration of the logger appears to be impractical.

Therefore I suggest to make the logging handler configurable, or do you have strong reasons to hard-code the file output?

Additionally, the Python docs on logging state:

Note

It is strongly advised that you do not add any handlers other than NullHandler to your library’s loggers. This is because the configuration of handlers is the prerogative of the application developer who uses your library. The application developer knows their target audience and what handlers are most appropriate for their application: if you add handlers ‘under the hood’, you might well interfere with their ability to carry out unit tests and deliver logs which suit their requirements.

If you accept this I would be happy to submit a PR implementing it.

Keep up the good work
Joschka

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions