Logging: add commands to runtime view/enable/disable logging
authorWilfried Goesgens <dothebart@citadel.org>
Sun, 29 Apr 2012 13:19:10 +0000 (15:19 +0200)
committerWilfried Goesgens <dothebart@citadel.org>
Sun, 29 Apr 2012 13:19:10 +0000 (15:19 +0200)
  - LOGP: print log config
  - LOGS: set one logging facility

citadel/modules/c-ares-dns/serv_c-ares-dns.c
citadel/modules/eventclient/serv_eventclient.c
citadel/modules/network/serv_networkclient.c
citadel/modules/pop3client/serv_pop3client.c
citadel/modules/rssclient/rss_atom_parser.c
citadel/modules/rssclient/serv_rssclient.c
citadel/modules/smtp/serv_smtpeventclient.c
citadel/serv_extensions.c
citadel/serv_extensions.h

index 13e156a80879a3ecb17ceb7e8e318d839a59cea9..0f5c004ee14e13d2aaf2c66a73e36607e94ebdf2 100644 (file)
@@ -610,16 +610,16 @@ void SockStateCb(void *data, int sock, int read, int write)
                ev_io_stop(event_base, &IO->DNS.send_event);
        }
 }
-void EnableDebugCAres(void)
+void EnableDebugCAres(const int n)
 {
-       DebugCAres = 1;
+       DebugCAres = n;
 }
 
 CTDL_MODULE_INIT(c_ares_client)
 {
        if (!threading)
        {
-               CtdlRegisterDebugFlagHook(HKEY("cares"), EnableDebugCAres);
+               CtdlRegisterDebugFlagHook(HKEY("cares"), EnableDebugCAres, &DebugCAres);
                int r = ares_library_init(ARES_LIB_INIT_ALL);
                if (0 != r) {
                        
index a079d123206d2f24f179d130a2973fb74822cc5b..06e140b7ebbe006e875fd645d9d2a5162d81440c 100644 (file)
@@ -841,27 +841,27 @@ void ShutDownEventQueues(void)
        pthread_mutex_unlock(&EventQueueMutex);
 }
 
-void DebugEventloopEnable(void)
+void DebugEventloopEnable(const int n)
 {
-       DebugEventLoop = 1;
+       DebugEventLoop = n;
 }
-void DebugEventloopBacktraceEnable(void)
+void DebugEventloopBacktraceEnable(const int n)
 {
-       DebugEventLoopBacktrace = 1;
+       DebugEventLoopBacktrace = n;
 }
 
-void DebugCurlEnable(void)
+void DebugCurlEnable(const int n)
 {
-       DebugCurl = 1;
+       DebugCurl = n;
 }
 
 CTDL_MODULE_INIT(event_client)
 {
        if (!threading)
        {
-               CtdlRegisterDebugFlagHook(HKEY("eventloop"), DebugEventloopEnable);
-               CtdlRegisterDebugFlagHook(HKEY("eventloopbacktrace"), DebugEventloopBacktraceEnable);
-               CtdlRegisterDebugFlagHook(HKEY("curl"), DebugCurlEnable);
+               CtdlRegisterDebugFlagHook(HKEY("eventloop"), DebugEventloopEnable, &DebugEventLoop);
+               CtdlRegisterDebugFlagHook(HKEY("eventloopbacktrace"), DebugEventloopBacktraceEnable, &DebugEventLoopBacktrace);
+               CtdlRegisterDebugFlagHook(HKEY("curl"), DebugCurlEnable, &DebugCurl);
                InitEventQueue();
                DBInitEventQueue();
                CtdlThreadCreate(client_event_thread);
index 91dd4ad4d7f0ad5446c25360c87e300cd0756c10..1a027ea2384e8ed481398cec9f6104e895118c6b 100644 (file)
@@ -1037,9 +1037,9 @@ void network_do_clientqueue(void)
                free(working_ignetcfg);
 }
 
-void LogDebugEnableNetworkClient(void)
+void LogDebugEnableNetworkClient(const int n)
 {
-       NetworkClientDebugEnabled = 1;
+       NetworkClientDebugEnabled = n;
 }
 /*
  * Module entry point
@@ -1051,7 +1051,7 @@ CTDL_MODULE_INIT(network_client)
                CtdlFillSystemContext(&networker_client_CC, "CitNetworker");
                
                CtdlRegisterSessionHook(network_do_clientqueue, EVT_TIMER);
-               CtdlRegisterDebugFlagHook(HKEY("networkclient"), LogDebugEnableNetworkClient);
+               CtdlRegisterDebugFlagHook(HKEY("networkclient"), LogDebugEnableNetworkClient, &NetworkClientDebugEnabled);
 
        }
        return "networkclient";
index 9784798cc6a58a4fcc4f8b24e199e3d58ced7ffa..3d1c1dd8f45f384781df03fc184bd0a88ab2078d 100644 (file)
@@ -1214,9 +1214,9 @@ void pop3_cleanup(void)
 
 
 
-void LogDebugEnablePOP3Client(void)
+void LogDebugEnablePOP3Client(const int n)
 {
-       POP3ClientDebugEnabled = 1;
+       POP3ClientDebugEnabled = n;
 }
 
 CTDL_MODULE_INIT(pop3client)
@@ -1229,7 +1229,7 @@ CTDL_MODULE_INIT(pop3client)
                POP3FetchUrls = NewHash(1, NULL);
                CtdlRegisterSessionHook(pop3client_scan, EVT_TIMER);
                CtdlRegisterEVCleanupHook(pop3_cleanup);
-               CtdlRegisterDebugFlagHook(HKEY("pop3client"), LogDebugEnablePOP3Client);
+               CtdlRegisterDebugFlagHook(HKEY("pop3client"), LogDebugEnablePOP3Client, &POP3ClientDebugEnabled);
        }
 
        /* return our module id for the log */
index 0c7290b5cc0857ce856d43a2ce614ca2eedb11aa..c33fe9e707643c3f8ff9b9c78c278097db74b9da 100644 (file)
@@ -1086,9 +1086,9 @@ void rss_parser_cleanup(void)
        DeleteHash(&KnownNameSpaces);
 }
 
-void LogDebugEnableRSSATOMParser(void)
+void LogDebugEnableRSSATOMParser(const int n)
 {
-       RSSAtomParserDebugEnabled = 1;
+       RSSAtomParserDebugEnabled = n;
 }
 
 CTDL_MODULE_INIT(rssparser)
@@ -1177,7 +1177,7 @@ CTDL_MODULE_INIT(rssparser)
                /* we don't like these namespaces because of they shadow our usefull parameters. */
                Put(KnownNameSpaces, HKEY("http://search.yahoo.com/mrss/"), NULL, reference_free_handler);
 #endif
-               CtdlRegisterDebugFlagHook(HKEY("RSSAtomParser"), LogDebugEnableRSSATOMParser);
+               CtdlRegisterDebugFlagHook(HKEY("RSSAtomParser"), LogDebugEnableRSSATOMParser, &RSSAtomParserDebugEnabled);
                CtdlRegisterCleanupHook(rss_parser_cleanup);
        }
        return "rssparser";
index 638300feb439abdbee4bb7cb42afa3fbcd825f82..f6561e6b1fd1e1a13c0ab6130c76c41376031ebd 100644 (file)
@@ -582,9 +582,9 @@ void rss_cleanup(void)
        DeleteHash(&RSSQueueRooms);
 }
 
