splinter icon indicating copy to clipboard operation
splinter copied to clipboard

Logging setup in browser.py clobbers other logging

Open jordanvance opened this issue 4 years ago • 10 comments

The logging in browser.py calls the root logger, which can cause unexpected changes to the setup and output in some testing environments. It would be preferable to have it log to something like:

LOG = logging.getLogger(__name__)
...
except ImportError as e:
    LOG.debug(f"Import warning: {e}")

jordanvance avatar Jun 16 '22 17:06 jordanvance

Trying to guess the intent behind #994 here. What's the usecase?

The problem with that approach in #994 is that logging.debug(f'Import Warning: {e}') does a logging.basicConfig() if there's no root handler defined. That seems to setup a StreamHandler on the root to stderr. We setup our logging expecting that it starts clean. Most of us will do import splinter somewhere at a module top. The problem is that at import time (before import splinter) it's rather hard to setup some meaningful logging. With #994 that still means there's no output on a missing import. With Jordan's above patch it will be still hard to have anything printed because you'll need to setup logging at import time (before import splinter).

I think @jsfehler imported splinter somewhere in code, after logging was setup. In this case there's a chance to get something on stderr(?) or on a configured logger with #994 .

agroszer avatar Jun 16 '22 17:06 agroszer

@jordanvance Good catch. Yes, not getting a logger just for splinter is a mistake.

@agroszer The reason this logging is set to the debug level is that it's only useful for debugging the splinter library. 99% of the time it's not useful information. The correct behaviour is to ignore missing but optional imports, so the log message would just be noise. When testing if splinter is working at all, however, this message can solve an extremely simple gotcha: You forgot a dependency. If all else fails, you can setup your logger before importing splinter and get something meaningful.

javascript-error avatar Jun 17 '22 14:06 javascript-error

Closed via #1054.

fsouza avatar Jun 18 '22 01:06 fsouza

can we get a release please?

agroszer avatar Jun 20 '22 11:06 agroszer

Sorry completely missed this. @jsfehler should we push out a patch-release? Or should we wait for the next regular release?

fsouza avatar Jun 26 '22 23:06 fsouza

@fsouza @jsfehler i'd love to get a patch release if possible as 0.18.0 has handling for the deprecations released in selenium 4.3.0.

jordanvance avatar Jun 27 '22 17:06 jordanvance

@fsouza I see no reason to wait.

javascript-error avatar Jun 27 '22 18:06 javascript-error

Sounds good I'll publish 0.18.1

fsouza avatar Jun 27 '22 21:06 fsouza

Sent #1061. I haven't bumped the version in a while, so opened as a PR.

fsouza avatar Jun 27 '22 21:06 fsouza

@fsouza @jsfehler thanks so much for everything!

jordanvance avatar Jun 28 '22 17:06 jordanvance