[SERVER-6777] Eliminate all direct use of cout/stdout and cerr/stderr Created: 16/Aug/12  Updated: 08/Sep/20  Resolved: 08/Sep/20

Status: Closed
Project: Core Server
Component/s: Logging
Affects Version/s: None
Fix Version/s: 4.7.0

Type: Bug Priority: Minor - P4
Reporter: Tad Marshall Assignee: Adam Cooper (Inactive)
Resolution: Done Votes: 0
Labels: Windows, community-team, neweng, platforms-re-triaged
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows, running as a service (mongod and mongos)


Issue Links:
Duplicate
duplicates SERVER-1693 no cout usage at all - have to specif... Closed
duplicates SERVER-23170 Remove lingering uses of std::cout an... Closed
Related
related to SERVER-6778 printStackTrace does not work when ru... Closed
related to SERVER-15884 mongod --version shouldn't print date... Closed
Backwards Compatibility: Fully Compatible
Operating System: Windows
Sprint: Server 2.7.5, Server 2.7.6, Security 2020-05-04, Security 2020-05-18, Security 2020-06-01, Security 2020-08-24, Security 2020-09-07, Security 2020-09-21
Participants:

 Description   

cout/stdout and cerr/stderr do not work when running as a Windows service

We use cout and cerr in assorted places in the code, and we use the C/C++ function dup2() to redirect file handles 1 and 2 (stdout and stderr) to the log file so that statements like "cout << "message" << endl;" will send text to the screen or to a log file if --logpath is set. This works fine in Windows when running in a console window.

It doesn't work when mongod.exe or mongos.exe is running as a service in Windows. Text sent to cout or cerr (or stdout or stderr) goes nowhere and does not appear in the log file.

The dup2() API does not return an error ... it just doesn't do what we want it to do.

This means that some output will not be logged when running as a Windows Service. We may need to audit the code to identify places where we are relying on redirection of standard file handles to log output and change them to use another mechanism (like log()).



 Comments   
Comment by Githook User [ 08/Sep/20 ]

Author:

{'name': 'Adam Cooper', 'email': 'adam.cooper@mongodb.com', 'username': 'super-cooper'}

Message: SERVER-6777 Eliminate all direct use of cout/stdout and cerr/stderr
Branch: master
https://github.com/mongodb/mongo/commit/277782e54a6ccd4dc783b53d5dface21ebaed938

Comment by Sara Golemon [ 01/Jun/20 ]

While there are a number of locations where cout/cerr are used in SERVER, the majority of these are by necessity as they are not log statements and relate to human interactivity when attempting to start the server (or shell).  The one case I ran into where we really shouldn't be using cout/cerr is mongo/util/processinfo_osx.cpp , however as the name implies this file related to OSX only and not Windows.

I'm going to downgrade this to 'Minor' and move it to the backlog so that we don't lose track of it.

Generated at Thu Feb 08 03:12:40 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.