-void LogDebugEnableRSSClient(void)
+void LogDebugEnableRSSClient(const int n)
 {
-       RSSClientDebugEnabled = 1;
+       RSSClientDebugEnabled = n;
 }
 
 CTDL_MODULE_INIT(rssclient)
@@ -598,7 +598,7 @@ CTDL_MODULE_INIT(rssclient)
                syslog(LOG_INFO, "%s\n", curl_version());
                CtdlRegisterSessionHook(rssclient_scan, EVT_TIMER);
                CtdlRegisterEVCleanupHook(rss_cleanup);
-               CtdlRegisterDebugFlagHook(HKEY("rssclient"), LogDebugEnableRSSClient);
+               CtdlRegisterDebugFlagHook(HKEY("rssclient"), LogDebugEnableRSSClient, &RSSClientDebugEnabled);
        }
        return "rssclient";
 }
index d98a2181b084d893814c27bbbe58890a21c7f78e..dbe2c297db94d940f03d74078ac3ef5cd0b97100 100644 (file)
@@ -828,14 +828,14 @@ eReadState SMTP_C_ReadServerStatus(AsyncIO *IO)
        return Finished;
 }
 
-void LogDebugEnableSMTPClient(void)
+void LogDebugEnableSMTPClient(const int n)
 {
-       SMTPClientDebugEnabled = 1;
+       SMTPClientDebugEnabled = n;
 }
 
 CTDL_MODULE_INIT(smtp_eventclient)
 {
        if (!threading)
-               CtdlRegisterDebugFlagHook(HKEY("smtpeventclient"), LogDebugEnableSMTPClient);
+               CtdlRegisterDebugFlagHook(HKEY("smtpeventclient"), LogDebugEnableSMTPClient, &SMTPClientDebugEnabled);
        return "smtpeventclient";
 }
index 45221c514eef4a3ced49c122cadc8e8c49e14c32..04c34704b7de0bc15a0dc69d32fcbf89114463a6 100644 (file)
@@ -55,6 +55,7 @@ typedef struct __LogDebugEntry {
        CtdlDbgFunction F;
        const char *Name;
        long Len;
+       const int *LogP;
 } LogDebugEntry;
 HashList *LogDebugEntryTable = NULL;
 
