# Logging sometimes reports wrong database in multisite

**URL:** https://meta.discourse.org/t/logging-sometimes-reports-wrong-database-in-multisite/69088
**Category:** Feature
**Created:** [August 30, 2017, 5:03pm UTC](https://meta.discourse.org/t/logging-sometimes-reports-wrong-database-in-multisite/69088 "2017-08-30T17:03:53Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![michaeld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/michaeld/32/1594_2.png) [@michaeld](https://meta.discourse.org/u/michaeld)
#### Post date: [August 30, 2017, 5:03pm UTC](https://meta.discourse.org/t/logging-sometimes-reports-wrong-database-in-multisite/69088/1 "2017-08-30T17:03:53Z")

</div>

I was investigating an issue and it seems like the lines in `production.log` sometimes report the wrong database.

I’ve seen this a few times before, so this is not a single incident. Here’s a good and clear example where you can see that the third line has been logged as belonging to database `db3785` where it obviously is about the same request as the fourth line, which is logged as belonging to `db9210`.

![image](https://global.discourse-cdn.com/meta/original/3X/6/6/66c35d34ad9bf5989c5ba57db6fe512b87143894.png)

I was unable to pinpoint the responsible code, it might be deep inside Rails, and this is probably a race condition.

v1.8.x on Unicorn.

_No, we’re not using Docker, no, I don’t think that matters here, and no, I don’t expect a quick solution.  
Just letting you guys know what we are seeing 🙂_

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [August 30, 2017, 7:17pm UTC](https://meta.discourse.org/t/logging-sometimes-reports-wrong-database-in-multisite/69088/2 "2017-08-30T19:17:19Z")

</div>

Rails logs are a trashfire, we plan to start using a new format in future

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [August 30, 2017, 9:19pm UTC](https://meta.discourse.org/t/logging-sometimes-reports-wrong-database-in-multisite/69088/6 "2017-08-30T21:19:36Z")

</div>

I’ll put this on my list first, it seems like the connection is switched even before logging is complete.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [October 2, 2017, 6:47am UTC](https://meta.discourse.org/t/logging-sometimes-reports-wrong-database-in-multisite/69088/7 "2017-10-02T06:47:21Z")

</div>

This is really unsolvable with the current log format. @tgxworld is going to investigate making [GitHub - roidrage/lograge: An attempt to tame Rails' default policy to log everything. · GitHub](https://github.com/roidrage/lograge) an optional (and hopefully default) log format for rails to avoid this mess and give us properly parsable log files.

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [October 31, 2017, 2:28am UTC](https://meta.discourse.org/t/logging-sometimes-reports-wrong-database-in-multisite/69088/8 "2017-10-31T02:28:17Z")

</div>

Note that lograge can now be enabled via a **hidden** `SiteSetting.logging_provider` or setting `ENABLE_LOGRAGE` to 1. We’ll be testing this on our servers for awhile before deciding if lograge should be the default for all Discourse users.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [June 21, 2018, 5:26am UTC](https://meta.discourse.org/t/logging-sometimes-reports-wrong-database-in-multisite/69088/9 "2018-06-21T05:26:23Z")

</div>

Is lograge the default now?

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [June 21, 2018, 5:49am UTC](https://meta.discourse.org/t/logging-sometimes-reports-wrong-database-in-multisite/69088/10 "2018-06-21T05:49:28Z")

</div>

Nope but we can make it so.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [July 17, 2018, 7:35am UTC](https://meta.discourse.org/t/logging-sometimes-reports-wrong-database-in-multisite/69088/11 "2018-07-17T07:35:35Z")

</div>

I am moving this to #Contribute > Feature as we already have a system that works nicely for multisite and multisite is very very uncommon.

I am fine to move to lograge by default longer term it will give Discourse Doctor more ammo.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [August 1, 2018, 9:56am UTC](https://meta.discourse.org/t/logging-sometimes-reports-wrong-database-in-multisite/69088/12 "2018-08-01T09:56:12Z")

</div>

`lograge` seems like a vast improvement and it took me forever to find this topic to find how to start it.

> [@tgxworld](#):
>
> Note that lograge can now be enabled via a **hidden** `SiteSetting.logging_provider` or setting `ENABLE_LOGRAGE` to 1.

Is it too soon to un-hide the site setting?

Would it be disastrous to change the default to `lograge` for new installs?

It’s not immediately clear what `discourse-doctor` might do, `grep` for “Error”, but having some logs around to look at is a first step. . .

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [August 1, 2018, 10:59am UTC](https://meta.discourse.org/t/logging-sometimes-reports-wrong-database-in-multisite/69088/13 "2018-08-01T10:59:46Z")

</div>

Yeah @tgxworld let’s make lograge the default?

---

<div class="post-metadata">

### Author: ![dscat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dscat/32/203656_2.png) [@dscat](https://meta.discourse.org/u/dscat)
#### Post date: [March 2, 2021, 4:16pm UTC](https://meta.discourse.org/t/logging-sometimes-reports-wrong-database-in-multisite/69088/14 "2021-03-02T16:16:54Z")

</div>

Hi there,  
in my organization we use lograge/graylog for all of our apps and we use the JSON formatter because it just gives us a more organized way to figure out problems.

We’re implementing a forum using discourse which does provide a lograge option but uses the `KeyValue` formatter, which would complicate our setup.

I have a PR [adding a lograge formatter env var · Pull Request #12206 · discourse/discourse](https://github.com/discourse/discourse/pull/12206/files) that still leaves the default formatter to `KeyValue` as it is right now but allows to override it by specifying a `LOGRAGE_FORMATTER` env var.
