diff options
author | Maxim Biro <nurupo.contributions@gmail.com> | 2015-12-31 01:24:31 -0500 |
---|---|---|
committer | Maxim Biro <nurupo.contributions@gmail.com> | 2015-12-31 01:24:31 -0500 |
commit | c50781a2b7d0ab56acb31b8f79df2e69f9f74b8b (patch) | |
tree | 6d120de273d14850689eda796c694f6e4753cfb1 /other/bootstrap_daemon/src/log.h | |
parent | bfc3c4eaac4eec6a2e714b7483b646d8ee21efc9 (diff) |
Make logger a global object instead of an instance
Passing Logger object into every function isn't fun. See for yourself:
something as simple as a public key printing function turns from
>void print_public_key(const uint8_t *public_key)
to
>void print_public_key(Logger *logger, const uint8_t *public_key)
Diffstat (limited to 'other/bootstrap_daemon/src/log.h')
-rw-r--r-- | other/bootstrap_daemon/src/log.h | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/other/bootstrap_daemon/src/log.h b/other/bootstrap_daemon/src/log.h new file mode 100644 index 00000000..7e5dce99 --- /dev/null +++ b/other/bootstrap_daemon/src/log.h | |||
@@ -0,0 +1,61 @@ | |||
1 | /* log.h | ||
2 | * | ||
3 | * Tox DHT bootstrap daemon. | ||
4 | * | ||
5 | * Copyright (C) 2015 Tox project All Rights Reserved. | ||
6 | * | ||
7 | * This file is part of Tox. | ||
8 | * | ||
9 | * Tox 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 | * Tox 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 Tox. If not, see <http://www.gnu.org/licenses/>. | ||
21 | * | ||
22 | */ | ||
23 | |||
24 | #ifndef LOG_H | ||
25 | #define LOG_H | ||
26 | |||
27 | typedef enum LOGGER_BACKEND { | ||
28 | LOGGER_BACKEND_SYSLOG, | ||
29 | LOGGER_BACKEND_STDOUT | ||
30 | } LOGGER_BACKEND; | ||
31 | |||
32 | typedef enum LOG_LEVEL { | ||
33 | LOG_LEVEL_INFO, | ||
34 | LOG_LEVEL_WARNING, | ||
35 | LOG_LEVEL_ERROR | ||
36 | } LOG_LEVEL; | ||
37 | |||
38 | /** | ||
39 | * Initializes logger. | ||
40 | * @param backend Specifies which backend to use. | ||
41 | * @return true on success, flase if log is already opened. | ||
42 | */ | ||
43 | bool open_log(LOGGER_BACKEND backend); | ||
44 | |||
45 | /** | ||
46 | * Releases all used resources by the logger. | ||
47 | * @return true on success, flase if log is already closed. | ||
48 | */ | ||
49 | bool close_log(); | ||
50 | |||
51 | /** | ||
52 | * Logs a message. | ||
53 | * @param level Log level to use. | ||
54 | * @param format printf-like format string. | ||
55 | * @param ... Zero or more arguments, similar to printf function. | ||
56 | * @return true on success, flase if log is closed. | ||
57 | */ | ||
58 | bool log(LOG_LEVEL level, const char *format, ...); | ||
59 | |||
60 | |||
61 | #endif // LOG_H | ||