nc_logging.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* Copyright 2010, University Corporation for Atmospheric Research. See
  2. COPYRIGHT file for copying and redistribution conditions.
  3. This file is part of netcdf-4, a netCDF-like interface for HDF5, or
  4. a HDF5 backend for netCDF, depending on your point of view.
  5. This file contains macros and prototyes relating to logging.
  6. $Id: nc_logging.h,v 1.1 2010/06/01 15:34:49 ed Exp $
  7. */
  8. #ifndef _NCLOGGING_
  9. #define _NCLOGGING_
  10. #include <stdlib.h>
  11. #include <assert.h>
  12. #ifdef LOGGING
  13. /* To log something... */
  14. void nc_log(int severity, const char *fmt, ...);
  15. void nc_log_hdf5(void);
  16. #define LOG(e) nc_log e
  17. /* To log based on error code, and set retval. */
  18. #define BAIL2(e) do { \
  19. retval = e; \
  20. LOG((0, "file %s, line %d.\n%s", __FILE__, __LINE__, nc_strerror(e))); \
  21. nc_log_hdf5(); \
  22. } while (0)
  23. /* To log an error message, set retval, and jump to exit. */
  24. #define BAIL(e) do { \
  25. BAIL2(e); \
  26. goto exit; \
  27. } while (0)
  28. /* To set retval and jump to exit, without logging error message. */
  29. #define BAIL_QUIET(e) do { \
  30. retval = e; \
  31. goto exit; \
  32. } while (0)
  33. #else
  34. /* These definitions will be used unless LOGGING is defined. */
  35. #define LOG(e)
  36. #define BAIL(e) do { \
  37. retval = e; \
  38. goto exit; \
  39. } while (0)
  40. #define BAIL_QUIET BAIL
  41. #define BAIL2(e) do { \
  42. goto exit; \
  43. } while (0)
  44. #define nc_set_log_level(e)
  45. #endif
  46. #endif /* _NCLOGGING_ */