34 #include <sys/types.h> 99 ret->pro_name = g_strdup(SCHE_PRONAME);
101 ret->pro_name = g_strdup(pro_name);
102 ret->pro_pid = pro_pid;
105 if(strcmp(log_name,
"stderr") != 0 && strcmp(log_name,
"stdout") != 0 &&
106 (stat(log_name, &stats) == 0) && S_ISDIR(stats.st_mode))
107 ret->log_name = g_strdup_printf(
"%s/fossology.log", log_name);
109 ret->log_name = g_strdup(log_name);
112 if (strcmp(ret->log_name,
"stderr") == 0) { ret->log_file = stderr; }
113 else if(strcmp(ret->log_name,
"stdout") == 0) { ret->log_file = stdout; }
114 else { ret->log_file = fopen(ret->log_name,
"a"); }
117 if(ret->log_file == NULL)
119 ERROR(
"could not open log file \"%s\"", ret->log_name);
120 g_free(ret->pro_name);
121 g_free(ret->log_name);
142 ret->
pro_name = g_strdup(SCHE_PRONAME);
150 V_JOB(
"NEW_LOG: log_name: \"%s\", pro_name: \"%s\", pro_pid: %d, log_file: %p\n",
199 if(log == NULL || log->
log_file == NULL)
227 static int n_line = 1;
230 time_t t = time(NULL);
238 strftime(time_buf,
sizeof(time_buf),
"%F %T",localtime(&t));
240 tmp = g_strdup_vprintf(fmt, args);
241 e_line = tmp[strlen(tmp) - 1] ==
'\n';
242 curr = strtok(tmp,
"\n");
245 if(n_line && fprintf(log->
log_file,
"%s %s [%d] :: ", time_buf,
249 if(fprintf(log->
log_file,
"%s", curr) == 0)
252 n_line = ((curr = strtok(NULL,
"\n")) != NULL);
253 if(n_line && fprintf(log->
log_file,
"\n") == 0)
260 if(fprintf(log->
log_file,
"\n") == 0)
295 pass->
msg = g_strdup_vprintf(fmt, args);
static void log_event(scheduler_t *scheduler, log_event_args *pass)
void log_destroy(log_t *log)
Free memory associated with the log file.
FILE * log_file
The log file itself.
int vlprintf(log_t *log, const char *fmt, va_list args)
The provides the same functionality for lprintf as vprintf does for printf.
int clprintf(log_t *log, char *s_name, uint16_t s_line, const char *fmt,...)
log_t * log_new_FILE(FILE *log_file, gchar *log_name, gchar *pro_name, pid_t pro_pid)
Creates a log file structure based on an already created FILE*.
gchar * pro_name
What should be printed as the process name.
void event_signal_ext(void *func, void *args, char *name, char *s_name, uint16_t s_line)
uint16_t s_line
Sample source line number.
log_t * log_new(gchar *log_name, gchar *pro_name, pid_t pro_pid)
Creates a new log.
int lprintf(log_t *log, const char *fmt,...)
Main logging function.
gchar * log_name
The name of the log file that will be printed to.
Event handling operations.
pid_t pro_pid
The pid of the process.
gchar * msg
Message to log.
GThread * main_thread
Pointer to the main thread.
Header file for the scheduler.
char * s_name
Sample source file name.