Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright 2003 James Bursa <bursa@users.sourceforge.net>
  3.  * Copyright 2004 John Tytgat <joty@netsurf-browser.org>
  4.  *
  5.  * This file is part of NetSurf, http://www.netsurf-browser.org/
  6.  *
  7.  * NetSurf is free software; you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation; version 2 of the License.
  10.  *
  11.  * NetSurf is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  */
  19.  
  20. #ifndef _NETSURF_LOG_H_
  21. #define _NETSURF_LOG_H_
  22.  
  23. #include <stdio.h>
  24. #include "desktop/netsurf.h"
  25. #include "utils/errors.h"
  26.  
  27. /**
  28.  * Ensures the FILE handle is available to write logging to.
  29.  *
  30.  * This is provided by the frontends if required
  31.  */
  32. typedef bool(nslog_ensure_t)(FILE *fptr);
  33.  
  34. /**
  35.  * Initialise the logging system.
  36.  *
  37.  * Sets up everything required for logging. Processes the argv passed
  38.  * to remove the -v switch for verbose logging. If necessary ensures
  39.  * the output file handle is available.
  40.  */
  41. extern nserror nslog_init(nslog_ensure_t *ensure, int *pargc, char **argv);
  42.  
  43. #ifdef NDEBUG
  44. #  define LOG(x) ((void) 0)
  45. #else
  46.  
  47. /**
  48.  * Obtain a formatted string suitable for prepending to a log message
  49.  *
  50.  * \return formatted string of the time since first log call
  51.  */
  52. extern const char *nslog_gettime(void);
  53. extern void nslog_log(const char *format, ...);
  54.  
  55. #  ifdef __GNUC__
  56. #    define LOG_FN __PRETTY_FUNCTION__
  57. #    define LOG_LN __LINE__
  58. #  elif defined(__CC_NORCROFT)
  59. #    define LOG_FN __func__
  60. #    define LOG_LN __LINE__
  61. #  else
  62. #    define LOG_FN ""
  63. #    define LOG_LN __LINE__
  64. #  endif
  65.  
  66. #define LOG(x) \
  67.         do {                                                            \
  68.                 if (verbose_log) {                                      \
  69.                         nslog_log("%s " __FILE__ " %s %i: ",            \
  70.                                   nslog_gettime(), LOG_FN, LOG_LN);     \
  71.                         nslog_log x;                                    \
  72.                         nslog_log("\n");                                \
  73.                 }                                                       \
  74.         } while(0)
  75.  
  76. #endif
  77.  
  78. #endif
  79.