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

Add threadID info to logging messages #582

Closed
AlexanderPoleschuk opened this issue Aug 15, 2017 · 5 comments

Comments

Projects
None yet
4 participants
@AlexanderPoleschuk
Copy link

commented Aug 15, 2017

Selenide has closeWebDriver method(code is below).

It would be nice to pass threadID along with logged messages, therefore,
log.severe("Failed to close webdriver in " + closeBrowserTimeoutMs + " milliseconds");
would be
log.severe("Failed to close webdriver " + thread.getId() + " in " + closeBrowserTimeoutMs + " milliseconds");
where thread.getId() is a presaved id of thread that selenide tried to close.
It will really help to investigate the reasons of some failures.

protected void closeWebDriver(Thread thread) {
    ALL_WEB_DRIVERS_THREADS.remove(thread);
    WebDriver webdriver = THREAD_WEB_DRIVER.remove(thread.getId());
    SelenideProxyServer proxy = THREAD_PROXY_SERVER.remove(thread.getId());
    
    if (webdriver != null && !holdBrowserOpen) {
      log.info("Close webdriver: " + thread.getId() + " -> " + webdriver);
      if (proxy != null) {
        log.info("Close proxy server: " + thread.getId() + " -> " + proxy);
      }

      long start = System.currentTimeMillis();

      Thread t = new Thread(new CloseBrowser(webdriver, proxy));
      t.setDaemon(true);
      t.start();

      try {
        t.join(closeBrowserTimeoutMs);
      } catch (InterruptedException e) {
        log.log(FINE, "Failed to close webdriver in " + closeBrowserTimeoutMs + " milliseconds", e);
      }

      long duration = System.currentTimeMillis() - start;
      if (duration >= closeBrowserTimeoutMs) {
        log.severe("Failed to close webdriver in " + closeBrowserTimeoutMs + " milliseconds");
      }
      else if (duration > 200) {
        log.info("Closed webdriver in " + duration + " ms");
      }
      else {
        log.fine("Closed webdriver in " + duration + " ms");
      }
    }
    else if (proxy != null && !holdBrowserOpen) {
      log.info("Close proxy server: " + thread.getId() + " -> " + proxy);
      proxy.shutdown();
    }
  }
@ddemin

This comment has been minimized.

Copy link
Contributor

commented Aug 16, 2017

As I know you can configure logging via some xml file and change logging format (include displaying of thread ID)

@AlexanderPoleschuk

This comment has been minimized.

Copy link
Author

commented Aug 17, 2017

Well, nice that we have an ability for a workaround, however, I don't see a point to do such kind of crutches.
Since Selenide logs a message of webdriver sessionID when it starts the driver, it should log the same format, when trying to clode the WD.
It's just a natural logic.

@BorisOsipov

This comment has been minimized.

Copy link
Member

commented Sep 6, 2017

@AlexanderPoleschuk can you make PR for these changes?

@rosolko

This comment has been minimized.

Copy link
Collaborator

commented Mar 23, 2018

@AlexanderPoleschuk Ping! We need you response.

@rosolko rosolko added the question label Mar 23, 2018

@BorisOsipov

This comment has been minimized.

Copy link
Member

commented May 11, 2018

fixed by #737

@rosolko rosolko added this to the 4.11.5 milestone May 11, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.