You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

112 lines
4.1 KiB

  1. /***************************************************************************
  2. * Copyright (C) 2005 by Dominic Rath *
  3. * Dominic.Rath@gmx.de *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 2 of the License, or *
  8. * (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 General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, write to the *
  17. * Free Software Foundation, Inc., *
  18. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  19. ***************************************************************************/
  20. #ifndef ERROR_H
  21. #define ERROR_H
  22. #include "replacements.h"
  23. #include "command.h"
  24. #include <stdarg.h>
  25. /* logging priorities
  26. * LOG_USER - user messages. Could be anything from information
  27. * to progress messags. These messages do not represent
  28. * incorrect or unexpected behaviour, just normal execution.
  29. * LOG_ERROR - fatal errors, that are likely to cause program abort
  30. * LOG_WARNING - non-fatal errors, that may be resolved later
  31. * LOG_INFO - state information, etc.
  32. * LOG_DEBUG - debug statements, execution trace
  33. */
  34. enum log_levels
  35. {
  36. LOG_OUTPUT = -2,
  37. LOG_USER = -1,
  38. LOG_ERROR = 0,
  39. LOG_WARNING = 1,
  40. LOG_INFO = 2,
  41. LOG_DEBUG = 3
  42. };
  43. extern void log_printf(enum log_levels level, const char *file, int line,
  44. const char *function, const char *format, ...)
  45. __attribute__ ((format (printf, 5, 6)));
  46. extern void log_printf_lf(enum log_levels level, const char *file, int line,
  47. const char *function, const char *format, ...)
  48. __attribute__ ((format (printf, 5, 6)));
  49. extern int log_register_commands(struct command_context_s *cmd_ctx);
  50. extern int log_init(struct command_context_s *cmd_ctx);
  51. extern int set_log_output(struct command_context_s *cmd_ctx, FILE *output);
  52. typedef void (*log_callback_fn)(void *priv, const char *file, int line,
  53. const char *function, const char *string);
  54. typedef struct log_callback_s
  55. {
  56. log_callback_fn fn;
  57. void *priv;
  58. struct log_callback_s *next;
  59. } log_callback_t;
  60. extern int log_add_callback(log_callback_fn fn, void *priv);
  61. extern int log_remove_callback(log_callback_fn fn, void *priv);
  62. char *alloc_printf(const char *fmt, va_list ap);
  63. extern int debug_level;
  64. /* Avoid fn call and building parameter list if we're not outputting the information.
  65. * Matters on feeble CPUs for DEBUG/INFO statements that are involved frequently */
  66. #define DEBUG(expr ...) \
  67. log_printf_lf (LOG_DEBUG, __FILE__, __LINE__, __FUNCTION__, expr)
  68. #define INFO(expr ...) \
  69. log_printf_lf (LOG_INFO, __FILE__, __LINE__, __FUNCTION__, expr)
  70. #define INFO_N(expr ...) \
  71. log_printf (LOG_INFO, __FILE__, __LINE__, __FUNCTION__, expr)
  72. #define WARNING(expr ...) \
  73. log_printf_lf (LOG_WARNING, __FILE__, __LINE__, __FUNCTION__, expr)
  74. #define ERROR(expr ...) \
  75. log_printf_lf (LOG_ERROR, __FILE__, __LINE__, __FUNCTION__, expr)
  76. #define USER(expr ...) \
  77. log_printf_lf (LOG_USER, __FILE__, __LINE__, __FUNCTION__, expr)
  78. #define USER_N(expr ...) \
  79. log_printf (LOG_USER, __FILE__, __LINE__, __FUNCTION__, expr)
  80. #define OUTPUT(expr ...) \
  81. log_printf (LOG_OUTPUT, __FILE__, __LINE__, __FUNCTION__, expr)
  82. /* general failures
  83. * error codes < 100
  84. */
  85. #define ERROR_OK (0)
  86. #define ERROR_INVALID_ARGUMENTS (-1)
  87. #define ERROR_NO_CONFIG_FILE (-2)
  88. #define ERROR_BUF_TOO_SMALL (-3)
  89. #endif /* LOG_H */