1 /* EINA - EFL data type library
2 * Copyright (C) 2002-2008 Gustavo Sverzut Barbieri
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library;
16 * if not, see <http://www.gnu.org/licenses/>.
19 #ifndef EINA_LOG_INLINE_H_
20 #define EINA_LOG_INLINE_H_
23 * @addtogroup Eina_Log_Group Log
29 * @brief Checks whenever the given level should be printed out.
31 * @param level The level to print
33 * This is useful to enable certain blocks of code just when given
34 * level is to be used.
39 * void my_func(void *data)
41 * if (eina_log_level_check(EINA_LOG_LEVEL_WARN))
42 * expensive_debugging_code(data);
48 * @return #EINA_TRUE if level is equal or smaller than the current global
51 static inline Eina_Bool
52 eina_log_level_check(int level)
54 return eina_log_level_get() >= level;
58 * @brief Checks whenever the given level should be printed out.
60 * @param domain The domain to check
61 * @param level The level to print
63 * This is useful to enable certain blocks of code just when given
64 * level is to be used.
69 * extern int _my_log_dom;
71 * void my_func(void *data)
73 * if (eina_log_domain_level_check(_my_log_dom, EINA_LOG_LEVEL_WARN))
74 * expensive_debugging_code(data);
80 * @return #EINA_TRUE if level is equal or smaller than the current
81 * domain logging level.
83 static inline Eina_Bool
84 eina_log_domain_level_check(int domain, int level)
86 int dom_level = eina_log_domain_registered_level_get(domain);
87 if (EINA_UNLIKELY(dom_level == EINA_LOG_LEVEL_UNKNOWN))
89 return dom_level >= level;
93 * Function to format the level as a 3 character (+1 null byte) string.
95 * This function converts the given level to a known string name (CRI,
96 * ERR, WRN, INF or DBG) or a zero-padded 3-character string. In any
97 * case the last byte will contain a trailing null byte.
99 * If extreme level values are used (greater than 999 and smaller than
100 * -99), then the value will just consider the less significant
101 * part. This is so uncommon that users should handle this in their
104 * @param level what level value to use.
105 * @param name where to write the actual value.
107 * @return pointer to @p name.
109 static inline const char *
110 eina_log_level_name_get(int level, char name[4])
112 #define BCPY(A, B, C) \
113 do { name[0] = A; name[1] = B; name[2] = C; } while (0)
115 if (EINA_UNLIKELY(level < 0))
118 name[1] = '0' + (-level / 10) % 10;
119 name[2] = '0' + (-level % 10);
121 else if (EINA_UNLIKELY(level >= EINA_LOG_LEVELS))
123 name[0] = '0' + (level / 100) % 10;
124 name[1] = '0' + (level / 10) % 10;
125 name[2] = '0' + level % 10;
146 * Function to get recommended color value for level.
148 * This function will not check if colors are enabled or not before
149 * returning the level color. If you desire such check, use
150 * eina_log_level_color_if_enabled_get().
152 * @param level what level value to use.
154 * @return pointer to null byte terminated ANSI color string to be
155 * used in virtual terminals supporting VT100 color codes.
157 * @see eina_log_level_color_if_enabled_get()
159 static inline const char *
160 eina_log_level_color_get(int level)
163 return EINA_COLOR_LIGHTRED;
165 return EINA_COLOR_RED;
167 return EINA_COLOR_YELLOW;
169 return EINA_COLOR_GREEN;
171 return EINA_COLOR_LIGHTBLUE;
173 return EINA_COLOR_BLUE;
177 * Function to get recommended color value for level, if colors are
180 * This function will check if colors are enabled or not before
181 * returning the level color. If colors are disabled, then empty
182 * string is returned.
184 * @param level what level value to use.
186 * @return pointer to null byte terminated ANSI color string to be
187 * used in virtual terminals supporting VT100 color codes. If
188 * colors are disabled, the empty string is returned.
190 static inline const char *
191 eina_log_level_color_if_enabled_get(int level)
193 if (eina_log_color_disable_get())
195 return eina_log_level_color_get(level);
202 #endif /* EINA_LOG_INLINE_H_ */