-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogging.c
More file actions
43 lines (33 loc) · 763 Bytes
/
logging.c
File metadata and controls
43 lines (33 loc) · 763 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "main.h"
void write_log(char * info)
{
time_t raw_time;
struct tm *cur_time;
char *printable_time;
time(&raw_time);
cur_time = localtime(&raw_time);
printable_time = (char *)asctime(cur_time);
printable_time[strlen(printable_time) - 1] = '\0';
FILE *fp;
fp = fopen("./echo-daemon.log", "a");
fprintf(fp, "[%s]: %s\n", printable_time, info);
fclose(fp);
}
void *logging_thread(void *log_queue)
{
struct node *n;
struct queue *q = (struct queue*)log_queue;
for(;;)
{
lock_queue(q);
n = pop(q);
if(n != NULL)
{
write_log(n->data);
free(n->data);
free(n);
}
unlock_queue(q);
}
return (void*)0;
}