Subversion Repositories Tewi

Rev

Rev 12 | Rev 182 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 12 Rev 62
Line 1... Line 1...
1
/* $Id: log.c 12 2024-09-13 13:36:03Z nishi $ */
1
/* $Id: log.c 62 2024-09-18 20:02:26Z nishi $ */
2
 
2
 
3
#include "cm_log.h"
3
#include "cm_log.h"
4
 
4
 
5
#include "cm_string.h"
5
#include "cm_string.h"
6
 
6
 
-
 
7
#include <time.h>
7
#include <stdio.h>
8
#include <stdio.h>
8
#include <stdbool.h>
9
#include <stdbool.h>
9
#include <string.h>
10
#include <string.h>
10
#include <stdlib.h>
11
#include <stdlib.h>
11
#include <stdarg.h>
12
#include <stdarg.h>
12
 
13
 
-
 
14
FILE* logfile;
-
 
15
 
13
bool cm_do_log = false;
16
bool cm_do_log = false;
14
 
17
 
15
#define LOGNAME_LENGTH 12
18
#define LOGNAME_LENGTH 12
16
 
19
 
-
 
20
void cm_force_log(const char* log) {
-
 
21
	time_t t = time(NULL);
-
 
22
	struct tm* tm = localtime(&t);
-
 
23
	char date[513];
-
 
24
	strftime(date, 512, "%a %b %d %H:%M:%S %Z %Y", tm);
-
 
25
	fprintf(logfile, "[%s] %s\n", date, log);
-
 
26
	fflush(logfile);
-
 
27
}
-
 
28
 
17
void cm_log(const char* name, const char* log, ...) {
29
void cm_log(const char* name, const char* log, ...) {
18
	if(!cm_do_log) return;
30
	if(!cm_do_log) return;
19
	va_list args;
31
	va_list args;
20
	va_start(args, log);
32
	va_start(args, log);
21
	char namebuf[LOGNAME_LENGTH + 1];
33
	char namebuf[LOGNAME_LENGTH + 1];
Line 54... Line 66...
54
			result = cm_strcat(tmp, cbuf);
66
			result = cm_strcat(tmp, cbuf);
55
			free(tmp);
67
			free(tmp);
56
		}
68
		}
57
	}
69
	}
58
 
70
 
59
	fprintf(stderr, "%s %s\n", namebuf, result);
71
	fprintf(logfile, "%s %s\n", namebuf, result);
60
	va_end(args);
72
	va_end(args);
61
 
73
 
62
	free(result);
74
	free(result);
63
}
75
}