This is probably a dumb question and I'm probably staring right at it, but isn't there a way to set the time limit for storing logs? I thought I saw something set to 7 days, but now I can't find it. Thanks.

Comments

Christefano-oldaccount’s picture

It's in /admin/settings (or /?q=admin/settings if don't have Clean URLs enabled) in the "error handling" field. Yeah, it's in "error handling," so I understand that it's not incredibly easy to find. You'll be able to set Drupal to save logs for anywhere between 1 hour and 1 month.

There was a discussion in another thread somewhere about how to immediately erase logs (instead of setting it to 1 hour and then waiting an hour for them to get deleted), but I don't remember if there was a way. Other than reinstalling Drupal, that is. Does anyone know about this?

noraa’s picture

Thanks. I knew I was staring right at it, and yet couldn't see it. Had clicked almost every one of those dropdowns in settings BUT the error handling. Tells me it's time to go to bed. Nite all!!

mrfrazzlebottom’s picture

My log entries are not being removed. And I notice the the notice: "Requires crontab." And further down the settings page: "Cron jobs - Cron has not run."

Clicking the "configuring cron jobs" link brings me to a nice page on how to add a cron job. Ooops. I have a hosted server and now need to find out if I can even do that.

So, a manual way of managing log files would be nice.

noraa’s picture

I'm on hosted too, so I installed the poormanscon module as advised on this forum. Works like a charm for me. Hope this helps.

xjessie007’s picture

It is fine, no question is dumb around here. Feel free to ask.

One way to delete recent log entries in Drupal is to set the expiration time in the Home - Administer - Site configuration - Error reporting menu. However, the shortest expiration time you can set is 1 hr. If you want to delete recent log entries immediately, you can do so by dumping everything in the watchdog table. After deleting everything on this table, do not forget to adjust index. Here are the queries for you.

DELETE FROM watchdog;
ALTER TABLE watchdog AUTO_INCREMENT = 0;

If you want to create a more permanent solution in your Drupal, for example a link that you click and recent log entries get deleted, you can do so by several means. I am using an approach that provides a delete link for an Admin only, in other words, I want this functionality to be hidden from outsiders.

step 1: create a function, something like the following:

function delRecentLogs() {
	db_query("DELETE FROM watchdog");
	db_query("ALTER TABLE watchdog AUTO_INCREMENT = 0");
}

step 2: create a node of page type

step 3: create a new block that will be visible on the page from step 2 and to the Admin role only. This block will have PHP input format for its body, and you just call the function from step 1 in the body of this block.

step 4: create a link in your navigation menu that points to the page from step 3

How it works? You click the link you just created in your navigation menu which calls a page that includes a block that only Admin can see and this page calls the delRecentLogs() function which dumps everything from the watchdog table. You can then verify by going to Home - Administer - Logs - Recent Log Entries. It should be empty.

Here is a guide that I wrote about dumping cache tables which is closely related to this topic: http://drupal.org/node/17620#comment-856035.

You can also find some print screens on my Drupal clear cache page (@ Maxi-Pedia).

More can be also found on my other page about the Drupal cache_clear_all() function (@Maxi-Pedia).

And, by the way, you do not need to run cron for this. It works without it.
And, of course, you can make it even more secure by including admin role checks directly into the function. Something like, "delete only if admin"...

Cheers!

---
www.Maxi-Pedia.com Your trusted resource for finance and IT!
www.finance-management.cz Central European Center for Finance and Management

Bartezz’s picture

This might work better when one has prefixed tables :)

<?php
db_query("DELETE FROM {watchdog}");
db_query("ALTER TABLE {watchdog} AUTO_INCREMENT = 0");
?>

Cheers

________________
Live fast die young

Lomez’s picture

This will save you a query and do the same thing :) Automatically reindexes to 1.

db_query(' TRUNCATE TABLE {watchdog} ');
thinkyhead’s picture

Drupal 6 has a setting at admin/settings/logging/dblog (Administer > Site configuration > Logging and alerts > Database logging) which limits the number of items stored in watchdog. The lowest number is 100. These are pruned by cron, so there may be over 100 (in that case) from time to time.

Is there a module to add a "Clear log" button to the Recent Log Entries page? I couldn't find it, so I just wrote one based on a drupal.org forum posting. Would there be any interest in this module being released if one doesn't already exist?

It's one of those tiny tweaks that by itself it seems almost overkill to devote a whole module to, but which should be collected in a bigger module with a bunch of similar tweaks. Does a module like that already exist?

thinkyhead’s picture

The Util module is what you're looking for. It can add a Clear Log button and does some nice interface tweaks too. It's several little modules in one. http://drupal.org/project/util