~ubuntu-branches/ubuntu/vivid/dleyna-core/vivid

« back to all changes in this revision

Viewing changes to libdleyna/core/log.h

  • Committer: Package Import Robot
  • Author(s): Emanuele Aina
  • Date: 2013-06-07 13:51:34 UTC
  • Revision ID: package-import@ubuntu.com-20130607135134-606qkw7c8sskizvm
Tags: upstream-0.1.0
ImportĀ upstreamĀ versionĀ 0.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * dLeyna
 
3
 *
 
4
 * Copyright (C) 2012-2013 Intel Corporation. All rights reserved.
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify it
 
7
 * under the terms and conditions of the GNU Lesser General Public License,
 
8
 * version 2.1, as published by the Free Software Foundation.
 
9
 *
 
10
 * This program is distributed in the hope it will be useful, but WITHOUT
 
11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
 
13
 * for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU Lesser General Public License
 
16
 * along with this program; if not, write to the Free Software Foundation, Inc.,
 
17
 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
 
18
 *
 
19
 * Ludovic Ferrandis <ludovic.ferrandis@intel.com>
 
20
 *
 
21
 */
 
22
 
 
23
#ifndef DLEYNA_LOG_H__
 
24
#define DLEYNA_LOG_H__
 
25
 
 
26
#include <glib.h>
 
27
#include <syslog.h>
 
28
 
 
29
enum dleyna_log_type_t_ {
 
30
        DLEYNA_LOG_TYPE_SYSLOG = 0,
 
31
        DLEYNA_LOG_TYPE_GLIB,
 
32
        DLEYNA_LOG_TYPE_FILE
 
33
};
 
34
typedef enum dleyna_log_type_t_ dleyna_log_type_t;
 
35
 
 
36
void dleyna_log_init(const char *program);
 
37
 
 
38
void dleyna_log_finalize(void);
 
39
 
 
40
void dleyna_log_update_type_level(dleyna_log_type_t log_type, int log_level);
 
41
 
 
42
void dleyna_log_trace(int priority, GLogLevelFlags flags,
 
43
                      const char *format, ...)
 
44
                                        __attribute__((format(printf, 3, 4)));
 
45
 
 
46
/* Generic Logging macro
 
47
 */
 
48
#ifdef DLEYNA_DEBUG_ENABLED
 
49
        #define DLEYNA_LOG_HELPER(priority, flags, fmt, ...)    \
 
50
                do { \
 
51
                        dleyna_log_trace(priority, flags, "%s : %s() --- " fmt,\
 
52
                                      __FILE__, __func__, ## __VA_ARGS__); \
 
53
                } while (0)
 
54
#else
 
55
        #define DLEYNA_LOG_HELPER(priority, flags, fmt, ...) \
 
56
                do { \
 
57
                        dleyna_log_trace(priority, flags, fmt, ## __VA_ARGS__);\
 
58
                } while (0)
 
59
#endif
 
60
 
 
61
 
 
62
/* Logging macro for error messages
 
63
 */
 
64
#if DLEYNA_LOG_LEVEL & DLEYNA_LOG_LEVEL_ERROR
 
65
        #define DLEYNA_LOG_ERROR(...) \
 
66
                DLEYNA_LOG_HELPER(LOG_ERR, G_LOG_LEVEL_ERROR, __VA_ARGS__, 0)
 
67
#else
 
68
        #define DLEYNA_LOG_ERROR(...)
 
69
#endif
 
70
 
 
71
 
 
72
/* Logging macro for critical messages
 
73
 */
 
74
#if DLEYNA_LOG_LEVEL & DLEYNA_LOG_LEVEL_CRITICAL
 
75
        #define DLEYNA_LOG_CRITICAL(...) \
 
76
                DLEYNA_LOG_HELPER(LOG_CRIT, G_LOG_LEVEL_CRITICAL, \
 
77
                                  __VA_ARGS__, 0)
 
78
#else
 
79
        #define DLEYNA_LOG_CRITICAL(...)
 
80
#endif
 
81
 
 
82
 
 
83
/* Logging macro for warning messages
 
84
 */
 
85
#if DLEYNA_LOG_LEVEL & DLEYNA_LOG_LEVEL_WARNING
 
86
        #define DLEYNA_LOG_WARNING(...) \
 
87
                DLEYNA_LOG_HELPER(LOG_WARNING, G_LOG_LEVEL_WARNING, \
 
88
                                  __VA_ARGS__, 0)
 
89
#else
 
90
        #define DLEYNA_LOG_WARNING(...)
 
91
#endif
 
92
 
 
93
 
 
94
/* Logging macro for messages
 
95
 */
 
96
#if DLEYNA_LOG_LEVEL & DLEYNA_LOG_LEVEL_MESSAGE
 
97
        #define DLEYNA_LOG_MESSAGE(...) \
 
98
                DLEYNA_LOG_HELPER(LOG_NOTICE, G_LOG_LEVEL_MESSAGE, \
 
99
                                  __VA_ARGS__, 0)
 
100
#else
 
101
        #define DLEYNA_LOG_MESSAGE(...)
 
102
#endif
 
103
 
 
104
 
 
105
/* Logging macro for informational messages
 
106
 */
 
107
#if DLEYNA_LOG_LEVEL & DLEYNA_LOG_LEVEL_INFO
 
108
        #define DLEYNA_LOG_INFO(...) \
 
109
                DLEYNA_LOG_HELPER(LOG_INFO, G_LOG_LEVEL_INFO, __VA_ARGS__, 0)
 
110
#else
 
111
        #define DLEYNA_LOG_INFO(...)
 
112
#endif
 
113
 
 
114
 
 
115
/* Logging macro for debug messages
 
116
 */
 
117
#if DLEYNA_LOG_LEVEL & DLEYNA_LOG_LEVEL_DEBUG
 
118
        #define DLEYNA_LOG_DEBUG(...) \
 
119
                DLEYNA_LOG_HELPER(LOG_DEBUG, G_LOG_LEVEL_DEBUG, __VA_ARGS__, 0)
 
120
#else
 
121
        #define DLEYNA_LOG_DEBUG(...)
 
122
#endif
 
123
 
 
124
 
 
125
/* Logging macro to display an empty line
 
126
 */
 
127
#if DLEYNA_LOG_LEVEL & DLEYNA_LOG_LEVEL_DEBUG
 
128
        #define DLEYNA_LOG_DEBUG_NL() \
 
129
                do { \
 
130
                        dleyna_log_trace(LOG_DEBUG, G_LOG_LEVEL_DEBUG, " "); \
 
131
                } while (0)
 
132
#else
 
133
        #define DLEYNA_LOG_DEBUG_NL()
 
134
#endif
 
135
 
 
136
#endif /* DLEYNA_LOG_H__ */