aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/eina/src/examples/eina_log_03.c
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/eina/src/examples/eina_log_03.c')
-rw-r--r--libraries/eina/src/examples/eina_log_03.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/libraries/eina/src/examples/eina_log_03.c b/libraries/eina/src/examples/eina_log_03.c
new file mode 100644
index 0000000..8dbe19e
--- /dev/null
+++ b/libraries/eina/src/examples/eina_log_03.c
@@ -0,0 +1,78 @@
1//Compile with:
2//gcc -Wall -o eina_log_03 eina_log_03.c `pkg-config --cflags --libs eina`
3
4#include <stdlib.h>
5#include <stdio.h>
6
7#include <Eina.h>
8
9#define log(fmt, ...) \
10 eina_log_print(EINA_LOG_LEVEL_ERR, __FILE__, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__)
11
12typedef struct _Data Data;
13
14struct _Data
15{
16 int to_stderr;
17};
18
19void print_cb(const Eina_Log_Domain *domain,
20 Eina_Log_Level level,
21 const char *file,
22 const char *fnc,
23 int line,
24 const char *fmt,
25 void *data,
26 va_list args)
27{
28 Data *d;
29 FILE *output;
30 char *str;
31
32 d = (Data*)data;
33 if (d->to_stderr)
34 {
35 output = stderr;
36 str = "stderr";
37 }
38 else
39 {
40 output = stdout;
41 str = "stdout";
42 }
43
44 fprintf(output, "%s:%s:%s (%d) %s: ",
45 domain->domain_str, file, fnc, line, str);
46 vfprintf(output, fmt, args);
47 putc('\n', output);
48}
49
50void test(Data *data, int i)
51{
52 if (i < 0)
53 data->to_stderr = 0;
54 else
55 data->to_stderr = 1;
56
57 EINA_LOG_INFO("Log message...");
58}
59
60int main(void)
61{
62 Data data;
63
64 if (!eina_init())
65 {
66 printf("log during the initialization of Eina_Log module\n");
67 return EXIT_FAILURE;
68 }
69
70 eina_log_print_cb_set(print_cb, &data);
71
72 test(&data, -1);
73 test(&data, 0);
74
75 eina_shutdown();
76
77 return EXIT_SUCCESS;
78}