-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger_test.c
71 lines (59 loc) · 1.57 KB
/
logger_test.c
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <stdio.h>
#include <unistd.h>
#include <limits.h>
#include "logger.h"
void usage(void)
{
printf("Usage: logger_test [-h] [-f filename] [-d log level] \n");
printf(" -h print this message\n");
printf(" -f log file name\n");
printf(" -d log level\n");
exit(0);
}
int main(int argc, char *argv[])
{
char c;
char *fname = NULL;
int log_level = 0;
while ((c = getopt(argc, argv, "hf:d:")) != EOF) {
switch(c) {
case 'h':
usage();
break;
case 'f':
fname = strdup(optarg);
break;
case 'd':
log_level = atoi(optarg);
break;
default:
usage();
}
}
if(logger_open(log_level, fname) < 0) {
perror("logger_open");
exit(-1);
}
print_log(DEBUG, "Hello World!\n");
print_log(INFO, "char %c, int %d long %lld\n", 'd', 3, (long long)3000);
print_log(ERROR, "double %e float %f\n", 3.0, 3.0);
char *str = "This is error message";
print_log(ERROR, "<<%-20.20s>>\n", str);
unsigned int i = 0;
while(i < 10) {
print_log(INFO, "Unsigned int %u Hexadecimal %x \n", i, INT_MAX - i);
i++;
}
i = 0;
while(i < 10) {
print_log(DEBUG, "Octal notation %o Pointer %p\n", i, str + i);
i++;
}
i = 0;
while(i < 10) {
print_log(ERROR, "Float %.2f Integer with width %*f \n", 0.01234, 2, 1.99999);
i++;
}
logger_close();
return 0;
}