@@ -332,15 +333,8 @@ long FourHash(const char *key, long length)
 
        return ret;
 }
-/*
-typedef struct __LogDebugEntry {
-       CtdlDbgFunction F;
-       const char *Name;
-       long Len;
-} LogDebugEntry;
-HashList *LogDebugEntryTable = NULL;
-*/
-void CtdlRegisterDebugFlagHook(const char *Name, long Len, CtdlDbgFunction F)
+
+void CtdlRegisterDebugFlagHook(const char *Name, long Len, CtdlDbgFunction F, const int *LogP)
 {
        LogDebugEntry *E;
        if (LogDebugEntryTable == NULL)
@@ -349,6 +343,7 @@ void CtdlRegisterDebugFlagHook(const char *Name, long Len, CtdlDbgFunction F)
        E->F = F;
        E->Name = Name;
        E->Len = Len;
+       E->LogP = LogP;
        Put(LogDebugEntryTable, Name, Len, E, NULL);
        
 }
@@ -377,7 +372,7 @@ void CtdlSetDebugLogFacilities(const char **Str, long n)
                                    (vptr != NULL))
                                {
                                        LogDebugEntry *E = (LogDebugEntry*)vptr;
-                                       E->F();
+                                       E->F(1);
                                }
                        }
                }
@@ -392,12 +387,58 @@ void CtdlSetDebugLogFacilities(const char **Str, long n)
                Pos = GetNewHashPos(LogDebugEntryTable, 0);
                while (GetNextHashPos(LogDebugEntryTable, Pos, &HKLen, &ch, &vptr)) {
                        LogDebugEntry *E = (LogDebugEntry*)vptr;
-                       E->F();
+                       E->F(1);
                }
 
                DeleteHashPos(&Pos);
        }
 }
+void cmd_log_get(char *argbuf)
+{
+       long HKLen;
+       const char *ch;
+       HashPos *Pos;
+       void *vptr;
+
+       if (CtdlAccessCheck(ac_aide)) return;
+
+       cprintf("%d Log modules enabled:\n", LISTING_FOLLOWS);
+
+       Pos = GetNewHashPos(LogDebugEntryTable, 0);
+
+       while (GetNextHashPos(LogDebugEntryTable, Pos, &HKLen, &ch, &vptr)) {
+               LogDebugEntry *E = (LogDebugEntry*)vptr;
+               cprintf("%s: %d\n", ch, *E->LogP);
+       }
+       
+       DeleteHashPos(&Pos);
+       cprintf("000\n");
+}
+void cmd_log_set(char *argbuf)
+{
+       void *vptr;
+       int lset;
+       int wlen;
+       char which[SIZ] = "";
+
+       if (CtdlAccessCheck(ac_aide)) return;
+
+       wlen = extract_token(which, argbuf, 0, '|', sizeof(which));
+       if (wlen < 0) wlen = 0;
+       lset = extract_int(argbuf, 1);
+       if (lset != 0) lset = 1;
+       if (GetHash(LogDebugEntryTable, which, wlen, &vptr) && 
+           (vptr != NULL))
+       {
+               LogDebugEntry *E = (LogDebugEntry*)vptr;
+               E->F(lset);
+               cprintf("%d %s|%d\n", CIT_OK, which, lset);
+       }
+       else {
+               cprintf("%d Log setting %s not known\n", 
+                       ERROR, which);
+       }
+}
 void CtdlDestroyDebugTable(void)
 {
 
@@ -1309,3 +1350,13 @@ void CtdlModuleStartCryptoMsgs(char *ok_response, char *nosup_response, char *er
        CtdlStartTLS (ok_response, nosup_response, error_response);
 #endif
 }
+
+
+CTDL_MODULE_INIT(modules)
+{
+       if (!threading) {
+               CtdlRegisterProtoHook(cmd_log_get, "LOGP", "Print Log-parameters");
+               CtdlRegisterProtoHook(cmd_log_set, "LOGS", "Set Log-parameters");
+       }
+       return "modules";
+}
index 0ef8e14083337390e5c3b697eebe785c6c3565c0..59dcfec3a3b93d11d3e064b1351eb3b99a016d17 100644 (file)
@@ -15,7 +15,7 @@
 /*
  */
 
-typedef void (*CtdlDbgFunction) (void);
+typedef void (*CtdlDbgFunction) (const int);
  
 
 
@@ -85,7 +85,7 @@ void CtdlDestroySearchHooks(void);
 void CtdlDestroyFixedOutputHooks(void);
 int PerformFixedOutputHooks(char *, char *, int);
 
-void CtdlRegisterDebugFlagHook(const char *Name, long len, CtdlDbgFunction F);
+void CtdlRegisterDebugFlagHook(const char *Name, long len, CtdlDbgFunction F, const int *);
 void CtdlSetDebugLogFacilities(const char **Str, long n);
 void CtdlDestroyDebugTable(void);