use dlog to print log
[adaptation/xorg/driver/xserver-xorg-module-xdbg.git] / lib / xdbg_log.h
1 /**************************************************************************
2
3 xdbg
4
5 Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
6
7 Contact: Boram Park <boram1288.park@samsung.com>
8          Sangjin LEE <lsj119@samsung.com>
9
10 Permission is hereby granted, free of charge, to any person obtaining a
11 copy of this software and associated documentation files (the
12 "Software"), to deal in the Software without restriction, including
13 without limitation the rights to use, copy, modify, merge, publish,
14 distribute, sub license, and/or sell copies of the Software, and to
15 permit persons to whom the Software is furnished to do so, subject to
16 the following conditions:
17
18 The above copyright notice and this permission notice (including the
19 next paragraph) shall be included in all copies or substantial portions
20 of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
25 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 **************************************************************************/
31
32 #if defined(XDBG_CLIENT)
33 #error "This header is not for client."
34 #endif
35
36 #ifndef __XDBG_LOG_H__
37 #define __XDBG_LOG_H__
38
39 #include <errno.h>
40 #include <stdlib.h>
41 #include <os.h>
42 #include <dlog.h>
43
44 // Masks
45 #define XLOG_MASK_LOGLEVEL   0x000000FF
46 #define XLOG_MASK_OPTIONS    0xFFFFFF00
47
48 // LogLevels
49 enum
50 {
51     XLOG_LEVEL_0,
52     XLOG_LEVEL_1,
53     XLOG_LEVEL_2,
54     XLOG_LEVEL_3,
55     XLOG_LEVEL_4,
56     XLOG_LEVEL_MAX,
57     XLOG_LEVEL_DEFAULT = XLOG_LEVEL_3
58 };
59
60 #define XLOG_LEVEL_DEBUG    XLOG_LEVEL_0
61 #define XLOG_LEVEL_TRACE    XLOG_LEVEL_1
62 #define XLOG_LEVEL_INFO     XLOG_LEVEL_2
63 #define XLOG_LEVEL_WARNING  XLOG_LEVEL_3
64 #define XLOG_LEVEL_ERROR    XLOG_LEVEL_4
65
66 // Log Options
67 #define XLOG_OPTION_KLOG        (1 << 8)
68 #define XLOG_OPTION_SLOG        (1 << 9)
69 #define XLOG_OPTION_XORG        (1 << 10)
70 #define XLOG_OPTION_SECURE      (1 << 11)   /* print secure log */
71
72 typedef enum
73 {
74     MODE_NAME_ONLY,
75     MODE_WITH_STATUS
76 } LOG_ENUM_MODE;
77
78 int   xDbgLogEnumModules (LOG_ENUM_MODE mode, char *buf, int *remain);
79 int   xDbgLogSetLevel    (unsigned int module, int level);
80 void* xDbgLog            (unsigned int module, int logoption, const char *file, int line, const char *f, ...);
81
82 // defines
83 #define XLOG_DEBUG(mod, ARG...)    xDbgLog(mod, XLOG_LEVEL_DEBUG, __FILE__, __LINE__, ##ARG)
84 #define XLOG_TRACE(mod, ARG...)    xDbgLog(mod, XLOG_LEVEL_TRACE, __FILE__, __LINE__, ##ARG)
85 #define XLOG_INFO(mod, ARG...)     xDbgLog(mod, XLOG_LEVEL_INFO, __FILE__, __LINE__, ##ARG)
86 #define XLOG_WARNING(mod, ARG...)  xDbgLog(mod, XLOG_LEVEL_WARNING, __FILE__, __LINE__, ##ARG)
87 #define XLOG_ERROR(mod, ARG...)    xDbgLog(mod, XLOG_LEVEL_ERROR, __FILE__, __LINE__, ##ARG)
88 #define XLOG_KLOG(mod, ARG...)     xDbgLog(mod, XLOG_LEVEL_INFO|XLOG_OPTION_KLOG, __FILE__, __LINE__, ##ARG)
89 #define XLOG_SLOG(mod, ARG...)     xDbgLog(mod, XLOG_LEVEL_INFO|XLOG_OPTION_SLOG, __FILE__, __LINE__, ##ARG)
90 #define XLOG_XORG(mod, ARG...)     xDbgLog(mod, XLOG_LEVEL_INFO|XLOG_OPTION_XORG, __FILE__, __LINE__, ##ARG)
91 #define XLOG_SECURE(mod, ARG...)   xDbgLog(mod, XLOG_LEVEL_INFO|XLOG_OPTION_SECURE, __FILE__, __LINE__, ##ARG)
92
93 #define XDBG_DEBUG(mod, fmt, ARG...)      XLOG_DEBUG(mod, "[%s] "fmt, __FUNCTION__, ##ARG)
94 #define XDBG_TRACE(mod, fmt, ARG...)      XLOG_TRACE(mod, "[%s] "fmt, __FUNCTION__, ##ARG)
95 #define XDBG_INFO(mod, fmt, ARG...)       XLOG_INFO(mod, "[%s] "fmt, __FUNCTION__, ##ARG)
96 #define XDBG_WARNING(mod, fmt, ARG...)    XLOG_WARNING(mod, "[%s] "fmt, __FUNCTION__, ##ARG)
97 #define XDBG_ERROR(mod, fmt, ARG...)      XLOG_ERROR(mod, "[%s] "fmt, __FUNCTION__, ##ARG)
98 #define XDBG_ERRNO(mod, fmt, ARG...)      XLOG_ERROR(mod, "[%s](err=%s(%d)) "fmt, __FUNCTION__, strerror(errno), errno, ##ARG)
99 #define XDBG_KLOG(mod, fmt, ARG...)       XLOG_KLOG(mod, "[%s] "fmt, __FUNCTION__, ##ARG)
100 #define XDBG_SLOG(mod, fmt, ARG...)       XLOG_SLOG(mod, "[%s] "fmt, __FUNCTION__, ##ARG)
101 #define XDBG_XORG(mod, fmt, ARG...)       XLOG_XORG(mod, "[%s] "fmt, __FUNCTION__, ##ARG)
102
103 /* _SECURE_LOG defined by system, <dlog.h> */
104 #ifdef _SECURE_LOG
105 #define XDBG_SECURE(mod, fmt, ARG...)     XLOG_SECURE(mod, "[%s] "fmt, __FUNCTION__, ##ARG)
106 #else
107 #define XDBG_SECURE(mod, fmt, ARG...)     (0)
108 #endif
109
110 #define XDBG_NEVER_GET_HERE(mod)          XLOG_ERROR(mod, "[%s:%d] ** NEVER GET HERE **\n", __FUNCTION__,__LINE__)
111
112 #define XDBG_WARNING_IF_FAIL(cond)         {if (!(cond)) { ErrorF ("[%s] '%s' failed.\n", __FUNCTION__, #cond);}}
113 #define XDBG_RETURN_IF_FAIL(cond)          {if (!(cond)) { ErrorF ("[%s] '%s' failed.\n", __FUNCTION__, #cond); return; }}
114 #define XDBG_RETURN_VAL_IF_FAIL(cond, val) {if (!(cond)) { ErrorF ("[%s] '%s' failed.\n", __FUNCTION__, #cond); return val; }}
115 #define XDBG_RETURN_VAL_IF_ERRNO(cond, val, errno)       {if (!(cond)) { ErrorF ("[%s] '%s' failed. (err=%s(%d))\n", __FUNCTION__, #cond, strerror(errno), errno); return val; }}
116 #define XDBG_GOTO_IF_FAIL(cond, dst)       {if (!(cond)) { ErrorF ("[%s] '%s' failed.\n", __FUNCTION__, #cond); goto dst; }}
117 #define XDBG_GOTO_IF_ERRNO(cond, dst, errno)       {if (!(cond)) { ErrorF ("[%s] '%s' failed. (err=%s(%d))\n", __FUNCTION__, #cond, strerror(errno), errno); goto dst; }}
118
119 #define XDBG_REPLY(fmt, ARG...)  \
120     do { \
121         if (reply && len && *len > 0) \
122         { \
123             int s = snprintf (reply, *len, fmt, ##ARG); \
124             reply += s; \
125             *len -= s; \
126         } \
127     } while (0)
128
129 unsigned int xDbgLogGetModule (char *name);
130
131 #define _C(b,s)             (((b) >> (s)) & 0xFF)
132 #define _B(c,s)             ((((unsigned int)(c)) & 0xff) << (s))
133 #define XDBG_M(a,b,c,d)     (_B(d,24)|_B(c,16)|_B(b,8)|_B(a,0))
134
135 /* debug module for XDBG */
136 #define MXDBG    XDBG_M('X','D','B','G')
137
138 #endif  /* __XDBG_LOG_H__ */