No logs in mongo v4.4

For mongodb@4.4 community edition, I don’t see any logs being written.

  • Yes, I have the correct config in /etc/mongodb.conf
    destination: file
    path: /var/log/mongodb/mongod.log
    logAppend: true
  • Yes, I have the correct permission for /var/log/mongodb/mongod.log and its parent folders (mongodb:mongodb)
  • I have set the profiling level to log all queries `db.setProfilingLevel(2, -1)

But the file size of /var/log/mongodb/mongod.log is 0

Most likely the mongod instance is not using the configuration file you shared.

How did you started mongod?

How do you connect to mongod?

Share the output of the following commands:

ss -tlnp
ps -aef | grep [m]ongo

Running mongo server using systemctl on ubuntu@18.
Can confirm that it is using the right config file /etc/mongod.conf
I connect to mongo using mongodb nodejs package mongodb@4.6.0

$ ps -aef | grep [m]ongo
mongodb  14400     1 99 Jun29 ?        295-20:17:30 /usr/bin/mongod --config /etc/mongod.conf

$ ss -tlnp
State  Recv-Q  Send-Q      Local Address:Port      Peer Address:Port                                     
LISTEN 0       128    *                                        
LISTEN 0       128        *                                        
LISTEN 0       128   *                                        
LISTEN 0       128        *                                        
LISTEN 0       128       *                                        
LISTEN 0       128   *                                        
LISTEN 0       128                     *:8080                 *:*      users:(("node",pid=11366,fd=10))  
LISTEN 0       128                  [::]:22                [::]:*                                        
LISTEN 0       128                     *:3000                 *:*      users:(("node /home/prad",pid=17598,fd=19))

Contents of /etc/mongod.conf

  dbPath: /var/lib/mongodb
    enabled: true

  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

  port: 27017

  timeZoneInfo: /usr/share/zoneinfo

  authorization: "enabled"

Output of the command:

ls -al /var/log/mongodb/mongod.log
-rw------- 1 mongodb mongodb 0 Jul 10 06:25 /var/log/mongodb/mongod.log


The above is the face of a perplex person.

I will come back later, hopefully with B-)

1 Like

Output of the command

df -v /var/log/mongodb/

The machine has a lot of space as well as memory available

I see a few possibilities.

The configuration file has changed since mongod was started and the running instance is in fact writing into a different file. In mongosh you might try

db.adminCommand( { getLog: "global" } )

to see if you can find log entries for initandlisten.

Commands such as

/bin/rm /var/log/mongodb/mongod.log
/bin/cp /dev/null /var/log/mongodb/mongod.log

were issued replacing the file that mongod is writing into. But mongod is still writing in the original file handle of the file. Some people do that when they do not run logRotate and the file becomes too big with the false hope that the original file is truncated.

1 Like

thank you. you are right. With the first command, I checked the logs were coming in fact.
Restarting the mongodb server fixed the issue. now I can see the logs in mongod.log.

And probably logrotate might be the culprit here. Is there anything wrong with my logrotate config that could have caused this issue?

/var/log/mongodb/mongod*.log {
        rotate 12
1 Like

I do not know enough about logrotate utility but you could look at



Of particular attention is the sentence:

reopen closes and reopens the log file following the typical Linux/Unix log rotate behavior. Use reopen when using the Linux/Unix logrotate utility to avoid log loss.

The default value is rename which seems to be incompatible with logrotate utility.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.