Release 1.0.3
[platform/upstream/gsignond.git] / include / gsignond / gsignond-log.h
1 /* vi: set et sw=4 ts=4 cino=t0,(0: */
2 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 /*
4  * This file is part of gsignond
5  *
6  * Copyright (C) 2012-2013 Intel Corporation.
7  *
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22  * 02110-1301 USA
23  */
24
25 #ifndef __GSIGNOND_LOG_H_
26 #define __GSIGNOND_LOG_H_
27
28 #include "config.h"
29
30 #include <glib.h>
31
32 #include <execinfo.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35
36 /**
37  * SECTION:gsignond-log
38  * @short_description: logging facilities
39  * @title: Logging
40  * @include: gsignond/gsignond-log.h
41  *
42  * <filename>gsignond/gsignond-log.h</filename> file contains logging macros 
43  * that plugins and extensions should use for debugging and tracing.
44  * 
45  * For example:
46  * |[    INFO("Plugin %s initialized", plugin_mechanism); ]|
47  */
48
49 /**
50  * TRACEBACK:
51  * 
52  * This macro prints the current function call stack to stderr.
53  */
54 #define TRACEBACK() \
55 { \
56     void *array[256];\
57     size_t size, i;\
58     char **strings;\
59 \
60     fprintf (stderr, "Backtrace for: %s %s\n", __FILE__, __PRETTY_FUNCTION__); \
61     size = backtrace (array, 256);\
62     strings = backtrace_symbols (array, size);\
63     if (strings) { \
64         for (i=0; i <size; i++) fprintf (stderr, "\t%s\n", strings[i]);\
65         free (strings);\
66     }\
67 }
68
69 /**
70  * ERR:
71  * @frmt: format string for the message
72  * @...: arguments for the format string
73  * 
74  * Use this macro to log error messages. GSignond will take care of
75  * correctly saving them.
76  */
77 #define ERR(frmt, args...)  g_critical("%f %s:%d %s " frmt , \
78         g_get_monotonic_time()*1.0e-6, __FILE__, __LINE__, \
79         __PRETTY_FUNCTION__, ##args)
80
81 /**
82  * WARN:
83  * @frmt: format string for the message
84  * @...: arguments for the format string
85  * 
86  * Use this macro to log warning messages. GSignond will take care of
87  * correctly saving them.
88  */
89 #define WARN(frmt, args...) g_warning("%f %s:%d %s " frmt , \
90         g_get_monotonic_time()*1.0e-6, __FILE__, __LINE__, \
91         __PRETTY_FUNCTION__, ##args)
92
93 #ifdef ENABLE_DEBUG
94 /**
95  * INFO:
96  * @frmt: format string for the message
97  * @...: arguments for the format string
98  * 
99  * Use this macro to log informational messages. GSignond will take care of
100  * correctly saving them.
101  */
102 #define INFO(frmt, args...) g_message("%f %s:%d %s " frmt , \
103         g_get_monotonic_time()*1.0e-6, __FILE__, __LINE__, \
104         __PRETTY_FUNCTION__, ##args)
105
106 /**
107  * DBG:
108  * @frmt: format string for the message
109  * @...: arguments for the format string
110  * 
111  * Use this macro to log debug messages. GSignond will take care of
112  * correctly saving them.
113  */
114 #define DBG(frmt, args...)  g_debug("%f %s:%d %s " frmt , \
115         g_get_monotonic_time()*1.0e-6, __FILE__, __LINE__, \
116         __PRETTY_FUNCTION__, ##args)
117 #else
118 # define INFO(frmt, args...)
119 # define DBG(frmt, args...)
120 #endif
121
122 #endif /* __GSIGNOND_LOG_H_ */