#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);
+ }
}
#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);
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);
+ }
+}