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.

139 lines
4.2 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: test/scratch/test.scratch.be.syslog.WithCallback/test.scratch.be.syslog.WithCallback.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: 10th November 2010
  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.syslog.h>
  30. /* STLSoft Header Files */
  31. #include <platformstl/synch/sleep_functions.h>
  32. /* UNIX Header Files */
  33. #include <syslog.h>
  34. /* Standard C/C++ Header Files */
  35. #include <exception> // for std::exception
  36. #include <string> // for std::string
  37. #include <stdio.h> // for fprintf()
  38. #include <stdlib.h> // for exit codes
  39. #include <string.h> // for memset()
  40. #include <pantheios/util/test/compiler_warnings_suppression.last_include.h>
  41. /* ////////////////////////////////////////////////////////////////////// */
  42. // Define the fe.simple process identity, so that it links when using fe.simple
  43. PANTHEIOS_EXTERN_C PAN_CHAR_T const PANTHEIOS_FE_PROCESS_IDENTITY[] = PANTHEIOS_LITERAL_STRING("test.scratch.speech");
  44. /* ////////////////////////////////////////////////////////////////////// */
  45. PANTHEIOS_CALL(void) pantheios_be_syslog_getAppInit(
  46. int /* backEndId */
  47. , pan_be_syslog_init_t* init
  48. ) /* throw() */
  49. {
  50. // Suppress perror
  51. init->options &= ~PANTHEIOS_BE_SYSLOG_F_PERROR;
  52. // Log to LOCAL1 (instead of USER)
  53. init->facility = LOG_LOCAL1;
  54. }
  55. /* ////////////////////////////////////////////////////////////////////// */
  56. int main()
  57. {
  58. unsigned shortPause = 1250;
  59. try
  60. {
  61. pantheios::log_NOTICE("Hi!");
  62. platformstl::micro_sleep(shortPause);
  63. pantheios::log_NOTICE("This is your logger, calling.");
  64. platformstl::micro_sleep(shortPause);
  65. pantheios::log_NOTICE("Here come some diagnostic logging statements ...");
  66. platformstl::micro_sleep(shortPause);
  67. pantheios::log_DEBUG("just being pedantic");
  68. platformstl::micro_sleep(shortPause);
  69. pantheios::log_INFORMATIONAL("you can ignore this");
  70. platformstl::micro_sleep(shortPause);
  71. pantheios::log_NOTICE("this is noteworthy");
  72. platformstl::micro_sleep(shortPause);
  73. pantheios::log_WARNING("there may be a problem");
  74. platformstl::micro_sleep(shortPause);
  75. pantheios::log_ERROR("there is a problem");
  76. platformstl::micro_sleep(shortPause);
  77. pantheios::log_CRITICAL("there is a serious problem");
  78. platformstl::micro_sleep(shortPause);
  79. pantheios::log_ALERT("there is a very serious problem");
  80. platformstl::micro_sleep(shortPause);
  81. pantheios::log_EMERGENCY("aargh! I'm operating in contradiction to my design!");
  82. platformstl::micro_sleep(90000);
  83. return EXIT_SUCCESS;
  84. }
  85. catch(std::bad_alloc &)
  86. {
  87. pantheios::log_CRITICAL("out of memory");
  88. }
  89. catch(std::exception &x)
  90. {
  91. pantheios::log_ALERT("Exception: ", x);
  92. }
  93. catch(...)
  94. {
  95. pantheios::logputs(pantheios::emergency, "Unexpected unknown error");
  96. }
  97. return EXIT_FAILURE;
  98. }
  99. /* ///////////////////////////// end of file //////////////////////////// */