Skip to content

CSSUTILS logger overrides existing config on import #13

Open

Description

@strokirk

Hi!

On first import of cssutils, the 'CSSUTILS' logger is set up and configured with some default values, as can be seen here:
https://github.com/jaraco/cssutils/blob/main/cssutils/errorhandler.py#L51-L56

This can lead to issues if your import of cssutils happens later than your main logging config setup, since it will override whatever is already configured. To avoid it, you must pre-emptively import cssutils before your own logging config.

It would be easier if cssutils detected if the logger has already been set up, and didn't add it's own default config in that case. At the very least, if it preserved the loglevel the user has selected that would help.

Activity

  1. jaraco commented on Jun 3, 2022

    @jaraco
    Owner

    Sounds reasonable to me. Can you draft a fix?

  2. Madin-H23 commented on Oct 21, 2026

    @Madin-H23

    Hi @strokirk — thanks for the report, and sorry for the slow reply. You are right: cssutils creates the CSSUTILS logger at import time, adds its own StreamHandler to it and forces the level to INFO, which overrides a logging setup that ran earlier.

    I would like to fix this. My plan:

    • install the default StreamHandler only when the CSSUTILS logger has no handlers at all, so an application handler is left alone and a second ErrorHandler does not add a duplicate handler,
    • apply the default level only when the logger has no level of its own and the root logger still has the default level, so a level chosen for CSSUTILS or for the root is preserved.

    For an unconfigured logger the behaviour stays exactly as it is today (handler on stderr, level INFO).

    I will open a PR with the change and the tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions