[mythtv] [Patch] Logging to database PLUS automatic mythfilldatabase

Joseph A. Caputo jcaputo1 at comcast.net
Fri Feb 27 13:43:17 EST 2004


On Friday 27 February 2004 12:35, Matt White wrote:
> Joseph A. Caputo wrote:
> > Glad I could help.  Would you be able to add a size limit to the
> > log table as well?  Either per-module or overall.  After (or
> > before) inserting a log message (assuming it's not a repeat), you
> > can do a:
> >
> > SELECT COUNT(*) from mythlog WHERE module = <module name>
> >
> > to get the current number of entries for a module; if it's greater
> > than some maximum, enter a loop where you delete the oldest entry
> > for that module until it's below the max number of entries. 
> > Actually, there's probably a clever way to delete the <n> oldest
> > entries, but my SQL isn't good enough...
> >
> > In any event, the simple case is that you should only ever have 1
> > entry to delete, unless you've lowered the max number (which would
> > be configurable) since the last time the housekeeping thread ran.
>
> I was trying to make the log call fairly quick, since it's being run
> in-line during regular operation and not in its own thread.  I don't
> know how much of an issue that is - like you say, it should be a
> pretty simple check.  I'll do some experimenting...

Alternately, you could do this, to avoid doing the SELECT COUNT(*) query 
every time the Log function is called:

void MythContext::LogEntry(const QString &module, int priority,
                     const QString &message, const QString &details)
{
	static QMap<QString, int> logCounts;

	if (0 == logCounts[module])
	{
		logCounts[module] = <result of SELECT COUNT(*) query>
	}
	else if (logCounts[module] >= <max allowable entries from 
gContext->getNumSetting()>
	{
		<delete N entries to get under the maximum>
	}

...[snip]...
}

> I think it should be fairly simple to just do
>
> SELECT logid FROM mythlog WHERE module=<modulename> ORDER BY ldate
> ASC;
>
> and then just deleting the first x events returned to get down under
> the limit...

Cool.


> > One last thing... (and I haven't looked at the UI for the logs, so
> > maybe you already filter this out of the UI...)  Does it really
> > make sense to keep logs in the database after they've been
> > acknowledged?  At the very least they should be filtered out of the
> > UI view, but I don't know that there's really any point to keeping
> > them in the DB once they've been acknowledged.  Just something to
> > chew on.
>
> The UI only shows non-acknowledged events.  I didn't do deletes from
> the mythlog module for a couple of reasons:  First, I figured that
> the cleanup stuff should be done in the main code, since a user
> doesn't necessarily need MythLog installed.  Second is that in some
> cases, you may want to have the Log view there for convenience, but
> have the logs mailed out as well periodically.  That's what I'm doing
> for my parents - I have it set so that the UI shows them important
> errors, and dad can look at it and deal with most of them, but it
> also emails me all of the events every couple of days so I can see if
> anything's up. That's kind of a special case, I know.


Sounds good.

-JAC


More information about the mythtv-dev mailing list