luna-sysmgr-common
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
Logging.h
Go to the documentation of this file.
1
/* @@@LICENSE
2
*
3
* Copyright (c) 2008-2012 Hewlett-Packard Development Company, L.P.
4
*
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
* you may not use this file except in compliance with the License.
7
* You may obtain a copy of the License at
8
*
9
* http://www.apache.org/licenses/LICENSE-2.0
10
*
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
16
*
17
* LICENSE@@@ */
18
19
20
21
22
#ifndef LOGGING_H
23
#define LOGGING_H
24
25
#include "
Common.h
"
26
27
#include <stdio.h>
28
#include <glib.h>
29
30
#if !defined(TARGET_DESKTOP)
31
#include <PmLogLib.h>
32
#endif
33
34
#ifdef __cplusplus
35
extern
"C"
{
36
#endif
37
38
bool
LunaChannelEnabled
(
const
char
* channel);
39
40
#ifdef ENABLE_TRACING
41
42
class
SysMgrTracer
43
{
44
public
:
45
SysMgrTracer(
const
char
*
function
,
const
char
* file,
int
line);
46
virtual
~SysMgrTracer();
47
48
private
:
49
const
char
* m_function;
50
const
int
m_indentSpaces;
51
};
52
53
#define SYSMGR_TRACE() SysMgrTracer __sysmgrtracer(__PRETTY_FUNCTION__, __FILE__, __LINE__)
54
55
#else
56
#define SYSMGR_TRACE()
57
#endif // ENABLE_TRACING
58
59
#ifndef NO_LOGGING
60
61
#define luna_log(channel, ...) \
62
do { \
63
if (LunaChannelEnabled(channel)) { \
64
fprintf(stdout, "LOG<%s>:(%s:%d) ", channel, __PRETTY_FUNCTION__, __LINE__); \
65
fprintf(stdout, __VA_ARGS__); \
66
fprintf(stdout, "\n"); \
67
} \
68
} while(0)
69
70
#define luna_warn(channel, ...) \
71
do { \
72
if (LunaChannelEnabled(channel)) { \
73
fprintf(stdout, "WARN<%s>:(%s:%d) ", channel, __PRETTY_FUNCTION__, __LINE__); \
74
fprintf(stdout, __VA_ARGS__); \
75
fprintf(stdout, "\n"); \
76
} \
77
} while(0)
78
79
#else // NO_LOGGING
80
81
#define luna_log(channel, ...) (void)0
82
#define luna_warn(channel, ...) (void)0
83
84
#endif // NO_LOGGING
85
86
#define luna_critical(channel, ...) \
87
do { \
88
fprintf(stdout, "CRITICAL<%s>:(%s:%d) ", channel, __PRETTY_FUNCTION__, __LINE__); \
89
fprintf(stdout, __VA_ARGS__); \
90
fprintf(stdout, "\n"); \
91
} while(0)
92
93
#define luna_assert(val) \
94
do { \
95
if (G_LIKELY(val)) {} \
96
else { \
97
g_critical("FATAL:(%s:%d) %s", __PRETTY_FUNCTION__, __LINE__, #val); \
98
int* p = 0; \
99
*p = 0; \
100
} \
101
} while(0) \
102
103
104
105
// Logging routed to PmLogLib on device
106
107
#if defined(TARGET_DESKTOP)
108
109
#define LunaLogContext void*
110
111
#define luna_syslog(context, level, message) \
112
g_log_default_handler(0, level, message, 0)
113
114
#define luna_syslogV(context, level, ...) \
115
g_log(0, level, __VA_ARGS__)
116
117
#else
118
119
PmLogLevel
GLogToPmLogLevel
(GLogLevelFlags flags);
120
121
#define LunaLogContext PmLogContext
122
123
#define luna_syslog(context, level, message) \
124
PmLogPrint((PmLogContext) context, GLogToPmLogLevel(level), "%s", message)
125
126
#define luna_syslogV(context, level, ...) \
127
PmLogPrint((PmLogContext) context, GLogToPmLogLevel(level), __VA_ARGS__)
128
129
#endif
130
131
LunaLogContext
syslogContextGlobal
();
132
LunaLogContext
syslogContextJavascript
();
133
134
void
logInit
();
135
void
logFilter
(
const
gchar *log_domain, GLogLevelFlags log_level,
const
gchar *message, gpointer unused_data);
136
138
#define VERIFY(t) (G_LIKELY(t) || (logFailedVerify(#t, __FILE__, __LINE__, __FUNCTION__), false))
139
141
#define CHECK(t) (G_LIKELY(t) || (logCheck(#t, __FILE__, __LINE__, __FUNCTION__), false))
142
144
#define FAILURE(m) logFailure(m, __FILE__, __LINE__, __FUNCTION__)
145
146
#define SHOULD_NOT_REACH_HERE FAILURE("This line should never be reached")
147
149
void
logFailedVerify
(
const
gchar * test,
const
gchar * file,
int
line,
const
gchar *
function
);
150
void
logFailure
(
const
gchar * message,
const
gchar * file,
int
line,
const
gchar *
function
);
151
void
logCheck
(
const
gchar * message,
const
gchar * file,
int
line,
const
gchar *
function
);
152
153
#ifdef __cplusplus
154
}
155
157
class
LogIndent {
158
public
:
159
LogIndent(
const
char
* indent);
160
~LogIndent();
161
162
private
:
163
const
char
* mIndent;
164
};
165
166
#endif
167
168
#endif
/* LOGGING_H */
luna-sysmgr-common
include
Logging.h
Generated on Fri Jun 21 2013 00:48:48 for luna-sysmgr-common by
1.8.3.1