The type field is often used for the module name when logging messages. There are many modules which have names longer than 16 characters. This field needs to be lengthened to at least 32.

Comments

dave reid’s picture

Title: Watchdog table "type" is too small » Change {dblog}.type from VARCHAR(16) to VARCHAR(32)

Marked #342709: Improve documentation for watchdog() as a duplicate of this issue. This seems to be an occasionally recurring problem:
#330844: Data too long
#312624: Odd Bug When Executing Action
#341229: Data too long for column 'type'

I don't see any downside to increasing the type character limit to 32. It seems to be a problem not many developers know about, especially since the limit is not documented in watchdog(). We should at a minimum improve the documentation for this problem.

dave reid’s picture

Status: Active » Needs review
StatusFileSize
new2.89 KB

Initial patch to increase the length of the {dblog}.type field. Added documentation to watchdog() and dblog_watchdog().

chriscohen’s picture

Is there any reason to limit it to 32? I'm sure that long module names combined with suffixes will come close to exceeding this limit. A length of 64 might be more appropriate, I think.

catch’s picture

Status: Needs review » Needs work

If we're going to increase it, might as well go to 64.

dave reid’s picture

Status: Needs work » Needs review
StatusFileSize
new9.03 KB

Revised patch with the 64-char limit. While browsing through hook_watchdog and implementations of hook_watchdog, I found lots of inconsistencies and errors, most notably, the drupal_mail() in hook_watchdog was the D5-version of the function. :)

Status: Needs review » Needs work

The last submitted patch failed testing.

dave reid’s picture

Status: Needs work » Needs review

Testing slave #8 failure.

nancydru’s picture

@chris.cohen: No, there is nothing magical about 32. When I discovered this problem, I did not know enough about all the places where this might be a problem, so I just went to a bit more than I actually needed. I am sure catch is much more versed in internals than I, so if he thinks it can go even larger, I am all for it.

dries’s picture

Patch looks good to me. Good catch on drupal_mail(). Further proof that it would be really useful to have some functionality that allows us to test drupal_mail() calls ...

david strauss’s picture

Status: Needs review » Needs work

Let's extend it to 64 or 128. There is no penalty in MySQL or PostgreSQL for simply having longer VARCHAR columns unless you're hitting maximum index or row length caps.

There are plenty of reasons we wouldn't want to be merely limited to the module name for the type.

dave reid’s picture

Title: Change {dblog}.type from VARCHAR(16) to VARCHAR(32) » Change {dblog}.type VARCHAR limit from 16 to 64
Status: Needs work » Needs review

The patch in #5 actually changes it to 64. Setting back to CNR so I can double check that it still passes with the testing bot.

dries’s picture

Status: Needs review » Fixed

Ran my own tests, and everything succeeded. Code looked good too, so committed to CVS HEAD. Thanks Dave.

nancydru’s picture

Fabulous! Thanks Dave and Dries.

ball.in.th’s picture

Hi,

I got here from Data too long for column 'link' in watchdog table which has been flaged as a dup of this issue.

Truncating the link column will prevent the warning about "Data too long" from showing up, but it also makes watchdog less useful because you won't know which *exact link* causes the log entry. If there's no penalty in having a longer varchar column in the database, why not also increase the size to, say, 2000. Just kidding; but something longer than 255.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

mustanggb’s picture

Version: 7.x-dev » 6.17
Status: Closed (fixed) » Patch (to be ported)

If some clever chap could port this back to 6.17 that would be great.

nancydru’s picture

I just went into the database and manually changed it. I have had no fall-out over it.

rdrh555’s picture

Assigned: Unassigned » rdrh555
StatusFileSize
new2.76 KB

Attempted:

nancydru’s picture

Status: Patch (to be ported) » Needs work

It was changed to 64 above. Plus you should use drupal_substr.

rdrh555’s picture

I realized, as soon as I did that, I was working from the wrong patch. I assumed it would need additional work, did I miss anything else? The additional changes in #5 apply to D7?

nimi’s picture

Please anyone, could we have a drupal 6.x version of this patch?

nancydru’s picture

@nimi, you don't really need to wait. All I did was to go into the database and manually change the length for that column. This patch merely makes it official and adds some little niceties. Even if rdrh555 reworks it, there is no guarantee that it will be committed, although IMHO, it does not break the API (although trimming the field might be considered that).

@rdrh555: while I was writing that, I had a thought: if you limit the display to 32, how does that affect the filtering?

mustanggb’s picture

Version: 6.17 » 6.x-dev
rdrh555’s picture

Status: Needs work » Needs review
StatusFileSize
new2.77 KB

@NancyDru, hmm, I don't know, perhaps someone w/more knowledge will comment? Also, curious, when do you use drupal_substr as opposed to substr?
As I was going through the API, I found a comment also referring to having this patched, although for the life of me, I cannot find it again...maybe it was nimi...
So, I redid it with #19 suggestions and higher powers can decide if it will be accepted.

nancydru’s picture

Drupal_substr is multibyte safe, so unless you know for an absolute fact that you are only using a single byte character set, you should use drupal_substr. Note that almost all Drupal sites use UTF8, which is multibyte. I pretty much always use drupal_substr to be safe. Fortunately the Coder module will warn you.

The patch looks good to me.

thedavidmeister’s picture

Assigned: rdrh555 » Unassigned
Issue summary: View changes
Status: Needs review » Needs work
+function dblog_update_6001() {
+   db_add_index($ret, 'watchdog', 'uid', array('uid'));
+   return $ret;
+ }

What's this about? I didn't see it in the D7 patch and it seems to be a mistake.

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.