Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable logging to stdout #35

Closed
Fogapod opened this issue May 28, 2018 · 6 comments
Closed

Disable logging to stdout #35

Fogapod opened this issue May 28, 2018 · 6 comments

Comments

@Fogapod
Copy link

Fogapod commented May 28, 2018

Library prints a lot of information to stdout, full page code when navigating / making screenshots. It's not clear from documentation how to disable these logs

@ojii
Copy link
Contributor

ojii commented May 28, 2018

The docs should do a better job here I agree. Arsenic uses structlog so for now please check their documentation on how to control output.

@nokados
Copy link

nokados commented Jan 4, 2019

Quick fix

def set_arsenic_log_level(level = logging.WARNING):
    # Create logger
    logger = logging.getLogger('arsenic')

    # We need factory, to return application-wide logger
    def logger_factory():
        return logger

    structlog.configure(logger_factory=logger_factory)
    logger.setLevel(level)

@superlevure
Copy link

I am encountering the same issue and can not manage to disable all logging to stdout even after reading the structlog manual.
Is there a chance someone has the solution ?

@superlevure
Copy link

I finally found the way to do it, it is actually quite simple (and present in the API doc):

service = services.Geckodriver(binary=GECKODRIVER, log_file=os.devnull)

@sVerentsov
Copy link

In my case, I wanted to preserve logging by just trimming long values in methods like screenshot.
This could be achieved by custom processor:

class DictTrimmerProcessor:
    def __init__(self, max_chars=25) -> None:
        self.max_chars = max_chars
        self.block_length = max_chars // 2 - 1

    def __call__(self, logger, method_name, event_dict):
        for field in event_dict:
            if isinstance(event_dict[field], dict):
                val = deepcopy(event_dict[field]) # Copy so that original event_dict is not changed
                for key in val:
                    if isinstance(val[key], str) and len(val[key]) > self.max_chars:
                        val[key] = f"{val[key][:self.block_length]}...{val[key][-self.block_length:]}"
                event_dict[field] = val
        return event_dict


def fix_arsenic_log():
    processors = structlog.get_config().get("processors", [])
    processors.insert(0, DictTrimmerProcessor())
    structlog.configure(processors=processors)

Hope someone finds this helpful since this issue is first on google when searching for logging problems in arsenic.

@ringzinc
Copy link

Using Python 3.10.7 and arsenic 21.8 on Windows 10 here. The confusing part is that arsenic, geckodriver and Firefox all emit info logs to the console, so I had do to quite a few things to turn the noise off:

  1. Comment out all log.info() in <your python install path>\Lib\site-packages\arsenic\connection.py on my machine
  2. Initiate arsenic using the following code (and remove -headless and -private if you don't need them)
service = arsenic.services.Geckodriver(log_file=os.devnull)
browser = arsenic.browsers.Firefox(**{'moz:firefoxOptions': {'args': ['-headless', '-private'], 'log': {'level': 'warn'}}})

I hope this will help someone, and I hope the arsenic developers will give us an option to turn off the logs in future releases

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

No branches or pull requests

7 participants