~ubuntu-branches/ubuntu/wily/sflphone/wily

« back to all changes in this revision

Viewing changes to daemon/src/logger.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2015-01-07 14:51:16 UTC
  • mfrom: (4.3.5 sid)
  • Revision ID: package-import@ubuntu.com-20150107145116-yxnafinf4lrdvrmx
Tags: 1.4.1-0.1ubuntu1
* Merge with Debian, remaining changes:
 - Drop soprano, nepomuk build-dep
* Drop ubuntu patches, now upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 *  as that of the covered work.
29
29
 */
30
30
 
31
 
#ifndef LOGGER_H_
32
 
#define LOGGER_H_
33
 
 
 
31
#ifndef H_LOGGER
 
32
#define H_LOGGER
 
33
 
 
34
#ifdef __cplusplus
 
35
extern "C" {
 
36
#endif
 
37
 
 
38
#include <stdint.h>
34
39
#include <pthread.h>
 
40
 
35
41
#ifdef __ANDROID__
36
 
#include <cstring>
37
42
#include <android/log.h>
38
43
#else
39
44
#include <syslog.h>
40
45
#endif
41
46
 
42
 
namespace Logger {
43
 
void log(const int, const char*, ...);
44
 
 
45
 
void setConsoleLog(bool);
46
 
void setDebugMode(bool);
47
 
bool getDebugMode();
 
47
/**
 
48
 * Print something, coloring it depending on the level
 
49
 */
 
50
void logger(const int level, const char *format, ...);
 
51
 
 
52
/**
 
53
 * Allow writing on the console
 
54
 */
 
55
void setConsoleLog(int c);
 
56
 
 
57
/**
 
58
 * When debug mode is not set, logging will not print anything
 
59
 */
 
60
void setDebugMode(int d);
 
61
 
 
62
/**
 
63
 * Return the current mode
 
64
 */
 
65
int getDebugMode(void);
 
66
 
 
67
/**
 
68
 * Thread-safe function to print the stringified contents of errno
 
69
 */
48
70
void strErr();
49
 
};
50
71
 
51
 
#define LOG_FORMAT(M, ...) "%s:%d:0x%x: " M, FILE_NAME, __LINE__, (unsigned long) pthread_self() & 0xffff, ##__VA_ARGS__
 
72
#define LOG_FORMAT(M, ...) "%s:%d:0x%x: " M, FILE_NAME, __LINE__, \
 
73
                           (unsigned long) pthread_self() & 0xffff, \
 
74
                           ##__VA_ARGS__
52
75
 
53
76
#ifndef __ANDROID__
54
77
 
57
80
#define WARN(M, ...)    LOGGER(M, LOG_WARNING, ##__VA_ARGS__)
58
81
#define INFO(M, ...)    LOGGER(M, LOG_INFO, ##__VA_ARGS__)
59
82
#define DEBUG(M, ...)   LOGGER(M, LOG_DEBUG, ##__VA_ARGS__)
60
 
#define LOGGER(M, LEVEL, ...) Logger::log(LEVEL, LOG_FORMAT(M, ##__VA_ARGS__))
 
83
#define LOGGER(M, LEVEL, ...) logger(LEVEL, LOG_FORMAT(M, ##__VA_ARGS__))
61
84
 
62
 
#else /* ANDROID */
 
85
#else /* __ANDROID__ */
63
86
 
64
87
#ifndef APP_NAME
65
88
#define APP_NAME "libsflphone"
66
 
#endif
 
89
#endif /* APP_NAME */
67
90
 
68
91
// Avoid printing whole path on android
69
 
#define FILE_NAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
 
92
#define FILE_NAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 \
 
93
                                          : __FILE__)
70
94
 
71
95
#define ERROR(M, ...)   LOGGER(M, ANDROID_LOG_ERROR, ##__VA_ARGS__)
72
96
#define WARN(M, ...)    LOGGER(M, ANDROID_LOG_WARN, ##__VA_ARGS__)
73
97
#define INFO(M, ...)    LOGGER(M, ANDROID_LOG_INFO, ##__VA_ARGS__)
74
98
#define DEBUG(M, ...)   LOGGER(M, ANDROID_LOG_DEBUG, ##__VA_ARGS__)
75
99
#define LOGGER(M, LEVEL, ...) __android_log_print(LEVEL, APP_NAME, LOG_FORMAT(M, ##__VA_ARGS__))
76
 
#endif /* ANDROID */
 
100
#endif /* __ANDROID__ */
77
101
 
78
102
#define BLACK "\033[22;30m"
79
103
#define RED "\033[22;31m"
93
117
#define WHITE "\033[01;37m"
94
118
#define END_COLOR "\033[0m"
95
119
 
96
 
#endif // LOGGER_H_
 
120
#ifdef __cplusplus
 
121
}
 
122
#endif
97
123
 
 
124
#endif // H_LOGGER