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.

135 lines
4.2 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: test/scratch/test.scratch.be.WindowsSyslog/test.scratch.be.WindowsSyslog.cpp
  3. *
  4. * Purpose: C++ example program for Pantheios. Demonstrates:
  5. *
  6. * - use of custom severity level information for tabbing output
  7. * - definition of a custom back-end that supports tabbed output
  8. * - use of pantheios::logputs() in bail-out conditions
  9. *
  10. * Created: 3rd August 2012
  11. * Updated: 6th August 2012
  12. *
  13. * www: http://www.pantheios.org/
  14. *
  15. * License: This source code is placed into the public domain 2010
  16. * by Synesis Software Pty Ltd. There are no restrictions
  17. * whatsoever to your use of the software.
  18. *
  19. * This software is provided "as is", and any warranties,
  20. * express or implied, of any kind and for any purpose, are
  21. * disclaimed.
  22. *
  23. * ////////////////////////////////////////////////////////////////////// */
  24. /* This inclusion required for suppressing warnings during NoX (No eXception-support) configurations. */
  25. #include <pantheios/util/test/compiler_warnings_suppression.first_include.h>
  26. /* Pantheios Header Files */
  27. #include <pantheios/pantheios.hpp>
  28. #include <pantheios/backend.h>
  29. #include <pantheios/backends/bec.WindowsSyslog.h>
  30. /* STLSoft Header Files */
  31. #include <platformstl/synch/sleep_functions.h>
  32. /* Standard C/C++ Header Files */
  33. #include <exception> // for std::exception
  34. #include <string> // for std::string
  35. #include <stdio.h> // for fprintf()
  36. #include <stdlib.h> // for exit codes
  37. #include <string.h> // for memset()
  38. #include <pantheios/util/test/compiler_warnings_suppression.last_include.h>
  39. /* ////////////////////////////////////////////////////////////////////// */
  40. // Define the fe.simple process identity, so that it links when using fe.simple
  41. PANTHEIOS_EXTERN_C PAN_CHAR_T const PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("test.scratch.be.WindowsSyslog");
  42. /* /////////////////////////////////////////////////////////////////////////
  43. * Application-defined functions
  44. */
  45. PANTHEIOS_CALL(void) pantheios_be_WindowsSyslog_getAppInit(
  46. int backEndId
  47. , pan_be_WindowsSyslog_init_t* init
  48. ) throw()
  49. {
  50. init->addrSize = 0;
  51. init->hostName = "127.0.0.1";
  52. }
  53. /* ////////////////////////////////////////////////////////////////////// */
  54. int main()
  55. {
  56. unsigned shortPause = 1250;
  57. try
  58. {
  59. pantheios::log_NOTICE("Hi!");
  60. platformstl::micro_sleep(shortPause);
  61. pantheios::log_NOTICE("This is your logger, calling.");
  62. platformstl::micro_sleep(shortPause);
  63. pantheios::log_NOTICE("Here come some diagnostic logging statements ...");
  64. platformstl::micro_sleep(shortPause);
  65. pantheios::log_DEBUG("just being pedantic");
  66. platformstl::micro_sleep(shortPause);
  67. pantheios::log_INFORMATIONAL("you can ignore this");
  68. platformstl::micro_sleep(shortPause);
  69. pantheios::log_NOTICE("this is noteworthy");
  70. platformstl::micro_sleep(shortPause);
  71. pantheios::log_WARNING("there may be a problem");
  72. platformstl::micro_sleep(shortPause);
  73. pantheios::log_ERROR("there is a problem");
  74. platformstl::micro_sleep(shortPause);
  75. pantheios::log_CRITICAL("there is a serious problem");
  76. platformstl::micro_sleep(shortPause);
  77. pantheios::log_ALERT("there is a very serious problem");
  78. platformstl::micro_sleep(shortPause);
  79. pantheios::log_EMERGENCY("aargh! I'm operating in contradiction to my design!");
  80. platformstl::micro_sleep(90000);
  81. return EXIT_SUCCESS;
  82. }
  83. catch(std::bad_alloc &)
  84. {
  85. pantheios::log_CRITICAL("out of memory");
  86. }
  87. catch(std::exception &x)
  88. {
  89. pantheios::log_ALERT("Exception: ", x);
  90. }
  91. catch(...)
  92. {
  93. pantheios::logputs(pantheios::emergency, "Unexpected unknown error");
  94. }
  95. return EXIT_FAILURE;
  96. }
  97. /* ///////////////////////////// end of file //////////////////////////// */