Annotation of gpl/axl/src/axl_log.c, revision 1.1
1.1 ! misho 1: /*
! 2: * LibAxl: Another XML library
! 3: * Copyright (C) 2006 Advanced Software Production Line, S.L.
! 4: *
! 5: * This program is free software; you can redistribute it and/or
! 6: * modify it under the terms of the GNU Lesser General Public License
! 7: * as published by the Free Software Foundation; either version 2.1 of
! 8: * the License, or (at your option) any later version.
! 9: *
! 10: * This program is distributed in the hope that it will be useful,
! 11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
! 12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! 13: * GNU Lesser General Public License for more details.
! 14: *
! 15: * You should have received a copy of the GNU Lesser General Public
! 16: * License along with this program; if not, write to the Free
! 17: * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
! 18: * 02111-1307 USA
! 19: *
! 20: * You may find a copy of the license under this software is released
! 21: * at COPYING file. This is LGPL software: you are welcome to
! 22: * develop proprietary applications using this library without any
! 23: * royalty or fee but returning back any change, improvement or
! 24: * addition in the form of source code, project image, documentation
! 25: * patches, etc.
! 26: *
! 27: * For commercial support on build XML enabled solutions contact us:
! 28: *
! 29: * Postal address:
! 30: * Advanced Software Production Line, S.L.
! 31: * Edificio Alius A, Oficina 102,
! 32: * C/ Antonio Suarez Nº 10,
! 33: * Alcalá de Henares 28802 Madrid
! 34: * Spain
! 35: *
! 36: * Email address:
! 37: * info@aspl.es - http://www.aspl.es/xml
! 38: */
! 39: #include <axl_log.h>
! 40:
! 41: /**
! 42: * \defgroup axl_log_module Axl Log: Console log reporting for AXL library
! 43: */
! 44:
! 45: /**
! 46: * \addtogroup axl_log_module
! 47: * @{
! 48: */
! 49:
! 50: /* console log */
! 51: axl_bool not_executed = axl_true;
! 52: axl_bool debug_enabled = axl_false;
! 53:
! 54: /* colored log */
! 55: axl_bool not_executed_color = axl_true;
! 56: axl_bool debug_color_enabled = axl_false;
! 57:
! 58: /**
! 59: * @brief Allows to check if the log reporting inside the system is
! 60: * enabled.
! 61: *
! 62: * @return axl_true if the log is enabled or axl_false
! 63: */
! 64: axl_bool axl_log_is_enabled (void)
! 65: {
! 66: #if defined(AXL_OS_WIN32) && ! defined(__GNUC__)
! 67: int requiredSize;
! 68: #endif
! 69:
! 70: if (not_executed) {
! 71: #if defined(AXL_OS_WIN32) && ! defined(__GNUC__)
! 72: getenv_s( &requiredSize, NULL, 0, "AXL_DEBUG");
! 73: debug_enabled = (requiredSize > 0);
! 74: #else
! 75: debug_enabled = (getenv ("AXL_DEBUG") != NULL);
! 76: #endif
! 77: not_executed = axl_false;
! 78: }
! 79:
! 80: /* return current value */
! 81: return debug_enabled;
! 82: }
! 83:
! 84: /**
! 85: *
! 86: * @brief Allows to get current log configuration, to use colors.
! 87: *
! 88: * @return axl_true if the color log is enabled or axl_false
! 89: */
! 90: axl_bool axl_log_color_is_enabled (void)
! 91: {
! 92: #if defined(AXL_OS_WIN32) && ! defined(__GNUC__)
! 93: int requiredSize;
! 94: #endif
! 95:
! 96: if (not_executed_color) {
! 97: #if defined(AXL_OS_WIN32) && ! defined(__GNUC__)
! 98: getenv_s( &requiredSize, NULL, 0, "AXL_DEBUG_COLOR");
! 99: debug_color_enabled = (requiredSize > 0);
! 100: #else
! 101: debug_color_enabled = (getenv ("AXL_DEBUG_COLOR") != NULL);
! 102: #endif
! 103: not_executed_color = axl_false;
! 104: }
! 105:
! 106: /* return current value */
! 107: return debug_color_enabled;
! 108: }
! 109:
! 110: /**
! 111: * @brief Allows to control how to activate the log reporting to the
! 112: * console from the axl core library.
! 113: *
! 114: * @param value axl_true to enable log to console, otherwise axl_false is
! 115: * returned.
! 116: */
! 117: void axl_log_enable (axl_bool value)
! 118: {
! 119: /* activate debuging according to the variable */
! 120: not_executed = axl_false;
! 121: debug_enabled = value;
! 122: return;
! 123: }
! 124:
! 125: /**
! 126: * @brief Allows to control how to activate the colog log reporting to
! 127: * the console from the axl core library.
! 128: *
! 129: * @param value axl_true to enable log to console, otherwise axl_false is
! 130: * returned.
! 131: */
! 132: void axl_log_color_enable (axl_bool value)
! 133: {
! 134: /* activate color debuging according to the variable */
! 135: not_executed_color = axl_false;
! 136: debug_color_enabled = value;
! 137: return;
! 138: }
! 139:
! 140: /**
! 141: * @brief Allows to drop a log to the console.
! 142: *
! 143: * This function allow to drop a log to the console using the given
! 144: * domain, as an identification of which subsystem have reported the
! 145: * information, and report level. This report level is used to notify
! 146: * the consideration of the log reported.
! 147: *
! 148: * The function allows to provide a printf like interface to report
! 149: * messages. Here are some examples:
! 150: *
! 151: * \code
! 152: * // drop a log about current library initialization
! 153: * axl_log ("axl", AXL_LEVEL_DEBUG, "library properly initialized status=%d", status);
! 154: * \endcode
! 155: *
! 156: *
! 157: * @param domain The domain where the log as generated. if NULL is
! 158: * provided a log with no domain will be generated.
! 159: *
! 160: * @param level The level that this message is classificed.
! 161: *
! 162: * @param message The message to report. The message to report must be
! 163: * not NULL.
! 164: */
! 165: void axl_log (char * domain, AxlDebugLevel level, char * message, ...)
! 166: {
! 167:
! 168: #ifdef SHOW_DEBUG_LOG
! 169: va_list args;
! 170:
! 171: /* check if the log is enabled */
! 172: if (! axl_log_is_enabled ())
! 173: return;
! 174:
! 175: /* printout the process pid */
! 176: if (axl_log_color_is_enabled ())
! 177: printf ("\e[1;36m(proc %d)\e[0m: ", getpid ());
! 178: else
! 179: printf ("(proc %d): ", getpid ());
! 180:
! 181: /* drop a log according to the level */
! 182: if (axl_log_color_is_enabled ()) {
! 183: switch (level) {
! 184: case AXL_LEVEL_DEBUG:
! 185: printf ("(\e[1;32mdebug\e[0m) ");
! 186: break;
! 187: case AXL_LEVEL_WARNING:
! 188: printf ("(\e[1;33mwarning\e[0m) ");
! 189: break;
! 190: case AXL_LEVEL_CRITICAL:
! 191: printf ("(\e[1;31mcritical\e[0m) ");
! 192: break;
! 193: }
! 194: }else {
! 195: switch (level) {
! 196: case AXL_LEVEL_DEBUG:
! 197: printf ("(debug)");
! 198: break;
! 199: case AXL_LEVEL_WARNING:
! 200: printf ("(warning)");
! 201: break;
! 202: case AXL_LEVEL_CRITICAL:
! 203: printf ("(critical) ");
! 204: break;
! 205: }
! 206: }
! 207:
! 208: /* drop a log according to the domain */
! 209: (domain != NULL) ? printf ("%s: ", domain) : printf (": ");
! 210:
! 211: /* print the message */
! 212: va_start (args, message);
! 213: vprintf (message, args);
! 214: va_end (args);
! 215:
! 216: printf ("\n");
! 217:
! 218: /* ensure that the log is droped to the console */
! 219: fflush (stdout);
! 220: #endif
! 221:
! 222: /* return */
! 223: return;
! 224: }
! 225:
! 226: /* @} */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>