]> Nishi Git Mirror - mandshurica.git/commitdiff
syslog module works
authornishi <nishi@f982e544-4a7d-3444-ad1a-fde59a2a69f1>
Sat, 13 Apr 2024 02:16:21 +0000 (02:16 +0000)
committernishi <nishi@f982e544-4a7d-3444-ad1a-fde59a2a69f1>
Sat, 13 Apr 2024 02:16:21 +0000 (02:16 +0000)
git-svn-id: file:///raid/svn-main/nishi-mandshurica/trunk@8 f982e544-4a7d-3444-ad1a-fde59a2a69f1

DevForge/log.c
DevForge/main.c
Module/syslog.c

index 593b64a158579a3d2374682544745231c7fb24f1..288d03b6d854251bd785772fb858866ce91266d4 100644 (file)
 
 #include "df_log.h"
 
+#include "df_config.h"
+#include "devforge.h"
+
 #include <stdio.h>
 #include <time.h>
+#include <stdbool.h>
+#include <dlfcn.h>
+#include <string.h>
 
 void devforge_log(const char* name, const char* log) {
-       char timestr[256];
-       time_t t = time(NULL);
-       struct tm* tm = localtime(&t);
-       strftime(timestr, 255, "%Y-%m-%d %H:%M:%S%z", tm);
-       fprintf(stderr, "%s %8s %s\n", timestr, name, log);
+       bool fallback = true;
+       if(loaded_mods != NULL){
+               int i;
+               for(i = 0; loaded_mods[i] != NULL; i++){
+                       const char* type = (const char*)dlsym(loaded_mods[i], "mod_type");
+                       if(strcmp(type, DF_MOD_LOG) == 0){
+                               void(*mod_log)(const char*, const char*) = (void(*)(const char*, const char*))dlsym(loaded_mods[i], "mod_log");
+                               if(mod_log != NULL){
+                                       fallback = false;
+                                       mod_log(name, log);
+                                       break;
+                               }
+                       }
+               }
+       }
+
+       if(fallback){
+               char timestr[256];
+               time_t t = time(NULL);
+               struct tm* tm = localtime(&t);
+               strftime(timestr, 255, "%Y-%m-%d %H:%M:%S%z", tm);
+               fprintf(stderr, "%s %8s %s\n", timestr, name, log);
+       }
 }
index cb913b8776998f08fc8bbdfa1a670175e80c24b2..9288555f18d97eb9190d60bc8cf1a9106e68760b 100644 (file)
@@ -71,4 +71,5 @@ int main(int argc, char** argv) {
                int ret = devforge_load_config(PREFIX "/etc/devforge.conf");
                if(ret != 0) return ret;
        }
+       devforge_log(DF_INFO, "Hello, world!");
 }
index cc4e42cc5fe0531e10f55233cbcca3c95ed1a956..c013f36e8de2ded6b3e9618a5e2befe28cb1408c 100644 (file)
 #include "../DevForge/devforge.h"
 #include "../DevForge/df_log.h"
 
-const char type[] = DF_MOD_LOG;
+#include <syslog.h>
+#include <string.h>
+
+const char mod_type[] = DF_MOD_LOG;
 
 void(*putlog)(const char* name, const char* log);
 
@@ -39,3 +42,15 @@ void mod_init(void(*_putlog)(const char* name, const char* log)){
        putlog = _putlog;
        putlog(DF_INFO, "Syslog Module init");
 }
+
+void mod_log(const char* name, const char* log){
+       if(strcmp(name, DF_INFO) == 0){
+               syslog(LOG_INFO, log);
+       }else if(strcmp(name, DF_LOG) == 0){
+               syslog(LOG_NOTICE, log);
+       }else if(strcmp(name, DF_ERROR) == 0){
+               syslog(LOG_ERR, log);
+       }else if(strcmp(name, DF_WARN) == 0){
+               syslog(LOG_WARNING, log);
+       }
+}