[SERVER-13011] Mongodb should log process_id on every log record Created: 03/Mar/14  Updated: 31/May/17  Resolved: 23/Mar/17

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

Type: Improvement Priority: Minor - P4
Reporter: Roy Smith Assignee: Mira Carey
Resolution: Won't Fix Votes: 0
Labels: platforms-re-triaged
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Participants:

 Description   

Mongodb does not log its process id. If you're running multiple mongodb instances on the same machine, there's no way to tell which log messages come from which instance.

Running multiple instances isn't something you want to do in production, but it happens a bunch a test or development environment, or when doing maintenance.



 Comments   
Comment by Mira Carey [ 23/Mar/17 ]

mongod and mongos can be directed to write to specific log files with --logpath. Additionally, attempting to write to an existing log file will cause mongod to move the old log file out of the way, writing to a new descriptor instead. So we don't actually offer interleaved output out of the box.

And while it is true that two copies of mongod can be launched from the same terminal, at which point their output will be unhelpfully interleaved, other options all involve invoking a separate process to handle multiple files or file descriptors. That process is more than capable of prefixing a line before multiplexing.

As an example, consider tools like multitail. It offers similar functionality to tail, but also allows a --label option per file, which prefixes a string for all lines from a given source.

Because this is a problem that can be solved with tooling, we prefer not to expand the size of log output when it can be easily handled in post (if separate log files are preserved).

Comment by Roy Smith [ 03/Mar/14 ]

Logging the pid ONCE isn't useful. Right now, I'm tailing my log file, watching messages from two mongodb processes go by, interleaved, with no way for me to filter for the ones that pertain to the process I'm interested in. You should log the pid on every line.

Comment by Eric Milkie [ 03/Mar/14 ]

It logs the pid in the first log message:
https://github.com/mongodb/mongo/blob/master/src/mongo/db/db.cpp#L655
Are you seeing something different?

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