Branch data Line data Source code
1 : : /**
2 : : * \file
3 : : *
4 : : * \author Georg Hopp
5 : : *
6 : : * \copyright
7 : : * Copyright © 2012 Georg Hopp
8 : : *
9 : : * This program is free software: you can redistribute it and/or modify
10 : : * it under the terms of the GNU General Public License as published by
11 : : * the Free Software Foundation, either version 3 of the License, or
12 : : * (at your option) any later version.
13 : : *
14 : : * This program is distributed in the hope that it will be useful,
15 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : : * GNU General Public License for more details.
18 : : *
19 : : * You should have received a copy of the GNU General Public License
20 : : * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 : : */
22 : :
23 : : #include <stdlib.h>
24 : : #include <stdio.h>
25 : : #include <stdarg.h>
26 : :
27 : : #include "logger/logger.h"
28 : : #include "logger/interface/logger.h"
29 : :
30 : : #include "utils/memory.h"
31 : :
32 : : const struct interface i_Logger = {
33 : : "logger",
34 : : 1
35 : : };
36 : :
37 : : void
38 : 11 : loggerLog(void * _object, logger_level level, const char * const fmt, ...) {
39 : 11 : Logger object = _object;
40 : :
41 : 11 : if (level >= object->min_level) {
42 : 10 : char * msg = NULL;
43 : 10 : size_t msg_size = 0;
44 : : va_list params;
45 : :
46 : 10 : va_start(params, fmt);
47 : 10 : msg_size = vsnprintf(NULL, msg_size, fmt, params);
48 : 10 : va_end(params);
49 : :
50 : 10 : msg = memMalloc(msg_size + 1);
51 : :
52 : 10 : va_start(params, fmt);
53 : 10 : vsnprintf(msg, msg_size + 1, fmt, params);
54 : 10 : va_end(params);
55 : :
56 : : // // ----- DEBUG ------
57 : : // do {
58 : : // struct i_Logger * iface;
59 : : //
60 : : // do {
61 : : // class_ptr class = GET_CLASS(_object);
62 : : // iface = (struct i_Logger *)IFACE_GET(class, &i_Logger);
63 : : // while ((NULL == iface || NULL == iface->log) && HAS_PARENT(class)) {
64 : : // class = class->parent;
65 : : // iface = (struct i_Logger *)IFACE_GET(class, &i_Logger);
66 : : // }
67 : : // assert(NULL != iface->log);
68 : : // } while(0);
69 : : //
70 : : // iface->log(_object, level, msg);
71 : : // } while(0);
72 : : // // ----- DEBUG ------
73 : 10 : CALL(_object, Logger, log, level, msg);
74 : :
75 : 10 : MEM_FREE(msg);
76 : : }
77 : 11 : }
78 : :
79 : : // vim: set ts=4 sw=4:
|