title: How to test content of winston logger message in console
body: <p>I am using Winston as my logger for my app, and I am trying to write unit tests (using Jest) for the logger message. I'm specifically trying to make sure no passwords are passed to my logs. </p>
  
  <p>Since the logger outputs to <code>stdout</code>, I can't find a way to access what my <code>winston.error</code> function outputs and run my asserts on the log object. </p>
  
  <p>I've tried several different ways to access the result of the logger and googled for solution without much success. This is my last iteration:</p>
  
  <p>My logger.js (the content parameter is sanitized prior to passing it to the logger):</p>
  
  <pre><code>export const error = (content) =&gt; {
    return winston.error(content);
  };
  </code></pre>
  
  <p>and my logger.spec.js:</p>
  
  <pre><code>const exampleLogs = { "email":"email", "password":"password" };
  
  describe('Passwords are filtered out of Winston logger messages', () =&gt; {
    it('Should filter out password data from "error" level errors', () =&gt; {
      logger.error(exampleLogs);
      const result = jest.fn();
      expect(result).not.toHaveProperty('password');
    });
  });
  </code></pre>
  
  <p>The test passes even though the password key is right there. When I <code>console.log(result)</code> I get a mock constructor object:</p>
  
  <pre><code>{ [Function: mockConstructor]
        _isMockFunction: true,
        getMockImplementation: [Function],
        mock: [Getter/Setter],
        mockClear: [Function],
        mockReset: [Function],
        mockRestore: [Function],
        mockReturnValueOnce: [Function],
        mockResolvedValueOnce: [Function],
        mockRejectedValueOnce: [Function],
        mockReturnValue: [Function],
        mockResolvedValue: [Function],
        mockRejectedValue: [Function],
        mockImplementationOnce: [Function],
        mockImplementation: [Function],
        mockReturnThis: [Function],
        mockName: [Function],
        getMockName: [Function] }
  </code></pre>
  
  <p>But I was hoping to see my <code>exampleLogs</code> object... how can I access the object that the logger sends to <code>stdout</code>? any help would be appreciated!</p>