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.

89 lines
3.1 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: examples/cpp/tracing/example.cpp.tracing.standard/example.cpp.tracing.standard.cpp
  3. *
  4. * Purpose: C++ example program for Pantheios. Demonstrates:
  5. *
  6. * - use of Pantheios Tracing API
  7. *
  8. * Created: 18th August 2007
  9. * Updated: 6th December 2010
  10. *
  11. * www: http://www.pantheios.org/
  12. *
  13. * License: This source code is placed into the public domain 2007
  14. * by Synesis Software Pty Ltd. There are no restrictions
  15. * whatsoever to your use of the software.
  16. *
  17. * This software is provided "as is", and any warranties,
  18. * express or implied, of any kind and for any purpose, are
  19. * disclaimed.
  20. *
  21. * ////////////////////////////////////////////////////////////////////// */
  22. /* Pantheios Header Files */
  23. #include <pantheios/pantheios.h> // Pantheios C main header
  24. #include <pantheios/trace.h> // Pantheios Trace API
  25. #include <pantheios/pantheios.hpp> // Pantheios C++ main header
  26. /* Standard C/C++ Header Files */
  27. #include <exception> // for std::exception
  28. #include <new> // for std::bad_alloc
  29. #include <string> // for std::string
  30. #include <stdlib.h> // for exit codes
  31. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  32. # if defined(STLSOFT_COMPILER_IS_MSVC)
  33. # pragma warning(disable : 4702)
  34. # endif /* compiler */
  35. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  36. /* ////////////////////////////////////////////////////////////////////// */
  37. /* Define the stock front-end process identity, so that it links when using
  38. * fe.N, fe.simple, etc. */
  39. PANTHEIOS_EXTERN_C const PAN_CHAR_T PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("example.cpp.tracing.standard");
  40. /* ////////////////////////////////////////////////////////////////////// */
  41. #define PSTR(x) PANTHEIOS_LITERAL_STRING(x)
  42. /* ////////////////////////////////////////////////////////////////////// */
  43. int main()
  44. {
  45. try
  46. {
  47. // Prints "[example.cpp.tracing.standard, 8/18/2007 17:14:08.875 PM; Notice]: example.cpp.tracing.standard.cpp(51): a string '<abc>' and a number 42"
  48. PANTHEIOS_TRACE_PRINTF(pantheios::notice, PSTR("a string '%s' and a number %d"), PSTR("<abc>"), 42);
  49. // Prints "[example.cpp.tracing.standard, 8/18/2007 17:14:08.875 PM; Notice]: example.cpp.tracing.standard.cpp(55): a string at NOTICE level"
  50. PANTHEIOS_TRACE_NOTICE(PSTR("a string at NOTICE level"));
  51. PANTHEIOS_TRACE_INFORMATIONAL(PSTR("informational"));
  52. PANTHEIOS_TRACE_ALERT(PSTR("alert"));
  53. PANTHEIOS_TRACE_WARNING(PSTR("warning"));
  54. return EXIT_SUCCESS;
  55. }
  56. catch(std::bad_alloc&)
  57. {
  58. pantheios::log(pantheios::alert, PSTR("out of memory"));
  59. }
  60. catch(std::exception& x)
  61. {
  62. pantheios::log_CRITICAL(PSTR("Exception: "), x);
  63. }
  64. catch(...)
  65. {
  66. pantheios::logputs(pantheios::emergency, PSTR("Unexpected unknown error"));
  67. }
  68. return EXIT_FAILURE;
  69. }
  70. /* ///////////////////////////// end of file //////////////////////////// */