23 #include <sys/types.h>
59 lprintf(pass->log,
"%s", pass->msg);
88 ret->pro_name = g_strdup(SCHE_PRONAME);
90 ret->pro_name = g_strdup(pro_name);
91 ret->pro_pid = pro_pid;
94 if(strcmp(log_name,
"stderr") != 0 && strcmp(log_name,
"stdout") != 0 &&
95 (stat(log_name, &stats) == 0) && S_ISDIR(stats.st_mode))
96 ret->log_name = g_strdup_printf(
"%s/fossology.log", log_name);
98 ret->log_name = g_strdup(log_name);
101 if (strcmp(ret->log_name,
"stderr") == 0) { ret->log_file = stderr; }
102 else if(strcmp(ret->log_name,
"stdout") == 0) { ret->log_file = stdout; }
103 else { ret->log_file = fopen(ret->log_name,
"a"); }
106 if(ret->log_file == NULL)
108 ERROR(
"could not open log file \"%s\"", ret->log_name);
109 g_free(ret->pro_name);
110 g_free(ret->log_name);
131 ret->
pro_name = g_strdup(SCHE_PRONAME);
139 V_JOB(
"NEW_LOG: log_name: \"%s\", pro_name: \"%s\", pro_pid: %d, log_file: %p\n",
188 if(log == NULL || log->
log_file == NULL)
216 static int n_line = 1;
219 time_t t = time(NULL);
227 strftime(time_buf,
sizeof(time_buf),
"%F %T",localtime(&t));
229 tmp = g_strdup_vprintf(fmt, args);
230 e_line = tmp[strlen(tmp) - 1] ==
'\n';
231 curr = strtok(tmp,
"\n");
234 if(n_line && fprintf(log->
log_file,
"%s %s [%d] :: ", time_buf,
238 if(fprintf(log->
log_file,
"%s", curr) == 0)
241 n_line = ((curr = strtok(NULL,
"\n")) != NULL);
242 if(n_line && fprintf(log->
log_file,
"\n") == 0)
249 if(fprintf(log->
log_file,
"\n") == 0)
284 pass->msg = g_strdup_vprintf(fmt, args);
void event_signal_ext(void *func, void *args, char *name, char *s_name, uint16_t s_line)
Event handling operations.
int lprintf(log_t *log, const char *fmt,...)
Main logging function.
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*.
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,...)
static void log_event(scheduler_t *scheduler, log_event_args *pass)
log_t * log_new(gchar *log_name, gchar *pro_name, pid_t pro_pid)
Creates a new log.
void log_destroy(log_t *log)
Free memory associated with the log file.
GThread * main_thread
Pointer to the main thread.
Header file for the scheduler.
gchar * msg
Message to log.
gchar * log_name
The name of the log file that will be printed to.
gchar * pro_name
What should be printed as the process name.
FILE * log_file
The log file itself.
pid_t pro_pid
The pid of the process.
char * s_name
Sample source file name.
uint16_t s_line
Sample source line number.