Log.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*******************************************************************************
  2. * Copyright (c) 2009, 2022 IBM Corp.
  3. *
  4. * All rights reserved. This program and the accompanying materials
  5. * are made available under the terms of the Eclipse Public License v2.0
  6. * and Eclipse Distribution License v1.0 which accompany this distribution.
  7. *
  8. * The Eclipse Public License is available at
  9. * https://www.eclipse.org/legal/epl-2.0/
  10. * and the Eclipse Distribution License is available at
  11. * http://www.eclipse.org/org/documents/edl-v10.php.
  12. *
  13. * Contributors:
  14. * Ian Craggs - initial API and implementation and/or initial documentation
  15. * Ian Craggs - updates for the async client
  16. *******************************************************************************/
  17. #if !defined(LOG_H)
  18. #define LOG_H
  19. #if defined(_WIN32) || defined(_WIN64)
  20. #include <windows.h>
  21. #define thread_id_type DWORD
  22. #else
  23. #include <pthread.h>
  24. #define thread_id_type pthread_t
  25. #endif
  26. /*BE
  27. map LOG_LEVELS
  28. {
  29. "TRACE_MAXIMUM" 1
  30. "TRACE_MEDIUM" 2
  31. "TRACE_MINIMUM" 3
  32. "TRACE_PROTOCOL" 4
  33. "ERROR" 5
  34. "SEVERE" 6
  35. "FATAL" 7
  36. }
  37. BE*/
  38. enum LOG_LEVELS {
  39. INVALID_LEVEL = -1,
  40. TRACE_MAXIMUM = 1,
  41. TRACE_MEDIUM,
  42. TRACE_MINIMUM,
  43. TRACE_PROTOCOL,
  44. LOG_ERROR,
  45. LOG_SEVERE,
  46. LOG_FATAL,
  47. };
  48. /*BE
  49. def trace_settings_type
  50. {
  51. n32 map LOG_LEVELS "trace_level"
  52. n32 dec "max_trace_entries"
  53. n32 dec "trace_output_level"
  54. }
  55. BE*/
  56. typedef struct
  57. {
  58. enum LOG_LEVELS trace_level; /**< trace level */
  59. int max_trace_entries; /**< max no of entries in the trace buffer */
  60. enum LOG_LEVELS trace_output_level; /**< trace level to output to destination */
  61. } trace_settings_type;
  62. extern trace_settings_type trace_settings;
  63. #define LOG_PROTOCOL TRACE_PROTOCOL
  64. #define TRACE_MAX TRACE_MAXIMUM
  65. #define TRACE_MIN TRACE_MINIMUM
  66. #define TRACE_MED TRACE_MEDIUM
  67. typedef struct
  68. {
  69. const char* name;
  70. const char* value;
  71. } Log_nameValue;
  72. int Log_initialize(Log_nameValue*);
  73. void Log_terminate(void);
  74. void Log(enum LOG_LEVELS, int, const char *, ...);
  75. void Log_stackTrace(enum LOG_LEVELS, int, thread_id_type, int, const char*, int, int*);
  76. typedef void Log_traceCallback(enum LOG_LEVELS level, const char *message);
  77. void Log_setTraceCallback(Log_traceCallback* callback);
  78. void Log_setTraceLevel(enum LOG_LEVELS level);
  79. #endif