title: How to log synchronously with winston in node.js
body: <p>I'm fairly new to node.js and I've came from C#/Java lands, so I need some help with logging.</p>
  
  <p>Right now I'm writing tests with Selenium, using native bundings and <code>mocha</code> as my testing framework. I have a <code>base-page.js</code> - base class for all other <code>Page Objects</code> which contains basic methods for interactions with the page and a <code>logInfo(message)</code> method.
  For now, I've decided to go with a <code>winston</code> for logging. My logger config looks like this:</p>
  
  <pre><code>import winston from 'winston'; 
  
  const tsFormat = () =&gt; (new Date()).toLocaleDateString() 
      + ": " + (new Date()).toLocaleTimeString();
  
  const logger = new (winston.Logger)({
      transports: [
      new (winston.transports.Console) ({ 
          timestamp: tsFormat,
          colorize: true }),
      new (winston.transports.File) ({ filename: 'logs.log'})
      ]
  });
  logger.level = 'silly';
  logger.cli();
  </code></pre>
  
  <p>And it works totally fine. The thing is that when I run my test-case all log messages are logged instantly, not as part of a function they are supposed to be logged, at least from C#/Java point of view. </p>
  
  <p>So I want them to be logged only when the execution of action for the page (ie, button click) happens. What can I do here?</p>
  
  <p><strong>EDIT</strong>: providing code as well as some explanations.
  My <code>base-page.js</code> methods looks like this:</p>
  
  <pre><code>    click(logMessage, locator, ...args) {
        this.logInfo(logMessage);
        //this.driver.findElement() is Selenium related. It returns a promise,
        //so I suppose this is a reason of proper execution of interactions.
        this.driver.findElement(locator.getLocator(...args)).click();
  }
  </code></pre>
  
  <p>My <code>logInfo()</code> method:</p>
  
  <pre><code>    logInfo(logMessage) {
        logger.logInfo(logMessage);
  }
  </code></pre>
  
  <p>And <code>logger</code> iself is import of <code>Winston</code> logger, moved to another file. Configs are provided.</p>
  
  <p>Finally, my tests are calling methods from <code>base-page.js</code> by inheritence chain, and i <em>suppose</em> that they are called <em>async too</em>, but because of promises from <code>Selenium</code> it looks like they are synchronous. Only logging shows that they aren't, in fact. So, what can be done here? </p>
  
  <p><strong>UPDATE</strong>: attempt to bubble up <code>Promise</code> from <code>click()</code>, returned by </p>
  
  <pre><code>this.driver.findElement(locator.getLocator(...args)).click();
  </code></pre>
  
  <p>does not affect overall behaviour.</p>