[mythtv] New patch: Event log in database

Matt White whitem at arts.usask.ca
Sun Feb 22 14:18:48 EST 2004


Attached is an updated patch.  This version uses the same priority
numbering as Unix syslog (thanks, Denys).

I thought I had figured out how to include new files with a CVS
diff, but apparently not.  cvs -uwN diff still ignores those
files.  I've tried on my own CVS server, and you need to do an
cvs add first, which I can't do without write access to the Myth
CVS tree.  Therefore, I'm including the two new files that come
with the patch (including one that I forgot before):

mythmaillog.pl - emails selected events
mailflushlog.pl - deletes old events to prevent db filling

-- 
Matt White                          whitem at arts.usask.ca
Arts and Science Computer Labs      University of Saskatchewan

It sure is Monday... Ain't it a sin
I've gotta work my way thru the week again.
	- Mark Chesnutt..."Sure Is Monday"
-------------- next part --------------
Index: libs/libmyth/mythcontext.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythcontext.cpp,v
retrieving revision 1.110
diff -u -w -r1.110 mythcontext.cpp
--- libs/libmyth/mythcontext.cpp	5 Feb 2004 22:50:36 -0000	1.110
+++ libs/libmyth/mythcontext.cpp	22 Feb 2004 19:10:58 -0000
@@ -845,6 +845,33 @@
     return retval.toInt();
 }
 
+void MythContext::LogEntry(const QString &module, int priority,
+                     const QString &message, const QString &details)
+{
+    if (gContext->GetNumSetting("LogEnabled", 0) == 1)
+    {
+        d->dbLock.lock();
+    
+        if (d->m_db->isOpen())
+        {
+            KickDatabase(d->m_db);
+    
+            QString querystr = QString("INSERT INTO mythlog ( module, priority, "
+                                       "logdate, host, message, details) "
+                                       "values ( '%1', %2, now(), '%3', "
+                                       "'%4','%5' );") . arg(module) .
+                                       arg(priority) . arg(d->m_localhostname) .
+                                       arg(message) . arg(details);
+    
+            QSqlQuery result = d->m_db->exec(querystr);
+            if (!result.isActive())
+                MythContext::DBError("LogEntry", querystr);
+        }
+    
+        d->dbLock.unlock();
+    }
+}
+
 QString MythContext::GetSettingOnHost(const QString &key, const QString &host,
                                       const QString &defaultval)
 {
Index: libs/libmyth/mythcontext.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythcontext.h,v
retrieving revision 1.128
diff -u -w -r1.128 mythcontext.h
--- libs/libmyth/mythcontext.h	17 Feb 2004 01:13:19 -0000	1.128
+++ libs/libmyth/mythcontext.h	22 Feb 2004 19:10:58 -0000
@@ -42,6 +42,17 @@
     VB_ALL       = 0xffff
 };
 
+enum LogPriorities {
+    LP_EMERG     = 0,
+    LP_ALERT     = 1,
+    LP_CRITICAL  = 2,
+    LP_ERROR     = 3,
+    LP_WARNING   = 4,
+    LP_NOTICE    = 5,
+    LP_INFO      = 6,
+    LP_DEBUG     = 7
+};
+
 #define VERBOSE(mask,args...) \
 do { \
 if ((print_verbose_messages & mask) != 0) \
@@ -129,6 +140,9 @@
     QString GetSetting(const QString &key, const QString &defaultval = "");
     int GetNumSetting(const QString &key, int defaultval = 0);
 
+    void LogEntry(const QString &module, int priority,
+                  const QString &message, const QString &details);
+
     QString GetSettingOnHost(const QString &key, const QString &host,
                              const QString &defaultval = "");
     int GetNumSettingOnHost(const QString &key, const QString &host,
Index: libs/libmythtv/dbcheck.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/dbcheck.cpp,v
retrieving revision 1.35
diff -u -w -r1.35 dbcheck.cpp
--- libs/libmythtv/dbcheck.cpp	12 Feb 2004 05:58:02 -0000	1.35
+++ libs/libmythtv/dbcheck.cpp	22 Feb 2004 19:11:00 -0000
@@ -8,7 +8,7 @@
 
 #include "mythcontext.h"
 
-const QString currentDatabaseVersion = "1033";
+const QString currentDatabaseVersion = "1034";
 
 void UpdateDBVersionNumber(const QString &newnumber)
 {
@@ -638,7 +638,25 @@
 };
         performActualUpdate(updates, "1033", dbver);
     }
+    if (dbver == "1033")
+    {
+        const QString updates[] = {
+"CREATE TABLE mythlog ("
+"  logid int(10) unsigned PRIMARY KEY NOT NULL auto_increment,"
+"  module char(32) NOT NULL,"
+"  priority int(11) NOT NULL,"
+"  acknowledged bool default 0,"
+"  logdate datetime,"
+"  host varchar(128),"
+"  message varchar(255) NOT NULL,"
+"  details text"
+");",
+""
 };
+        performActualUpdate(updates, "1034", dbver);
+    }
+
+}
 
 void InitializeDatabase(void)
 {
Index: programs/mythbackend/main.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythbackend/main.cpp,v
retrieving revision 1.58
diff -u -w -r1.58 main.cpp
--- programs/mythbackend/main.cpp	10 Feb 2004 03:34:25 -0000	1.58
+++ programs/mythbackend/main.cpp	22 Feb 2004 19:11:02 -0000
@@ -51,6 +51,11 @@
                 cerr << "One of your capturecard entries does not have a "
                      << "hostname.\n  Please run setup and confirm all of the "
                      << "capture cards.\n";
+                gContext->LogEntry("mythbackend",LP_CRITICAL,
+                      "Problem with capture cards",
+                      "One of your capturecard entries does not have a "
+                      "hostname.\n  Please run setup and confirm all of the "
+                      "capture cards.\n");
                 exit(-1);
             }
 
