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.

128 lines
4.0 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: examples/cpp/frontends/example.cpp.frontends.custom/example.cpp.frontends.custom.cpp
  3. *
  4. * Purpose: C++ example program for Pantheios. Demonstrates:
  5. *
  6. * - definition of a custom front-end that supports tabbed output
  7. * - use of pantheios::logputs() in bail-out conditions
  8. *
  9. * Created: 31st August 2006
  10. * Updated: 7th December 2010
  11. *
  12. * www: http://www.pantheios.org/
  13. *
  14. * License: This source code is placed into the public domain 2006
  15. * by Synesis Software Pty Ltd. There are no restrictions
  16. * whatsoever to your use of the software.
  17. *
  18. * This software is provided "as is", and any warranties,
  19. * express or implied, of any kind and for any purpose, are
  20. * disclaimed.
  21. *
  22. * ////////////////////////////////////////////////////////////////////// */
  23. #define PANTHEIOS_NO_INCLUDE_OS_AND_3PTYLIB_STRING_ACCESS // Faster compilation
  24. /* Pantheios Header Files */
  25. #include <pantheios/pantheios.hpp> // Pantheios C++ main header
  26. #include <pantheios/frontend.h>
  27. /* Standard C/C++ Header Files */
  28. #include <exception> // for std::exception
  29. #include <new> // for std::bad_alloc
  30. #include <string> // for std::string
  31. #include <stdlib.h> // for exit codes, atoi()
  32. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  33. # if defined(STLSOFT_COMPILER_IS_MSVC)
  34. # pragma warning(disable : 4702)
  35. # endif /* compiler */
  36. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  37. /* ////////////////////////////////////////////////////////////////////// */
  38. namespace
  39. {
  40. // By default, we will log everything at NOTICE and below (remember that
  41. // they get more serious as the values get lower).
  42. static int s_severityCeiling = pantheios::notice;
  43. } // anonymous namespace
  44. /* ////////////////////////////////////////////////////////////////////// */
  45. #define PSTR(x) PANTHEIOS_LITERAL_STRING(x)
  46. /* ////////////////////////////////////////////////////////////////////// */
  47. // USAGE: [<severity-ceiling>]
  48. //
  49. // where:
  50. // <severity-ceiling> - a number between 0 and 7, which sets the maximum level
  51. // displayed, or -1 to suppress all output.
  52. int main(int argc, char **argv)
  53. {
  54. if(argc > 1)
  55. {
  56. s_severityCeiling = ::atoi(argv[1]);
  57. }
  58. try
  59. {
  60. pantheios::log_DEBUG(PSTR("debug statement"));
  61. pantheios::log_INFORMATIONAL(PSTR("informational statement"));
  62. pantheios::log_NOTICE(PSTR("notice statement"));
  63. pantheios::log_WARNING(PSTR("warning statement"));
  64. pantheios::log_ERROR(PSTR("error statement"));
  65. pantheios::log_CRITICAL(PSTR("critical statement"));
  66. pantheios::log_ALERT(PSTR("alert statement"));
  67. pantheios::log_EMERGENCY(PSTR("emergency statement"));
  68. return EXIT_SUCCESS;
  69. }
  70. catch(std::bad_alloc&)
  71. {
  72. pantheios::log(pantheios::alert, PSTR("out of memory"));
  73. }
  74. catch(std::exception& x)
  75. {
  76. pantheios::log_CRITICAL(PSTR("Exception: "), x);
  77. }
  78. catch(...)
  79. {
  80. pantheios::logputs(pantheios::emergency, PSTR("Unexpected unknown error"));
  81. }
  82. return EXIT_FAILURE;
  83. }
  84. /* ////////////////////////////////////////////////////////////////////// */
  85. PANTHEIOS_CALL(int) pantheios_fe_init( void* /* reserved */
  86. , void** ptoken)
  87. {
  88. *ptoken = NULL;
  89. return 0;
  90. }
  91. PANTHEIOS_CALL(void) pantheios_fe_uninit(void* /* token */)
  92. {}
  93. PANTHEIOS_CALL(PAN_CHAR_T const*) pantheios_fe_getProcessIdentity(void* /* token */)
  94. {
  95. return PSTR("example.cpp.frontends.custom");
  96. }
  97. PANTHEIOS_CALL(int) pantheios_fe_isSeverityLogged( void* /* token */
  98. , int severity
  99. , int /* backEndId */)
  100. {
  101. return severity <= s_severityCeiling;
  102. }
  103. /* ///////////////////////////// end of file //////////////////////////// */