@@ -85,6 +90,8 @@
     {
         cerr << "ERROR: no capture cards are defined in the database.\n";
         cerr << "Perhaps you should read the installation instructions?\n";
+        gContext->LogEntry("mythbackend",LP_CRITICAL,
+                "No capture cards are defined","Please run the setup program.");
         return false;
     }
 
@@ -436,6 +443,9 @@
     if (masterip == myip)
     {
         cerr << "Starting up as the master server.\n";
+        gContext->LogEntry("mythbackend",LP_INFO,
+                           "MythBackend started as master server","");
+
         ismaster = true;
 
         if (nosched)
@@ -445,6 +455,8 @@
     else
     {
         cerr << "Running as a slave backend.\n";
+        gContext->LogEntry("mythbackend",LP_INFO,
+                           "MythBackend started as a slave backend","");
     }
  
     bool runsched = setupTVs(ismaster);
@@ -503,6 +515,8 @@
     a.exec();
 
     // delete trans;
+    gContext->LogEntry("mythbackend",LP_INFO,
+                       "MythBackend exiting","");
 
     cleanup();
 
Index: programs/mythfilldatabase/filldata.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythfilldatabase/filldata.cpp,v
retrieving revision 1.90
diff -u -w -r1.90 filldata.cpp
--- programs/mythfilldatabase/filldata.cpp	13 Feb 2004 05:59:34 -0000	1.90
+++ programs/mythfilldatabase/filldata.cpp	22 Feb 2004 19:11:07 -0000
@@ -2051,6 +2051,7 @@
         return -1;
     }
 
+    gContext->LogEntry("mythfilldatabase",LP_INFO,"Listings Download Started","");
     if (from_xawfile)
     {
         readXawtvChannels(fromxawfile_id, fromxawfile_name);
@@ -2088,6 +2089,7 @@
              {
                   cerr << "There are no channel sources defined, did you run the "
                        << "setup program?\n";
+                  gContext->LogEntry("mythfilldatabase",LP_CRITICAL,"No channel sources defined","Could not find any defined channel sources - did you run the setup program?");
                   exit(-1);
              }
         }
@@ -2102,6 +2104,7 @@
         if (!ret)
         {
              cerr << "Failed to fetch some program info\n";
+             gContext->LogEntry("mythfilldatabase",LP_WARNING,"Failed to fetch some program info","");
              exit(1);
         }
     }
@@ -2116,6 +2119,7 @@
 
     ScheduledRecording::signalChange(db);
 
+    gContext->LogEntry("mythfilldatabase",LP_INFO,"Listings Download Finished","");
     delete gContext;
 
     return 0;
Index: programs/mythfrontend/globalsettings.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythfrontend/globalsettings.cpp,v
retrieving revision 1.139
diff -u -w -r1.139 globalsettings.cpp
--- programs/mythfrontend/globalsettings.cpp	16 Feb 2004 06:43:43 -0000	1.139
+++ programs/mythfrontend/globalsettings.cpp	22 Feb 2004 19:11:14 -0000
@@ -966,6 +966,18 @@
     };
 };
 
+class LogEnabled: public CheckBoxSetting, public GlobalSetting {
+public:
+    LogEnabled():
+        GlobalSetting("LogEnabled") {
+        setLabel(QObject::tr("DB Logging Enabled"));
+        setValue(false);
+        setHelpText(QObject::tr("If checked, the Myth modules will send event details "
+                    "to the database, where they can be viewed with MythLog or emailed "
+                    "out periodically."));
+    };
+};
+
 class XineramaScreen: public SpinBoxSetting, public GlobalSetting {
 public:
     XineramaScreen():
@@ -1664,6 +1676,7 @@
     general->addChild(new HaltCommand());
     general->addChild(new SetupPinCodeRequired());
     general->addChild(new SetupPinCode());
+    general->addChild(new LogEnabled());
     general->addChild(new EnableMediaMon());
     general->addChild(new EnableXbox());
     addChild(general);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mythflushlog.pl
Type: application/x-perl
Size: 1584 bytes
Desc: not available
Url : http://mythtv.org/pipermail/mythtv-dev/attachments/20040222/5c0f30a8/mythflushlog.pl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mythmaillog.pl
Type: application/x-perl
Size: 3562 bytes
Desc: not available
Url : http://mythtv.org/pipermail/mythtv-dev/attachments/20040222/5c0f30a8/mythmaillog.pl


More information about the mythtv-dev mailing list